GeoDistanceSortField extends SortField { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } GeoDistanceSortField other = (GeoDistanceSortField) o; return reverse == other.reverse && field.equals(other.field) && latitude == other.latitude && longitude == other.longitude; } GeoDistanceSortField(String field, Boolean reverse, double latitude, double longitude); @Override org.apache.lucene.search.SortField sortField(Schema schema); Set<String> postProcessingFields(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); final String field; final double latitude; final double longitude; }
@Test public void testEquals() { GeoDistanceSortField sortField = new GeoDistanceSortField("field", true, 0.0, 0.0); assertEquals("SortField equals is wrong", sortField, sortField); assertEquals("SortField equals is wrong", sortField, new GeoDistanceSortField("field", true, 0.0, 0.0)); assertFalse("SortField equals is wrong", sortField.equals(new GeoDistanceSortField("field2", true, 0.0, 0.0))); assertFalse("SortField equals is wrong", sortField.equals(new GeoDistanceSortField("field", false, 0.0, 0.0))); assertFalse("SortField equals is wrong", sortField.equals(new GeoDistanceSortField("field", true, 0.0, 1.0))); assertFalse("SortField equals is wrong", sortField.equals(new GeoDistanceSortField("field", true, -1.0, 0.0))); assertFalse("SortField equals is wrong", sortField.equals(nullInt())); assertFalse("SortField equals is wrong", sortField.equals(nullSortField())); }
@Test public void testEqualsWithNull() { GeoDistanceSortField sortField = new GeoDistanceSortField("field", true, 0.0, 0.0); assertFalse("SortField equals is wrong", sortField.equals(null)); assertFalse("SortField equals is wrong", sortField.equals(new Integer(0))); }