Skip to content

Commit

Permalink
[#335] Bugfix: Abstract class ArgSpec should not implement equals
Browse files Browse the repository at this point in the history
… and `hashCode`.

Closes #335.
  • Loading branch information
remkop committed Apr 9, 2018
1 parent e4ef759 commit 44320ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ No features have been promoted in this picocli release.
- [#325] Enhancement: Allow custom type converter to map empty String to custom default value for empty options. Thanks to [jesselong](https://github.com/jesselong) for the suggestion.
- [#303] Enhancement: Improve validation to prevent common mistakes.
- [#327] Bugfix: Default values should not cause options and positional parameters to be added to ParseResult.
- [#330] Bugfix: Interpreter should clear option's and positional parameter's rawStringValues list before parsing new input.
- [#330] Bugfix: `Interpreter` should clear option's and positional parameter's rawStringValues list before parsing new input.
- [#335] Bugfix: Abstract class `ArgSpec` should not implement `equals` and `hashCode`.

## <a name="3.0.0-alpha-5-deprecated"></a> Deprecations
See [3.0.0-alpha-1](https://github.com/remkop/picocli/releases/tag/v3.0.0-alpha-1#3.0.0-alpha-1-deprecated)
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -3524,10 +3524,8 @@ protected boolean showDefaultValue(CommandSpec commandSpec) {
private String[] splitValue(String value) {
return splitRegex().length() == 0 ? new String[] {value} : value.split(splitRegex());
}
public boolean equals(Object obj) {
if (obj == this) { return true; }
if (!(obj instanceof ArgSpec)) { return false; }
ArgSpec other = (ArgSpec) obj;
protected boolean equalsImpl(ArgSpec other) {
if (other == this) { return true; }
boolean result = Assert.equals(this.defaultValue, other.defaultValue)
&& Assert.equals(this.type, other.type)
&& Assert.equals(this.arity, other.arity)
Expand All @@ -3540,7 +3538,7 @@ public boolean equals(Object obj) {
;
return result;
}
public int hashCode() {
protected int hashCodeImpl() {
return 17
+ 37 * Assert.hashCode(defaultValue)
+ 37 * Assert.hashCode(type)
Expand Down Expand Up @@ -3796,15 +3794,15 @@ public boolean equals(Object obj) {
if (obj == this) { return true; }
if (!(obj instanceof OptionSpec)) { return false; }
OptionSpec other = (OptionSpec) obj;
boolean result = super.equals(obj)
boolean result = super.equalsImpl(other)
&& help == other.help
&& usageHelp == other.usageHelp
&& versionHelp == other.versionHelp
&& new HashSet<String>(Arrays.asList(names)).equals(new HashSet<String>(Arrays.asList(other.names)));
return result;
}
public int hashCode() {
return super.hashCode()
return super.hashCodeImpl()
+ 37 * Assert.hashCode(help)
+ 37 * Assert.hashCode(usageHelp)
+ 37 * Assert.hashCode(versionHelp)
Expand Down Expand Up @@ -3931,7 +3929,7 @@ private PositionalParamSpec(Builder builder) {
public static Builder builder() { return new Builder(); }

public int hashCode() {
return super.hashCode()
return super.hashCodeImpl()
+ 37 * Assert.hashCode(capacity)
+ 37 * Assert.hashCode(index);
}
Expand All @@ -3943,7 +3941,8 @@ public boolean equals(Object obj) {
return false;
}
PositionalParamSpec other = (PositionalParamSpec) obj;
return Assert.equals(this.capacity, other.capacity)
return super.equalsImpl(other)
&& Assert.equals(this.capacity, other.capacity)
&& Assert.equals(this.index, other.index);
}

Expand Down

0 comments on commit 44320ee

Please sign in to comment.