Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5793: add equals/hashCode to FieldType

Robert Muirbb0814140941
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 3bd803d1a29..9b59835f969 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -109,6 +109,8 @@ API Changes
* LUCENE-5752: Simplified Automaton API to be immutable. (Mike McCandless)
+* LUCENE-5793: Add equals/hashCode to FieldType. (Shay Banon, Robert Muir)
+
Optimizations
* LUCENE-5780: Make OrdinalMap more memory-efficient, especially in case the
diff --git a/lucene/core/src/java/org/apache/lucene/document/FieldType.java b/lucene/core/src/java/org/apache/lucene/document/FieldType.java
index c08692313c8..f2942f336a9 100644
--- a/lucene/core/src/java/org/apache/lucene/document/FieldType.java
+++ b/lucene/core/src/java/org/apache/lucene/document/FieldType.java
@@ -434,4 +434,44 @@ public class FieldType implements IndexableFieldType {
checkIfFrozen();
docValueType = type;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((docValueType == null) ? 0 : docValueType.hashCode());
+ result = prime * result + ((indexOptions == null) ? 0 : indexOptions.hashCode());
+ result = prime * result + (indexed ? 1231 : 1237);
+ result = prime * result + numericPrecisionStep;
+ result = prime * result + ((numericType == null) ? 0 : numericType.hashCode());
+ result = prime * result + (omitNorms ? 1231 : 1237);
+ result = prime * result + (storeTermVectorOffsets ? 1231 : 1237);
+ result = prime * result + (storeTermVectorPayloads ? 1231 : 1237);
+ result = prime * result + (storeTermVectorPositions ? 1231 : 1237);
+ result = prime * result + (storeTermVectors ? 1231 : 1237);
+ result = prime * result + (stored ? 1231 : 1237);
+ result = prime * result + (tokenized ? 1231 : 1237);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
+ FieldType other = (FieldType) obj;
+ if (docValueType != other.docValueType) return false;
+ if (indexOptions != other.indexOptions) return false;
+ if (indexed != other.indexed) return false;
+ if (numericPrecisionStep != other.numericPrecisionStep) return false;
+ if (numericType != other.numericType) return false;
+ if (omitNorms != other.omitNorms) return false;
+ if (storeTermVectorOffsets != other.storeTermVectorOffsets) return false;
+ if (storeTermVectorPayloads != other.storeTermVectorPayloads) return false;
+ if (storeTermVectorPositions != other.storeTermVectorPositions) return false;
+ if (storeTermVectors != other.storeTermVectors) return false;
+ if (stored != other.stored) return false;
+ if (tokenized != other.tokenized) return false;
+ return true;
+ }
}
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java b/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
new file mode 100644
index 00000000000..1179474b693
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
@@ -0,0 +1,70 @@
+package org.apache.lucene.document;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.document.FieldType.NumericType;
+import org.apache.lucene.index.FieldInfo.DocValuesType;
+import org.apache.lucene.index.FieldInfo.IndexOptions;
+import org.apache.lucene.util.LuceneTestCase;
+
+/** simple testcases for concrete impl of IndexableFieldType */
+public class TestFieldType extends LuceneTestCase {
+
+ public void testEquals() throws Exception {
+ FieldType ft = new FieldType();
+ assertEquals(ft, ft);
+ assertFalse(ft.equals(null));
+
+ FieldType ft2 = new FieldType();
+ assertEquals(ft, ft2);
+ assertEquals(ft.hashCode(), ft2.hashCode());
+
+ FieldType ft3 = new FieldType();
+ ft3.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
+ assertFalse(ft3.equals(ft));
+
+ FieldType ft4 = new FieldType();
+ ft4.setDocValueType(DocValuesType.BINARY);
+ assertFalse(ft4.equals(ft));
+
+ FieldType ft5 = new FieldType();
+ ft5.setIndexed(true);
+ assertFalse(ft5.equals(ft));
+
+ FieldType ft6 = new FieldType();
+ ft6.setStored(true);
+ assertFalse(ft6.equals(ft));
+
+ FieldType ft7 = new FieldType();
+ ft7.setOmitNorms(true);
+ assertFalse(ft7.equals(ft));
+
+ FieldType ft8 = new FieldType();
+ ft8.setNumericType(NumericType.DOUBLE);
+ assertFalse(ft8.equals(ft));
+
+ FieldType ft9 = new FieldType();
+ ft9.setNumericPrecisionStep(3);
+ assertFalse(ft9.equals(ft));
+
+ FieldType ft10 = new FieldType();
+ ft10.setStoreTermVectors(true);
+ assertFalse(ft10.equals(ft));
+
+ }
+}