DATACMNS-436 - Order.equals(…) / hashCode() / toString() now consider ignore case flag.

Extended equals(…), hashCode() and toString() methods t consider the ignore case flag held in an Order instance.
This commit is contained in:
Oliver Gierke
2014-02-06 18:13:54 +01:00
parent 899cf25330
commit 1e3640e0ee
2 changed files with 19 additions and 2 deletions

View File

@@ -375,6 +375,7 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
result = 31 * result + direction.hashCode();
result = 31 * result + property.hashCode();
result = 31 * result + (ignoreCase ? 1 : 0);
return result;
}
@@ -396,7 +397,8 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
Order that = (Order) obj;
return this.direction.equals(that.direction) && this.property.equals(that.property);
return this.direction.equals(that.direction) && this.property.equals(that.property)
&& this.ignoreCase == that.ignoreCase;
}
/*
@@ -405,7 +407,9 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
*/
@Override
public String toString() {
return String.format("%s: %s", property, direction);
String result = String.format("%s: %s", property, direction);
return ignoreCase ? result.concat(", ignoring case") : result;
}
}
}

View File

@@ -117,4 +117,17 @@ public class SortUnitTests {
public void orderDoesNotIgnoreCaseByDefault() {
assertThat(new Order(Direction.ASC, "foo").isIgnoreCase(), is(false));
}
/**
* @see DATACMNS-436
*/
@Test
public void ordersWithDifferentIgnoreCaseDoNotEqual() {
Order foo = new Order("foo");
Order fooIgnoreCase = new Order("foo").ignoreCase();
assertThat(foo, is(not(fooIgnoreCase)));
assertThat(foo.hashCode(), is(not(fooIgnoreCase.hashCode())));
}
}