Skip to content

Commit cf94289

Browse files
committed
Re-implement equals/hashCode with java.lang.Objects.
1 parent f87f0b3 commit cf94289

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

src/main/java/org/apache/commons/cli/Option.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2020
import java.io.Serializable;
2121
import java.util.ArrayList;
2222
import java.util.List;
23+
import java.util.Objects;
2324

2425
/**
2526
* Describes a single command-line option. It maintains information regarding the short-name of the option, the
@@ -461,22 +462,15 @@ public Object clone() {
461462
}
462463

463464
@Override
464-
public boolean equals(final Object o) {
465-
if (this == o) {
465+
public boolean equals(Object obj) {
466+
if (this == obj) {
466467
return true;
467468
}
468-
if (o == null || getClass() != o.getClass()) {
469+
if (!(obj instanceof Option)) {
469470
return false;
470471
}
471-
472-
final Option option = (Option) o;
473-
474-
if ((this.option != null ? !this.option.equals(option.option) : option.option != null)
475-
|| (longOption != null ? !longOption.equals(option.longOption) : option.longOption != null)) {
476-
return false;
477-
}
478-
479-
return true;
472+
Option other = (Option) obj;
473+
return Objects.equals(longOption, other.longOption) && Objects.equals(option, other.option);
480474
}
481475

482476
/**
@@ -655,10 +649,7 @@ public boolean hasArgs() {
655649

656650
@Override
657651
public int hashCode() {
658-
int result;
659-
result = option != null ? option.hashCode() : 0;
660-
result = 31 * result + (longOption != null ? longOption.hashCode() : 0);
661-
return result;
652+
return Objects.hash(longOption, option);
662653
}
663654

664655
/**

0 commit comments

Comments
 (0)