Java Code Examples for org.springframework.expression.spel.support.BooleanTypedValue#forValue()
The following examples show how to use
org.springframework.expression.spel.support.BooleanTypedValue#forValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OperatorInstanceof.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Compare the left operand to see it is an instance of the type specified as the * right operand. The right operand must be a class. * @param state the expression state * @return true if the left operand is an instanceof of the right operand, otherwise * false * @throws EvaluationException if there is a problem evaluating the expression */ @Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { TypedValue left = getLeftOperand().getValueInternal(state); TypedValue right = getRightOperand().getValueInternal(state); Object leftValue = left.getValue(); Object rightValue = right.getValue(); BooleanTypedValue result = null; if (rightValue == null || !(rightValue instanceof Class<?>)) { throw new SpelEvaluationException(getRightOperand().getStartPosition(), SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND, (rightValue == null ? "null" : rightValue.getClass().getName())); } Class<?> rightClass = (Class<?>) rightValue; if (leftValue == null) { result = BooleanTypedValue.FALSE; // null is not an instanceof anything } else { result = BooleanTypedValue.forValue(rightClass.isAssignableFrom(leftValue.getClass())); } this.type = rightClass; this.exitTypeDescriptor = "Z"; return result; }
Example 2
Source File: OperatorBetween.java From java-technology-stack with MIT License | 6 votes |
/** * 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 public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); if (!(right instanceof List) || ((List<?>) right).size() != 2) { throw new SpelEvaluationException(getRightOperand().getStartPosition(), SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST); } List<?> list = (List<?>) right; Object low = list.get(0); Object high = list.get(1); TypeComparator comp = state.getTypeComparator(); try { return BooleanTypedValue.forValue(comp.compare(left, low) >= 0 && comp.compare(left, high) <= 0); } catch (SpelEvaluationException ex) { ex.setPosition(getStartPosition()); throw ex; } }
Example 3
Source File: OperatorInstanceof.java From java-technology-stack with MIT License | 5 votes |
/** * Compare the left operand to see it is an instance of the type specified as the * right operand. The right operand must be a class. * @param state the expression state * @return {@code true} if the left operand is an instanceof of the right operand, * otherwise {@code false} * @throws EvaluationException if there is a problem evaluating the expression */ @Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { SpelNodeImpl rightOperand = getRightOperand(); TypedValue left = getLeftOperand().getValueInternal(state); TypedValue right = rightOperand.getValueInternal(state); Object leftValue = left.getValue(); Object rightValue = right.getValue(); BooleanTypedValue result; if (rightValue == null || !(rightValue instanceof Class)) { throw new SpelEvaluationException(getRightOperand().getStartPosition(), SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND, (rightValue == null ? "null" : rightValue.getClass().getName())); } Class<?> rightClass = (Class<?>) rightValue; if (leftValue == null) { result = BooleanTypedValue.FALSE; // null is not an instanceof anything } else { result = BooleanTypedValue.forValue(rightClass.isAssignableFrom(leftValue.getClass())); } this.type = rightClass; if (rightOperand instanceof TypeReference) { // Can only generate bytecode where the right operand is a direct type reference, // not if it is indirect (for example when right operand is a variable reference) this.exitTypeDescriptor = "Z"; } return result; }
Example 4
Source File: OpNE.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); return BooleanTypedValue.forValue( !equalityCheck(state.getEvaluationContext(), left, right)); }
Example 5
Source File: OperatorNot.java From spring-analysis-note with MIT License | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { try { Boolean value = this.children[0].getValue(state, Boolean.class); if (value == null) { throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean"); } return BooleanTypedValue.forValue(!value); } catch (SpelEvaluationException ex) { ex.setPosition(getChild(0).getStartPosition()); throw ex; } }
Example 6
Source File: OpNE.java From spring-analysis-note with MIT License | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object leftValue = getLeftOperand().getValueInternal(state).getValue(); Object rightValue = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(leftValue); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(rightValue); return BooleanTypedValue.forValue(!equalityCheck(state.getEvaluationContext(), leftValue, rightValue)); }
Example 7
Source File: OpOr.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { if (getBooleanValue(state, getLeftOperand())) { // no need to evaluate right operand return BooleanTypedValue.TRUE; } return BooleanTypedValue.forValue(getBooleanValue(state, getRightOperand())); }
Example 8
Source File: OpEQ.java From spring-analysis-note with MIT License | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); return BooleanTypedValue.forValue(equalityCheck(state.getEvaluationContext(), left, right)); }
Example 9
Source File: OpNE.java From java-technology-stack with MIT License | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object leftValue = getLeftOperand().getValueInternal(state).getValue(); Object rightValue = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(leftValue); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(rightValue); return BooleanTypedValue.forValue(!equalityCheck(state.getEvaluationContext(), leftValue, rightValue)); }
Example 10
Source File: OpOr.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { if (getBooleanValue(state, getLeftOperand())) { // no need to evaluate right operand return BooleanTypedValue.TRUE; } return BooleanTypedValue.forValue(getBooleanValue(state, getRightOperand())); }
Example 11
Source File: OperatorNot.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { try { Boolean value = this.children[0].getValue(state, Boolean.class); if (value == null) { throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean"); } return BooleanTypedValue.forValue(!value); } catch (SpelEvaluationException ex) { ex.setPosition(getChild(0).getStartPosition()); throw ex; } }
Example 12
Source File: OpAnd.java From java-technology-stack with MIT License | 5 votes |
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { if (!getBooleanValue(state, getLeftOperand())) { // no need to evaluate right operand return BooleanTypedValue.FALSE; } return BooleanTypedValue.forValue(getBooleanValue(state, getRightOperand())); }
Example 13
Source File: OpOr.java From java-technology-stack with MIT License | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { if (getBooleanValue(state, getLeftOperand())) { // no need to evaluate right operand return BooleanTypedValue.TRUE; } return BooleanTypedValue.forValue(getBooleanValue(state, getRightOperand())); }
Example 14
Source File: OperatorNot.java From java-technology-stack with MIT License | 5 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { try { Boolean value = this.children[0].getValue(state, Boolean.class); if (value == null) { throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean"); } return BooleanTypedValue.forValue(!value); } catch (SpelEvaluationException ex) { ex.setPosition(getChild(0).getStartPosition()); throw ex; } }
Example 15
Source File: OpLE.java From spring-analysis-note with MIT License | 4 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); if (left instanceof Number && right instanceof Number) { Number leftNumber = (Number) left; Number rightNumber = (Number) right; if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) { BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class); BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class); return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) <= 0); } else if (leftNumber instanceof Double || rightNumber instanceof Double) { return BooleanTypedValue.forValue(leftNumber.doubleValue() <= rightNumber.doubleValue()); } else if (leftNumber instanceof Float || rightNumber instanceof Float) { return BooleanTypedValue.forValue(leftNumber.floatValue() <= rightNumber.floatValue()); } else if (leftNumber instanceof BigInteger || rightNumber instanceof BigInteger) { BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class); return BooleanTypedValue.forValue(leftBigInteger.compareTo(rightBigInteger) <= 0); } else if (leftNumber instanceof Long || rightNumber instanceof Long) { return BooleanTypedValue.forValue(leftNumber.longValue() <= rightNumber.longValue()); } else if (leftNumber instanceof Integer || rightNumber instanceof Integer) { return BooleanTypedValue.forValue(leftNumber.intValue() <= rightNumber.intValue()); } else if (leftNumber instanceof Short || rightNumber instanceof Short) { return BooleanTypedValue.forValue(leftNumber.shortValue() <= rightNumber.shortValue()); } else if (leftNumber instanceof Byte || rightNumber instanceof Byte) { return BooleanTypedValue.forValue(leftNumber.byteValue() <= rightNumber.byteValue()); } else { // Unknown Number subtypes -> best guess is double comparison return BooleanTypedValue.forValue(leftNumber.doubleValue() <= rightNumber.doubleValue()); } } return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) <= 0); }
Example 16
Source File: OpGE.java From java-technology-stack with MIT License | 4 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); if (left instanceof Number && right instanceof Number) { Number leftNumber = (Number) left; Number rightNumber = (Number) right; if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) { BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class); BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class); return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) >= 0); } else if (leftNumber instanceof Double || rightNumber instanceof Double) { return BooleanTypedValue.forValue(leftNumber.doubleValue() >= rightNumber.doubleValue()); } else if (leftNumber instanceof Float || rightNumber instanceof Float) { return BooleanTypedValue.forValue(leftNumber.floatValue() >= rightNumber.floatValue()); } else if (leftNumber instanceof BigInteger || rightNumber instanceof BigInteger) { BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class); return BooleanTypedValue.forValue(leftBigInteger.compareTo(rightBigInteger) >= 0); } else if (leftNumber instanceof Long || rightNumber instanceof Long) { return BooleanTypedValue.forValue(leftNumber.longValue() >= rightNumber.longValue()); } else if (leftNumber instanceof Integer || rightNumber instanceof Integer) { return BooleanTypedValue.forValue(leftNumber.intValue() >= rightNumber.intValue()); } else if (leftNumber instanceof Short || rightNumber instanceof Short) { return BooleanTypedValue.forValue(leftNumber.shortValue() >= rightNumber.shortValue()); } else if (leftNumber instanceof Byte || rightNumber instanceof Byte) { return BooleanTypedValue.forValue(leftNumber.byteValue() >= rightNumber.byteValue()); } else { // Unknown Number subtypes -> best guess is double comparison return BooleanTypedValue.forValue(leftNumber.doubleValue() >= rightNumber.doubleValue()); } } return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) >= 0); }
Example 17
Source File: OpLT.java From spring-analysis-note with MIT License | 4 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); if (left instanceof Number && right instanceof Number) { Number leftNumber = (Number) left; Number rightNumber = (Number) right; if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) { BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class); BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class); return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) < 0); } else if (leftNumber instanceof Double || rightNumber instanceof Double) { return BooleanTypedValue.forValue(leftNumber.doubleValue() < rightNumber.doubleValue()); } else if (leftNumber instanceof Float || rightNumber instanceof Float) { return BooleanTypedValue.forValue(leftNumber.floatValue() < rightNumber.floatValue()); } else if (leftNumber instanceof BigInteger || rightNumber instanceof BigInteger) { BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class); return BooleanTypedValue.forValue(leftBigInteger.compareTo(rightBigInteger) < 0); } else if (leftNumber instanceof Long || rightNumber instanceof Long) { return BooleanTypedValue.forValue(leftNumber.longValue() < rightNumber.longValue()); } else if (leftNumber instanceof Integer || rightNumber instanceof Integer) { return BooleanTypedValue.forValue(leftNumber.intValue() < rightNumber.intValue()); } else if (leftNumber instanceof Short || rightNumber instanceof Short) { return BooleanTypedValue.forValue(leftNumber.shortValue() < rightNumber.shortValue()); } else if (leftNumber instanceof Byte || rightNumber instanceof Byte) { return BooleanTypedValue.forValue(leftNumber.byteValue() < rightNumber.byteValue()); } else { // Unknown Number subtypes -> best guess is double comparison return BooleanTypedValue.forValue(leftNumber.doubleValue() < rightNumber.doubleValue()); } } if (left instanceof CharSequence && right instanceof CharSequence) { left = left.toString(); right = right.toString(); } return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) < 0); }
Example 18
Source File: OpGT.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); if (left instanceof Number && right instanceof Number) { Number leftNumber = (Number) left; Number rightNumber = (Number) right; if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) { BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class); BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class); return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) > 0); } else if (leftNumber instanceof Double || rightNumber instanceof Double) { return BooleanTypedValue.forValue(leftNumber.doubleValue() > rightNumber.doubleValue()); } else if (leftNumber instanceof Float || rightNumber instanceof Float) { return BooleanTypedValue.forValue(leftNumber.floatValue() > rightNumber.floatValue()); } else if (leftNumber instanceof BigInteger || rightNumber instanceof BigInteger) { BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class); return BooleanTypedValue.forValue(leftBigInteger.compareTo(rightBigInteger) > 0); } else if (leftNumber instanceof Long || rightNumber instanceof Long) { return BooleanTypedValue.forValue(leftNumber.longValue() > rightNumber.longValue()); } else if (leftNumber instanceof Integer || rightNumber instanceof Integer) { return BooleanTypedValue.forValue(leftNumber.intValue() > rightNumber.intValue()); } else if (leftNumber instanceof Short || rightNumber instanceof Short) { return BooleanTypedValue.forValue(leftNumber.shortValue() > rightNumber.shortValue()); } else if (leftNumber instanceof Byte || rightNumber instanceof Byte) { return BooleanTypedValue.forValue(leftNumber.byteValue() > rightNumber.byteValue()); } else { // Unknown Number subtypes -> best guess is double comparison return BooleanTypedValue.forValue(leftNumber.doubleValue() > rightNumber.doubleValue()); } } if (left instanceof CharSequence && right instanceof CharSequence) { left = left.toString(); right = right.toString(); } return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) > 0); }
Example 19
Source File: BooleanLiteral.java From lams with GNU General Public License v2.0 | 4 votes |
public BooleanLiteral(String payload, int pos, boolean value) { super(payload, pos); this.value = BooleanTypedValue.forValue(value); this.exitTypeDescriptor = "Z"; }
Example 20
Source File: OpLE.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { Object left = getLeftOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue(); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); if (left instanceof Number && right instanceof Number) { Number leftNumber = (Number) left; Number rightNumber = (Number) right; if (leftNumber instanceof BigDecimal || rightNumber instanceof BigDecimal) { BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class); BigDecimal rightBigDecimal = NumberUtils.convertNumberToTargetClass(rightNumber, BigDecimal.class); return BooleanTypedValue.forValue(leftBigDecimal.compareTo(rightBigDecimal) <= 0); } else if (leftNumber instanceof Double || rightNumber instanceof Double) { return BooleanTypedValue.forValue(leftNumber.doubleValue() <= rightNumber.doubleValue()); } else if (leftNumber instanceof Float || rightNumber instanceof Float) { return BooleanTypedValue.forValue(leftNumber.floatValue() <= rightNumber.floatValue()); } else if (leftNumber instanceof BigInteger || rightNumber instanceof BigInteger) { BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); BigInteger rightBigInteger = NumberUtils.convertNumberToTargetClass(rightNumber, BigInteger.class); return BooleanTypedValue.forValue(leftBigInteger.compareTo(rightBigInteger) <= 0); } else if (leftNumber instanceof Long || rightNumber instanceof Long) { return BooleanTypedValue.forValue(leftNumber.longValue() <= rightNumber.longValue()); } else if (leftNumber instanceof Integer || rightNumber instanceof Integer) { return BooleanTypedValue.forValue(leftNumber.intValue() <= rightNumber.intValue()); } else if (leftNumber instanceof Short || rightNumber instanceof Short) { return BooleanTypedValue.forValue(leftNumber.shortValue() <= rightNumber.shortValue()); } else if (leftNumber instanceof Byte || rightNumber instanceof Byte) { return BooleanTypedValue.forValue(leftNumber.byteValue() <= rightNumber.byteValue()); } else { // Unknown Number subtypes -> best guess is double comparison return BooleanTypedValue.forValue(leftNumber.doubleValue() <= rightNumber.doubleValue()); } } return BooleanTypedValue.forValue(state.getTypeComparator().compare(left, right) <= 0); }