javadoc
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@75 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
07076642a3
commit
18b42bb979
|
|
@ -20,14 +20,14 @@ import java.util.List;
|
||||||
import org.antlr.runtime.Token;
|
import org.antlr.runtime.Token;
|
||||||
import org.springframework.expression.EvaluationException;
|
import org.springframework.expression.EvaluationException;
|
||||||
import org.springframework.expression.TypeComparator;
|
import org.springframework.expression.TypeComparator;
|
||||||
|
import org.springframework.expression.spel.ExpressionState;
|
||||||
import org.springframework.expression.spel.SpelException;
|
import org.springframework.expression.spel.SpelException;
|
||||||
import org.springframework.expression.spel.SpelMessages;
|
import org.springframework.expression.spel.SpelMessages;
|
||||||
import org.springframework.expression.spel.ExpressionState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the between operator. The left operand to between must be a single value and the right operand must be a
|
* Represents the between operator. The left operand to between must be a single value and the right operand must be a
|
||||||
* list - this operator returns true if the left operand is between (using the registered comparator) the two elements
|
* list - this operator returns true if the left operand is between (using the registered comparator) the two elements
|
||||||
* in the list.
|
* in the list. The definition of between being inclusive follows the SQL BETWEEN definition.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
*/
|
*/
|
||||||
|
|
@ -42,8 +42,16 @@ public class OperatorBetween extends Operator {
|
||||||
return "between";
|
return "between";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a boolean based on whether a value is in the range expressed. The first operand is any value whilst the
|
||||||
|
* second is a list of two values - those two values being the bounds allowed for the first operand (inclusive).
|
||||||
|
*
|
||||||
|
* @param state the expression state
|
||||||
|
* @return true if the left operand is in the range specified, false otherwise
|
||||||
|
* @throws EvaluationException if there is a problem evaluating the expression
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(ExpressionState state) throws EvaluationException {
|
public Boolean getValue(ExpressionState state) throws EvaluationException {
|
||||||
Object left = getLeftOperand().getValue(state);
|
Object left = getLeftOperand().getValue(state);
|
||||||
Object right = getRightOperand().getValue(state);
|
Object right = getRightOperand().getValue(state);
|
||||||
if (!(right instanceof List) || ((List<?>) right).size() != 2) {
|
if (!(right instanceof List) || ((List<?>) right).size() != 2) {
|
||||||
|
|
@ -55,11 +63,10 @@ public class OperatorBetween extends Operator {
|
||||||
Object high = l.get(1);
|
Object high = l.get(1);
|
||||||
TypeComparator comparator = state.getTypeComparator();
|
TypeComparator comparator = state.getTypeComparator();
|
||||||
try {
|
try {
|
||||||
// TODO between is inclusive, is that OK
|
|
||||||
return (comparator.compare(left, low) >= 0 && comparator.compare(left, high) <= 0);
|
return (comparator.compare(left, low) >= 0 && comparator.compare(left, high) <= 0);
|
||||||
} catch (SpelException ee) {
|
} catch (SpelException ex) {
|
||||||
ee.setPosition(getCharPositionInLine());
|
ex.setPosition(getCharPositionInLine());
|
||||||
throw ee;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue