From ff977926a90608128a8f391d889a7e04dc63b756 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 20 Oct 2011 00:51:24 +0200 Subject: [PATCH] add equals support to index metadata --- .../cluster/metadata/IndexMetaData.java | 24 +++++ .../cluster/metadata/MappingMetaData.java | 88 +++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index 1dc012b5a66..14164d0d4f5 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -229,6 +229,30 @@ public class IndexMetaData { return excludeFilters; } + @Override public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + IndexMetaData that = (IndexMetaData) o; + + if (!aliases.equals(that.aliases)) return false; + if (!index.equals(that.index)) return false; + if (!mappings.equals(that.mappings)) return false; + if (!settings.equals(that.settings)) return false; + if (state != that.state) return false; + + return true; + } + + @Override public int hashCode() { + int result = index.hashCode(); + result = 31 * result + state.hashCode(); + result = 31 * result + aliases.hashCode(); + result = 31 * result + settings.hashCode(); + result = 31 * result + mappings.hashCode(); + return result; + } + public static Builder newIndexMetaDataBuilder(String index) { return new Builder(index); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java index 3bf6a226fa0..5e87951f28f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java @@ -33,6 +33,7 @@ import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.internal.TimestampFieldMapper; import java.io.IOException; +import java.util.Arrays; import java.util.Map; import static org.elasticsearch.common.xcontent.support.XContentMapValues.*; @@ -70,6 +71,24 @@ public class MappingMetaData { public String[] pathElements() { return this.pathElements; } + + @Override public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Id id = (Id) o; + + if (path != null ? !path.equals(id.path) : id.path != null) return false; + if (!Arrays.equals(pathElements, id.pathElements)) return false; + + return true; + } + + @Override public int hashCode() { + int result = path != null ? path.hashCode() : 0; + result = 31 * result + (pathElements != null ? Arrays.hashCode(pathElements) : 0); + return result; + } } public static class Routing { @@ -107,6 +126,26 @@ public class MappingMetaData { public String[] pathElements() { return this.pathElements; } + + @Override public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Routing routing = (Routing) o; + + if (required != routing.required) return false; + if (path != null ? !path.equals(routing.path) : routing.path != null) return false; + if (!Arrays.equals(pathElements, routing.pathElements)) return false; + + return true; + } + + @Override public int hashCode() { + int result = (required ? 1 : 0); + result = 31 * result + (path != null ? path.hashCode() : 0); + result = 31 * result + (pathElements != null ? Arrays.hashCode(pathElements) : 0); + return result; + } } public static class Timestamp { @@ -173,6 +212,31 @@ public class MappingMetaData { public FormatDateTimeFormatter dateTimeFormatter() { return this.dateTimeFormatter; } + + @Override public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Timestamp timestamp = (Timestamp) o; + + if (enabled != timestamp.enabled) return false; + if (dateTimeFormatter != null ? !dateTimeFormatter.equals(timestamp.dateTimeFormatter) : timestamp.dateTimeFormatter != null) + return false; + if (format != null ? !format.equals(timestamp.format) : timestamp.format != null) return false; + if (path != null ? !path.equals(timestamp.path) : timestamp.path != null) return false; + if (!Arrays.equals(pathElements, timestamp.pathElements)) return false; + + return true; + } + + @Override public int hashCode() { + int result = (enabled ? 1 : 0); + result = 31 * result + (path != null ? path.hashCode() : 0); + result = 31 * result + (format != null ? format.hashCode() : 0); + result = 31 * result + (pathElements != null ? Arrays.hashCode(pathElements) : 0); + result = 31 * result + (dateTimeFormatter != null ? dateTimeFormatter.hashCode() : 0); + return result; + } } private final String type; @@ -389,6 +453,30 @@ public class MappingMetaData { out.writeUTF(mappingMd.timestamp().format()); } + @Override public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MappingMetaData that = (MappingMetaData) o; + + if (!id.equals(that.id)) return false; + if (!routing.equals(that.routing)) return false; + if (!source.equals(that.source)) return false; + if (!timestamp.equals(that.timestamp)) return false; + if (!type.equals(that.type)) return false; + + return true; + } + + @Override public int hashCode() { + int result = type.hashCode(); + result = 31 * result + source.hashCode(); + result = 31 * result + id.hashCode(); + result = 31 * result + routing.hashCode(); + result = 31 * result + timestamp.hashCode(); + return result; + } + public static MappingMetaData readFrom(StreamInput in) throws IOException { String type = in.readUTF(); CompressedString source = CompressedString.readCompressedString(in);