Skip to content

Commit

Permalink
Minor cleanups of equals and hashcode in core (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga authored May 11, 2020
1 parent 764d66a commit 26f9431
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public boolean equals(Object o) {
*/
public int hashCode() {
if (arn == null && logGroup == null) {
return Objects.hash("");
return "".hashCode();
} else if (arn == null) {
return Objects.hash(logGroup);
return logGroup.hashCode();
} else {
return Objects.hash(arn);
return arn.hashCode();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigInteger;
import java.time.Instant;
import java.util.Objects;

import com.amazonaws.xray.ThreadLocalStorage;

Expand Down Expand Up @@ -85,18 +86,10 @@ public int hashCode() {
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
if (!(obj instanceof TraceID)) {
return false;
}
TraceID other = (TraceID) obj;
if (number == null) {
if (other.number != null)
return false;
} else if (!number.equals(other.number))
return false;
if (startTime != other.startTime)
return false;
return true;
return Objects.equals(number, other.number) && startTime == other.startTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import com.amazonaws.xray.entities.AWSLogReference;
Expand Down Expand Up @@ -155,6 +154,6 @@ public boolean equals(Object o) {
* Hash plugin object using origin to uniquely identify them
*/
public int hashCode() {
return Objects.hash(this.getOrigin());
return this.getOrigin().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import com.amazonaws.xray.utils.DockerUtils;
import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -90,7 +89,7 @@ public boolean equals(Object o) {
* Hash plugin object using origin to uniquely identify them
*/
public int hashCode() {
return Objects.hash(this.getOrigin());
return this.getOrigin().hashCode();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@

import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;


Expand Down Expand Up @@ -133,6 +131,6 @@ public boolean equals(Object o) {
* Hash plugin object using origin to uniquely identify them
*/
public int hashCode() {
return Objects.hash(this.getOrigin());
return this.getOrigin().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -90,6 +89,6 @@ public boolean equals(Object o) {
* Hash plugin object using origin to uniquely identify them
*/
public int hashCode() {
return Objects.hash(this.getOrigin());
return this.getOrigin().hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.time.Instant;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

Expand Down Expand Up @@ -240,7 +241,9 @@ public String getName() {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!(o instanceof CentralizedRule)) {
return false;
}

CentralizedRule that = (CentralizedRule) o;

Expand All @@ -249,7 +252,7 @@ public boolean equals(Object o) {
if (!name.equals(that.name)) return false;
if (!centralizedReservoir.equals(that.centralizedReservoir)) return false;
if (!statistics.equals(that.statistics)) return false;
return matchers != null ? matchers.equals(that.matchers) : that.matchers == null;
return Objects.equals(matchers, that.matchers);
}

@Override
Expand Down

0 comments on commit 26f9431

Please sign in to comment.