org.springframework.expression.TypeComparator Java Examples
The following examples show how to use
org.springframework.expression.TypeComparator.
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: OperatorBetween.java From spring4-understanding with Apache License 2.0 | 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 #2
Source File: OperatorBetween.java From lams with GNU General Public License v2.0 | 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: 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 #4
Source File: OperatorBetween.java From spring-analysis-note 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 #5
Source File: DefaultComparatorUnitTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testNonPrimitiveNumbers() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); BigDecimal bdOne = new BigDecimal("1"); BigDecimal bdTwo = new BigDecimal("2"); assertTrue(comparator.compare(bdOne, bdTwo) < 0); assertTrue(comparator.compare(bdOne, new BigDecimal("1")) == 0); assertTrue(comparator.compare(bdTwo, bdOne) > 0); assertTrue(comparator.compare(1, bdTwo) < 0); assertTrue(comparator.compare(1, bdOne) == 0); assertTrue(comparator.compare(2, bdOne) > 0); assertTrue(comparator.compare(1.0d, bdTwo) < 0); assertTrue(comparator.compare(1.0d, bdOne) == 0); assertTrue(comparator.compare(2.0d, bdOne) > 0); assertTrue(comparator.compare(1.0f, bdTwo) < 0); assertTrue(comparator.compare(1.0f, bdOne) == 0); assertTrue(comparator.compare(2.0f, bdOne) > 0); assertTrue(comparator.compare(1L, bdTwo) < 0); assertTrue(comparator.compare(1L, bdOne) == 0); assertTrue(comparator.compare(2L, bdOne) > 0); }
Example #6
Source File: DefaultComparatorUnitTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testCanCompare() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.canCompare(null,1)); assertTrue(comparator.canCompare(1,null)); assertTrue(comparator.canCompare(2,1)); assertTrue(comparator.canCompare("abc","def")); assertTrue(comparator.canCompare("abc",3)); assertFalse(comparator.canCompare(String.class,3)); }
Example #7
Source File: DefaultComparatorUnitTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testObjects() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.compare("a","a")==0); assertTrue(comparator.compare("a","b")<0); assertTrue(comparator.compare("b","a")>0); }
Example #8
Source File: DefaultComparatorUnitTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testNulls() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.compare(null,"abc")<0); assertTrue(comparator.compare(null,null)==0); assertTrue(comparator.compare("abc",null)>0); }
Example #9
Source File: DefaultComparatorUnitTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testNonPrimitiveNumbers() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); BigDecimal bdOne = new BigDecimal("1"); BigDecimal bdTwo = new BigDecimal("2"); assertTrue(comparator.compare(bdOne, bdTwo) < 0); assertTrue(comparator.compare(bdOne, new BigDecimal("1")) == 0); assertTrue(comparator.compare(bdTwo, bdOne) > 0); assertTrue(comparator.compare(1, bdTwo) < 0); assertTrue(comparator.compare(1, bdOne) == 0); assertTrue(comparator.compare(2, bdOne) > 0); assertTrue(comparator.compare(1.0d, bdTwo) < 0); assertTrue(comparator.compare(1.0d, bdOne) == 0); assertTrue(comparator.compare(2.0d, bdOne) > 0); assertTrue(comparator.compare(1.0f, bdTwo) < 0); assertTrue(comparator.compare(1.0f, bdOne) == 0); assertTrue(comparator.compare(2.0f, bdOne) > 0); assertTrue(comparator.compare(1L, bdTwo) < 0); assertTrue(comparator.compare(1L, bdOne) == 0); assertTrue(comparator.compare(2L, bdOne) > 0); }
Example #10
Source File: DefaultComparatorUnitTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testPrimitives() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); // primitive int assertTrue(comparator.compare(1, 2) < 0); assertTrue(comparator.compare(1, 1) == 0); assertTrue(comparator.compare(2, 1) > 0); assertTrue(comparator.compare(1.0d, 2) < 0); assertTrue(comparator.compare(1.0d, 1) == 0); assertTrue(comparator.compare(2.0d, 1) > 0); assertTrue(comparator.compare(1.0f, 2) < 0); assertTrue(comparator.compare(1.0f, 1) == 0); assertTrue(comparator.compare(2.0f, 1) > 0); assertTrue(comparator.compare(1L, 2) < 0); assertTrue(comparator.compare(1L, 1) == 0); assertTrue(comparator.compare(2L, 1) > 0); assertTrue(comparator.compare(1, 2L) < 0); assertTrue(comparator.compare(1, 1L) == 0); assertTrue(comparator.compare(2, 1L) > 0); assertTrue(comparator.compare(1L, 2L) < 0); assertTrue(comparator.compare(1L, 1L) == 0); assertTrue(comparator.compare(2L, 1L) > 0); }
Example #11
Source File: StandardComponentsTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testStandardEvaluationContext() { StandardEvaluationContext context = new StandardEvaluationContext(); assertNotNull(context.getTypeComparator()); TypeComparator tc = new StandardTypeComparator(); context.setTypeComparator(tc); assertEquals(tc, context.getTypeComparator()); TypeLocator tl = new StandardTypeLocator(); context.setTypeLocator(tl); assertEquals(tl, context.getTypeLocator()); }
Example #12
Source File: DefaultComparatorUnitTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testCanCompare() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.canCompare(null,1)); assertTrue(comparator.canCompare(1,null)); assertTrue(comparator.canCompare(2,1)); assertTrue(comparator.canCompare("abc","def")); assertTrue(comparator.canCompare("abc",3)); assertFalse(comparator.canCompare(String.class,3)); }
Example #13
Source File: DefaultComparatorUnitTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testObjects() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.compare("a","a")==0); assertTrue(comparator.compare("a","b")<0); assertTrue(comparator.compare("b","a")>0); }
Example #14
Source File: DefaultComparatorUnitTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testNulls() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.compare(null,"abc")<0); assertTrue(comparator.compare(null,null)==0); assertTrue(comparator.compare("abc",null)>0); }
Example #15
Source File: DefaultComparatorUnitTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testPrimitives() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); // primitive int assertTrue(comparator.compare(1, 2) < 0); assertTrue(comparator.compare(1, 1) == 0); assertTrue(comparator.compare(2, 1) > 0); assertTrue(comparator.compare(1.0d, 2) < 0); assertTrue(comparator.compare(1.0d, 1) == 0); assertTrue(comparator.compare(2.0d, 1) > 0); assertTrue(comparator.compare(1.0f, 2) < 0); assertTrue(comparator.compare(1.0f, 1) == 0); assertTrue(comparator.compare(2.0f, 1) > 0); assertTrue(comparator.compare(1L, 2) < 0); assertTrue(comparator.compare(1L, 1) == 0); assertTrue(comparator.compare(2L, 1) > 0); assertTrue(comparator.compare(1, 2L) < 0); assertTrue(comparator.compare(1, 1L) == 0); assertTrue(comparator.compare(2, 1L) > 0); assertTrue(comparator.compare(1L, 2L) < 0); assertTrue(comparator.compare(1L, 1L) == 0); assertTrue(comparator.compare(2L, 1L) > 0); }
Example #16
Source File: StandardComponentsTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testStandardEvaluationContext() { StandardEvaluationContext context = new StandardEvaluationContext(); assertNotNull(context.getTypeComparator()); TypeComparator tc = new StandardTypeComparator(); context.setTypeComparator(tc); assertEquals(tc, context.getTypeComparator()); TypeLocator tl = new StandardTypeLocator(); context.setTypeLocator(tl); assertEquals(tl, context.getTypeLocator()); }
Example #17
Source File: DefaultComparatorUnitTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCanCompare() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.canCompare(null,1)); assertTrue(comparator.canCompare(1,null)); assertTrue(comparator.canCompare(2,1)); assertTrue(comparator.canCompare("abc","def")); assertTrue(comparator.canCompare("abc",3)); assertFalse(comparator.canCompare(String.class,3)); }
Example #18
Source File: DefaultComparatorUnitTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testObjects() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.compare("a","a")==0); assertTrue(comparator.compare("a","b")<0); assertTrue(comparator.compare("b","a")>0); }
Example #19
Source File: DefaultComparatorUnitTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testNulls() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); assertTrue(comparator.compare(null,"abc")<0); assertTrue(comparator.compare(null,null)==0); assertTrue(comparator.compare("abc",null)>0); }
Example #20
Source File: StandardComponentsTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testStandardEvaluationContext() { StandardEvaluationContext context = new StandardEvaluationContext(); assertNotNull(context.getTypeComparator()); TypeComparator tc = new StandardTypeComparator(); context.setTypeComparator(tc); assertEquals(tc, context.getTypeComparator()); TypeLocator tl = new StandardTypeLocator(); context.setTypeLocator(tl); assertEquals(tl, context.getTypeLocator()); }
Example #21
Source File: DefaultComparatorUnitTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testPrimitives() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); // primitive int assertTrue(comparator.compare(1, 2) < 0); assertTrue(comparator.compare(1, 1) == 0); assertTrue(comparator.compare(2, 1) > 0); assertTrue(comparator.compare(1.0d, 2) < 0); assertTrue(comparator.compare(1.0d, 1) == 0); assertTrue(comparator.compare(2.0d, 1) > 0); assertTrue(comparator.compare(1.0f, 2) < 0); assertTrue(comparator.compare(1.0f, 1) == 0); assertTrue(comparator.compare(2.0f, 1) > 0); assertTrue(comparator.compare(1L, 2) < 0); assertTrue(comparator.compare(1L, 1) == 0); assertTrue(comparator.compare(2L, 1) > 0); assertTrue(comparator.compare(1, 2L) < 0); assertTrue(comparator.compare(1, 1L) == 0); assertTrue(comparator.compare(2, 1L) > 0); assertTrue(comparator.compare(1L, 2L) < 0); assertTrue(comparator.compare(1L, 1L) == 0); assertTrue(comparator.compare(2L, 1L) > 0); }
Example #22
Source File: DefaultComparatorUnitTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testNonPrimitiveNumbers() throws EvaluationException { TypeComparator comparator = new StandardTypeComparator(); BigDecimal bdOne = new BigDecimal("1"); BigDecimal bdTwo = new BigDecimal("2"); assertTrue(comparator.compare(bdOne, bdTwo) < 0); assertTrue(comparator.compare(bdOne, new BigDecimal("1")) == 0); assertTrue(comparator.compare(bdTwo, bdOne) > 0); assertTrue(comparator.compare(1, bdTwo) < 0); assertTrue(comparator.compare(1, bdOne) == 0); assertTrue(comparator.compare(2, bdOne) > 0); assertTrue(comparator.compare(1.0d, bdTwo) < 0); assertTrue(comparator.compare(1.0d, bdOne) == 0); assertTrue(comparator.compare(2.0d, bdOne) > 0); assertTrue(comparator.compare(1.0f, bdTwo) < 0); assertTrue(comparator.compare(1.0f, bdOne) == 0); assertTrue(comparator.compare(2.0f, bdOne) > 0); assertTrue(comparator.compare(1L, bdTwo) < 0); assertTrue(comparator.compare(1L, bdOne) == 0); assertTrue(comparator.compare(2L, bdOne) > 0); }
Example #23
Source File: SimpleEvaluationContext.java From spring-analysis-note with MIT License | 4 votes |
/** * Return an instance of {@link StandardTypeComparator}. */ @Override public TypeComparator getTypeComparator() { return this.typeComparator; }
Example #24
Source File: ExpressionState.java From java-technology-stack with MIT License | 4 votes |
public TypeComparator getTypeComparator() { return this.relatedContext.getTypeComparator(); }
Example #25
Source File: StandardEvaluationContext.java From spring-analysis-note with MIT License | 4 votes |
public void setTypeComparator(TypeComparator typeComparator) { Assert.notNull(typeComparator, "TypeComparator must not be null"); this.typeComparator = typeComparator; }
Example #26
Source File: StandardEvaluationContext.java From spring-analysis-note with MIT License | 4 votes |
@Override public TypeComparator getTypeComparator() { return this.typeComparator; }
Example #27
Source File: ExpressionState.java From spring-analysis-note with MIT License | 4 votes |
public TypeComparator getTypeComparator() { return this.relatedContext.getTypeComparator(); }
Example #28
Source File: ExpressionState.java From spring4-understanding with Apache License 2.0 | 4 votes |
public TypeComparator getTypeComparator() { return this.relatedContext.getTypeComparator(); }
Example #29
Source File: StandardEvaluationContext.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public TypeComparator getTypeComparator() { return this.typeComparator; }
Example #30
Source File: StandardEvaluationContext.java From spring4-understanding with Apache License 2.0 | 4 votes |
public void setTypeComparator(TypeComparator typeComparator) { Assert.notNull(typeComparator, "TypeComparator must not be null"); this.typeComparator = typeComparator; }