DATACMNS-281 - Added support to Order for case insensitive sorts.

Modified the Order class to allow an ignore case flag to be set so that case insensitive sorts could be supported.
This commit is contained in:
Kevin Raymond
2013-02-08 16:54:16 -05:00
committed by Oliver Gierke
parent b26f09f3b4
commit a588f43857
2 changed files with 73 additions and 19 deletions

View File

@@ -234,13 +234,16 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
* {@link Sort}
*
* @author Oliver Gierke
* @author Kevin Raymond
*/
public static class Order implements Serializable {
private static final long serialVersionUID = 1522511010900108987L;
private static final boolean DEFAULT_IGNORE_CASE = false;
private final Direction direction;
private final String property;
private final boolean ignoreCase;
/**
* Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
@@ -251,12 +254,7 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
*/
public Order(Direction direction, String property) {
if (!StringUtils.hasText(property)) {
throw new IllegalArgumentException("Property must not null or empty!");
}
this.direction = direction == null ? DEFAULT_DIRECTION : direction;
this.property = property;
this(direction, property, DEFAULT_IGNORE_CASE);
}
/**
@@ -269,6 +267,25 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
this(DEFAULT_DIRECTION, property);
}
/**
* Creates a new {@link Order} instance. if order is {@literal null} then order defaults to
* {@link Sort#DEFAULT_DIRECTION}
*
* @param direction can be {@literal null}, will default to {@link Sort#DEFAULT_DIRECTION}
* @param property must not be {@literal null} or empty.
* @param ignoreCase true if sorting should be case insensitive. false if sorting should be case sensitive.
*/
private Order(Direction direction, String property, boolean ignoreCase) {
if (!StringUtils.hasText(property)) {
throw new IllegalArgumentException("Property must not null or empty!");
}
this.direction = direction == null ? DEFAULT_DIRECTION : direction;
this.property = property;
this.ignoreCase = ignoreCase;
}
/**
* @deprecated use {@link Sort#Sort(Direction, List)} instead.
*/
@@ -309,6 +326,15 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
return this.direction.equals(Direction.ASC);
}
/**
* Returns whether or not the sort will be case sensitive.
*
* @return
*/
public boolean isIgnoreCase() {
return ignoreCase;
}
/**
* Returns a new {@link Order} with the given {@link Order}.
*
@@ -329,6 +355,15 @@ public class Sort implements Iterable<org.springframework.data.domain.Sort.Order
return new Sort(this.direction, properties);
}
/**
* Returns a new {@link Order} with case insensitive sorting enabled.
*
* @return
*/
public Order ignoreCase() {
return new Order(direction, property, true);
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()