You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2003/06/07 03:29:49 UTC
cvs commit: jakarta-commons/cli/src/java/org/apache/commons/cli OptionImpl.java
jkeyes 2003/06/06 18:29:49
Modified: cli/src/java/org/apache/commons/cli Tag: cli_1_x
OptionImpl.java
Log:
o added equals and hashCode method
Revision Changes Path
No revision
No revision
1.1.2.5 +48 -3 jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/OptionImpl.java
Index: OptionImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/OptionImpl.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- OptionImpl.java 6 Jun 2003 22:17:08 -0000 1.1.2.4
+++ OptionImpl.java 7 Jun 2003 01:29:49 -0000 1.1.2.5
@@ -61,6 +61,7 @@
package org.apache.commons.cli;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
/**
@@ -188,6 +189,50 @@
return (children != null && this.children.size() > 0);
}
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+
+ if (!(obj instanceof OptionImpl)) {
+ return false;
+ }
+
+ OptionImpl option = (OptionImpl)obj;
+
+ String name = option.getName();
+ String longName = option.getLongName();
+ String description = option.getDescription();
+ boolean required = option.isRequired();
+ Collection children = option.getChildren();
+
+ return (
+ this.name == name || (this.name != null && this.name.equals(name)))
+ && (this.longName == longName
+ || (this.longName != null && this.longName.equals(longName)))
+ && (this.description == description
+ || (this.description != null
+ && this.description.equals(description)))
+ && this.required == required
+ && (this.children == children
+ || (this.children != null && this.children.equals(children)));
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return
+ (this.name == null ? 0 : this.name.hashCode()) ^
+ (this.longName == null ? 0 : this.longName.hashCode()) ^
+ (this.description == null ? 0 : this.description.hashCode()) ^
+ (this.required ? 0 : 1) ^
+ (this.children == null ? 0 : this.children.hashCode());
+ }
+
/**
* <p>
* Validates whether <code>opt</code> is a permissable Option
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org