Browse Source

DATACMNS-908 - Introduced Order.withProperty(…).

The introduced method allows creating new Order instances for a different property ensuring all other aspects (ignore case, null handling) are retained.
pull/178/head
Oliver Gierke 10 years ago
parent
commit
e294fb5ef4
  1. 19
      src/main/java/org/springframework/data/domain/Sort.java
  2. 15
      src/test/java/org/springframework/data/domain/SortUnitTests.java

19
src/main/java/org/springframework/data/domain/Sort.java

@ -393,13 +393,24 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order @@ -393,13 +393,24 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
}
/**
* Returns a new {@link Order} with the given {@link Order}.
* Returns a new {@link Order} with the given {@link Direction}.
*
* @param order
* @param direction
* @return
*/
public Order with(Direction order) {
return new Order(order, this.property, nullHandling);
public Order with(Direction direction) {
return new Order(direction, this.property, this.ignoreCase, this.nullHandling);
}
/**
* Returns a new {@link Order}
*
* @param property must not be {@literal null} or empty.
* @return
* @since 1.13
*/
public Order withProperty(String property) {
return new Order(this.direction, property, this.ignoreCase, this.nullHandling);
}
/**

15
src/test/java/org/springframework/data/domain/SortUnitTests.java

@ -164,4 +164,19 @@ public class SortUnitTests { @@ -164,4 +164,19 @@ public class SortUnitTests {
public void orderWithDefaultNullHandlingHint() {
assertThat(new Order("foo").getNullHandling(), is(NATIVE));
}
/**
* @see DATACMNS-908
*/
@Test
public void createsNewOrderForDifferentProperty() {
Order source = new Order(Direction.DESC, "foo").nullsFirst().ignoreCase();
Order result = source.withProperty("bar");
assertThat(result.getProperty(), is("bar"));
assertThat(result.getDirection(), is(source.getDirection()));
assertThat(result.getNullHandling(), is(source.getNullHandling()));
assertThat(result.isIgnoreCase(), is(source.isIgnoreCase()));
}
}

Loading…
Cancel
Save