diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/PlainShardIterator.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/PlainShardIterator.java index 24c74a4b20b..e4f9f7fa6a5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/PlainShardIterator.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/routing/PlainShardIterator.java @@ -51,15 +51,11 @@ public class PlainShardIterator extends PlainShardsIterator implements ShardIter @Override public boolean equals(Object o) { if (this == o) return true; - ShardIterator that = (ShardIterator) o; - - if (shardId != null ? !shardId.equals(that.shardId()) : that.shardId() != null) return false; - - return true; + return shardId.equals(that.shardId()); } @Override public int hashCode() { - return shardId != null ? shardId.hashCode() : 0; + return shardId.hashCode(); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/Index.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/Index.java index a9e9937f3bf..2b8a6a02944 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/Index.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/Index.java @@ -57,17 +57,13 @@ public class Index implements Serializable, Streamable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (o == null) return false; Index index1 = (Index) o; - - if (name != null ? !name.equals(index1.name) : index1.name != null) return false; - - return true; + return name.equals(index1.name); } @Override public int hashCode() { - return name != null ? name.hashCode() : 0; + return name.hashCode(); } public static Index readIndexName(StreamInput in) throws IOException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/ShardId.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/ShardId.java index 0b86080780f..7870523e44d 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/ShardId.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/ShardId.java @@ -40,6 +40,8 @@ public class ShardId implements Serializable, Streamable { private int shardId; + private int hashCode; + private ShardId() { } @@ -51,6 +53,7 @@ public class ShardId implements Serializable, Streamable { public ShardId(Index index, int shardId) { this.index = index; this.shardId = shardId; + this.hashCode = computeHashCode(); } public Index index() { @@ -75,17 +78,16 @@ public class ShardId implements Serializable, Streamable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (o == null) return false; ShardId shardId1 = (ShardId) o; - - if (shardId != shardId1.shardId) return false; - if (index != null ? !index.equals(shardId1.index) : shardId1.index != null) return false; - - return true; + return shardId == shardId1.shardId && index.name().equals(shardId1.index.name()); } @Override public int hashCode() { + return hashCode; + } + + private int computeHashCode() { int result = index != null ? index.hashCode() : 0; result = 31 * result + shardId; return result;