SimpleSortField extends SortField { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } SimpleSortField otherSimpleSortField = (SimpleSortField) o; return reverse == otherSimpleSortField.reverse && field.equals(otherSimpleSortField.field); } SimpleSortField(String field, Boolean reverse); String getField(); @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; }
@Test public void testEquals() { SimpleSortField sortField = new SimpleSortField("field", true); assertEquals("SortField equals is wrong", sortField, sortField); assertEquals("SortField equals is wrong", sortField, new SimpleSortField("field", true)); assertFalse("SortField equals is wrong", sortField.equals(new SimpleSortField("field2", true))); assertFalse("SortField equals is wrong", sortField.equals(new SimpleSortField("field", false))); assertFalse("SortField equals is wrong", sortField.equals(nullInt())); assertFalse("SortField equals is wrong", sortField.equals(nullSortField())); }
@Test public void testEqualsWithNull() { SimpleSortField sortField = new SimpleSortField("field", true); assertFalse("SortField equals is wrong", sortField.equals(null)); assertFalse("SortField equals is wrong", sortField.equals(new Integer(0))); }