Skip to content

Commit

Permalink
Merge pull request #11644 from rjernst/refactor/field-type-equality
Browse files Browse the repository at this point in the history
Add equals/hashcode to fieldtypes
  • Loading branch information
rjernst committed Jun 15, 2015
2 parents 2fb8df0 + a08f51e commit 7ab0009
Show file tree
Hide file tree
Showing 35 changed files with 1,241 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Objects;

/**
* This defines the core properties and functions to operate on a field.
Expand Down Expand Up @@ -200,7 +201,29 @@ public MappedFieldType clone() {
return new MappedFieldType(this);
}

// norelease: we need to override freeze() and add safety checks that all settings are actually set
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
MappedFieldType fieldType = (MappedFieldType) o;
return boost == fieldType.boost &&
docValues == fieldType.docValues &&
Objects.equals(names, fieldType.names) &&
Objects.equals(indexAnalyzer, fieldType.indexAnalyzer) &&
Objects.equals(searchAnalyzer, fieldType.searchAnalyzer) &&
Objects.equals(searchQuoteAnalyzer(), fieldType.searchQuoteAnalyzer()) &&
Objects.equals(similarity, fieldType.similarity) &&
Objects.equals(normsLoading, fieldType.normsLoading) &&
Objects.equals(fieldDataType, fieldType.fieldDataType) &&
Objects.equals(nullValue, fieldType.nullValue) &&
Objects.equals(nullValueAsString, fieldType.nullValueAsString);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), names, boost, docValues, indexAnalyzer, searchAnalyzer, searchQuoteAnalyzer, similarity, normsLoading, fieldDataType, nullValue, nullValueAsString);
}

// norelease: we need to override freeze() and add safety checks that all settings are actually set

public boolean isNumeric() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static org.elasticsearch.index.mapper.MapperBuilders.binaryField;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseField;
Expand Down Expand Up @@ -82,7 +83,7 @@ public Builder(String name) {
@Override
public BinaryFieldMapper build(BuilderContext context) {
setupFieldType(context);
((BinaryFieldType)fieldType).tryUncompressing = context.indexCreatedVersion().before(Version.V_2_0_0);
((BinaryFieldType)fieldType).setTryUncompressing(context.indexCreatedVersion().before(Version.V_2_0_0));
return new BinaryFieldMapper(fieldType, docValues,
fieldDataSettings, context.indexSettings(), multiFieldsBuilder.build(this, context), copyTo);
}
Expand All @@ -106,7 +107,7 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
}

static final class BinaryFieldType extends MappedFieldType {
protected boolean tryUncompressing = false;
private boolean tryUncompressing = false;

public BinaryFieldType() {
super(AbstractFieldMapper.Defaults.FIELD_TYPE);
Expand All @@ -122,6 +123,27 @@ public MappedFieldType clone() {
return new BinaryFieldType(this);
}

@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
BinaryFieldType that = (BinaryFieldType) o;
return Objects.equals(tryUncompressing, that.tryUncompressing);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), tryUncompressing);
}

public boolean tryUncompressing() {
return tryUncompressing;
}

public void setTryUncompressing(boolean tryUncompressing) {
checkIfFrozen();
this.tryUncompressing = tryUncompressing;
}

@Override
public BytesReference value(Object value) {
if (value == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -234,6 +235,19 @@ public DateFieldType clone() {
return new DateFieldType(this);
}

@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
DateFieldType that = (DateFieldType) o;
return Objects.equals(dateTimeFormatter.format(), that.dateTimeFormatter.format()) &&
Objects.equals(timeUnit, that.timeUnit);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), dateTimeFormatter.format(), timeUnit);
}

public FormatDateTimeFormatter dateTimeFormatter() {
return dateTimeFormatter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,26 @@ public MappedFieldType clone() {
return new GeoPointFieldType(this);
}

@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
GeoPointFieldType that = (GeoPointFieldType) o;
return geohashPrecision == that.geohashPrecision &&
geohashPrefixEnabled == that.geohashPrefixEnabled &&
validateLon == that.validateLon &&
validateLat == that.validateLat &&
normalizeLon == that.normalizeLon &&
normalizeLat == that.normalizeLat &&
java.util.Objects.equals(geohashFieldType, that.geohashFieldType) &&
java.util.Objects.equals(latFieldType, that.latFieldType) &&
java.util.Objects.equals(lonFieldType, that.lonFieldType);
}

@Override
public int hashCode() {
return java.util.Objects.hash(super.hashCode(), geohashFieldType, geohashPrecision, geohashPrefixEnabled, latFieldType, lonFieldType, validateLon, validateLat, normalizeLon, normalizeLat);
}

public boolean isGeohashEnabled() {
return geohashFieldType != null;
}
Expand Down

0 comments on commit 7ab0009

Please sign in to comment.