roxspring 2004/10/08 03:22:07
Modified: cli/src/java/org/apache/commons/cli2/option OptionImpl.java
Log:
OptionImpl now avoids NullPointerExceptions
Revision Changes Path
1.5 +17 -6
jakarta-commons/cli/src/java/org/apache/commons/cli2/option/OptionImpl.java
Index: OptionImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/OptionImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- OptionImpl.java 7 Sep 2004 00:18:23 -0000 1.4
+++ OptionImpl.java 8 Oct 2004 10:22:07 -0000 1.5
@@ -69,18 +69,29 @@
final OptionImpl that = (OptionImpl)thatObj;
return getId() == that.getId()
- && getPreferredName().equals(that.getPreferredName())
- && (getDescription() == that.getDescription()
- || getDescription().equals(that.getDescription()))
- && getPrefixes().equals(that.getPrefixes())
- && getTriggers().equals(that.getTriggers());
+ && equals(getPreferredName(),that.getPreferredName())
+ && equals(getDescription(),that.getDescription())
+ && equals(getPrefixes(),that.getPrefixes())
+ && equals(getTriggers(),that.getTriggers());
}
else {
return false;
}
}
- public int hashCode() {
+ private boolean equals(Object left, Object right) {
+ if(left==null && right==null){
+ return true;
+ }
+ else if(left==null || right==null){
+ return false;
+ }
+ else{
+ return left.equals(right);
+ }
+ }
+
+ public int hashCode() {
int hashCode = getId();
hashCode = hashCode * 37 + getPreferredName().hashCode();
if (getDescription() != null) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]