Package org.springframework.expression

Examples of org.springframework.expression.TypeComparator


          SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST);
    }
    List<?> l = (List<?>) right;
    Object low = l.get(0);
    Object high = l.get(1);
    TypeComparator comparator = state.getTypeComparator();
    try {
      return BooleanTypedValue.forValue((comparator.compare(left, low) >= 0 && comparator.compare(left, high) <= 0));
    } catch (SpelEvaluationException ex) {
      ex.setPosition(getStartPosition());
      throw ex;
    }
  }
View Full Code Here


*/
public class DefaultComparatorUnitTests {

  @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);
  }
View Full Code Here

    assertTrue(comparator.compare(2L, 1L) > 0);
  }

  @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);

  }
View Full Code Here

  }

  @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);
  }
View Full Code Here

    assertTrue(comparator.compare("abc",null)>0);
  }

  @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);
  }
View Full Code Here

    assertTrue(comparator.compare("b","a")>0);
  }

  @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));
  }
View Full Code Here

  @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);
View Full Code Here

    }

    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;
    }
View Full Code Here

TOP

Related Classes of org.springframework.expression.TypeComparator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.