Skip to content

Commit

Permalink
GEODE-5986 Inconsistent equals/hashCode
Browse files Browse the repository at this point in the history
Added hashCode and equals methods to classes that were missing one or
the other.
  • Loading branch information
bschuchardt committed Nov 8, 2018
1 parent 23af84c commit a5b04cc
Show file tree
Hide file tree
Showing 42 changed files with 306 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private LocalRegion createOrRetrieveGatewayDeltaRegion() {
return (LocalRegion) region;
}

@Override
public boolean equals(Object obj) {
// This method is only implemented so that RegionCreator.validateRegion works properly.
// The CacheListener comparison fails because two of these instances are not equal.
Expand All @@ -179,4 +180,9 @@ public boolean equals(Object obj) {

return true;
}

@Override
public int hashCode() {
return GatewayDeltaForwarderCacheListener.class.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public void afterDestroy(EntryEvent<String, HttpSession> event) {

public void init(Properties p) {}


@Override
public boolean equals(Object obj) {
// This method is only implemented so that RegionAttributesCreation.sameAs
// works properly.
Expand All @@ -73,4 +75,11 @@ public boolean equals(Object obj) {

return true;
}


@Override
public int hashCode() {
return SessionExpirationCacheListener.class.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,11 @@ public boolean equals(Object obj) {

return true;
}


@Override
public int hashCode() {
return DebugCacheListener.class.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ public boolean equals(Object obj) {

return true;
}


@Override
public int hashCode() {
return getClass().hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public boolean equals(Object obj) {
return obj == this || obj instanceof MonthBasedPartitionResolver;
}

@Override
public int hashCode() {
return super.hashCode();
}

@Override
public String getName() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -2000,6 +2001,11 @@ public boolean equals(Object o) {
Customer cust = (Customer) o;
return (cust.name.equals(name) && cust.address.equals(address));
}

@Override
public int hashCode() {
return Objects.hash(name, address);
}
}


Expand Down Expand Up @@ -2040,6 +2046,15 @@ public boolean equals(Object obj) {
}
return false;
}

@Override
public int hashCode() {
if (orderName == null) {
return super.hashCode();
}
return orderName.hashCode();
}

}


Expand Down Expand Up @@ -2080,4 +2095,14 @@ public boolean equals(Object obj) {
}
return false;
}


@Override
public int hashCode() {
if (shipmentName == null) {
return super.hashCode();
}
return shipmentName.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ public void toData(DataOutput out) throws IOException {
out.writeInt(month);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof SerializableMonth)) {
return false;
}
SerializableMonth that = (SerializableMonth) o;
return month == that.month;
}

@Override
public int hashCode() {
if (month < 4) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public LinkedResultSet() {}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof LinkedResultSet)) {
return false;
}
Expand All @@ -69,6 +72,11 @@ public boolean equals(Object other) {
return super.equals(other);
}

@Override
public int hashCode() {
return this.elementType.hashCode();
}

public void setElementType(ObjectType elementType) {
if (elementType instanceof StructType)
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public boolean equals(Object o) {
return o instanceof NullToken;
}

@Override
public int hashCode() {
return NullToken.class.hashCode();
}

@Override
public int getDSFID() {
return NULL_TOKEN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public void setElementType(ObjectType elementType) {

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof ResultsSet)) {
return false;
}
Expand All @@ -99,6 +102,10 @@ public boolean equals(Object other) {
return super.equals(other);
}

@Override
public int hashCode() {
return this.elementType.hashCode();
}

public List asList() {
return new ArrayList(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.apache.geode.cache.query.internal;

import java.util.Comparator;
import java.util.Objects;

import org.apache.geode.cache.query.SelectResults;

Expand Down Expand Up @@ -53,4 +54,9 @@ public int compare(Object obj1, Object obj2) {
public boolean equals(Object o1) {
return this == o1;
}

@Override
public int hashCode() {
return Objects.hash(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public SortedResultSet() {}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof SortedResultSet)) {
return false;
}
Expand All @@ -78,6 +81,11 @@ public boolean equals(Object other) {
return super.equals(other);
}

@Override
public int hashCode() {
return this.elementType.hashCode();
}

public void setElementType(ObjectType elementType) {
if (elementType instanceof StructType)
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public boolean equals(Object other) {
return super.equals(other);
}

@Override
public int hashCode() {
return super.hashCode();
}

/** Add a Struct */
@Override
public boolean add(Object obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public boolean equals(Object o) {
return (o instanceof Undefined);
}

@Override
public int hashCode() {
return Undefined.class.hashCode();
}



@Override
public Version[] getSerializationVersions() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public boolean equals(Object obj) {
return obj instanceof ExtendedNumericComparator;
}

@Override
public int hashCode() {
return ExtendedNumericComparator.class.hashCode();
}

public int compare(Object obj1, Object obj2) {
if (obj1.getClass() != obj2.getClass() && (obj1 instanceof Number && obj2 instanceof Number)) {
return super.compare(obj1, obj2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public boolean equals(Object obj) {
return obj instanceof NumericComparator;
}

@Override
public int hashCode() {
return NumericComparator.class.hashCode();
}


// throws ClassCastExcepton if obj1 or obj2 is not a Number
public int compare(Object obj1, Object obj2) {
Number num1 = (Number) obj1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public boolean equals(Object obj) {
return obj instanceof TemporalComparator;
}

@Override
public int hashCode() {
return TemporalComparator.class.hashCode();
}


// throws ClassCastExcepton if obj1 or obj2 is not a java.util.Date or subclass
public int compare(Object obj1, Object obj2) {
java.util.Date date1 = (java.util.Date) obj1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import org.apache.geode.DataSerializer;
Expand Down Expand Up @@ -182,6 +183,11 @@ protected void process(ClusterDistributionManager dm) {
throw new IllegalStateException("this message should not be executed");
}

@Override
public int hashCode() {
return Objects.hash(senderId, view, registrants, requestId);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

import org.apache.geode.DataSerializer;
import org.apache.geode.distributed.internal.ClusterDistributionManager;
Expand Down Expand Up @@ -106,6 +107,11 @@ public String toString() {
+ (credentials == null ? "null" : "not null") + ")";
}

@Override
public int hashCode() {
return Objects.hash(view, previousViewId);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;

import org.apache.geode.DataSerializer;
import org.apache.geode.distributed.internal.ClusterDistributionManager;
Expand Down Expand Up @@ -102,6 +103,11 @@ public int getFailureDetectionPort() {
return failureDetectionPort;
}

@Override
public int hashCode() {
return Objects.hash(memberID);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;

import org.apache.geode.DataSerializer;
import org.apache.geode.distributed.internal.ClusterDistributionManager;
Expand Down Expand Up @@ -133,6 +134,11 @@ public void fromData(DataInput in) throws IOException, ClassNotFoundException {
secretPk = DataSerializer.readByteArray(in);
}

@Override
public int hashCode() {
return Objects.hash(memberID);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down
Loading

0 comments on commit a5b04cc

Please sign in to comment.