Search in sources :

Example 1 with IntegerRange

use of org.apache.tapestry5.commons.util.IntegerRange in project tapestry-5 by apache.

the class PropertyConduitSourceImplTest method range_variable_from.

@Test
public void range_variable_from() {
    PropertyConduit pc = source.create(IntegerHolder.class, "value..99");
    IntegerHolder h = new IntegerHolder();
    h.setValue(72);
    IntegerRange ir = (IntegerRange) pc.get(h);
    assertEquals(ir, new IntegerRange(72, 99));
}
Also used : IntegerRange(org.apache.tapestry5.commons.util.IntegerRange) IntegerHolder(org.apache.tapestry5.integration.app1.data.IntegerHolder) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) InternalPropertyConduit(org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit) PropBindingFactoryTest(org.apache.tapestry5.internal.bindings.PropBindingFactoryTest) Test(org.testng.annotations.Test)

Example 2 with IntegerRange

use of org.apache.tapestry5.commons.util.IntegerRange in project tapestry-5 by apache.

the class IntegerRangeTest method finish_less_than_start.

@Test
public void finish_less_than_start() {
    IntegerRange r = new IntegerRange(3, 1);
    assertEquals(r.toString(), "3..1");
    Iterator<Integer> i = r.iterator();
    assertEquals(i.next().intValue(), 3);
    assertEquals(i.next().intValue(), 2);
    assertTrue(i.hasNext());
    assertEquals(i.next().intValue(), 1);
    assertFalse(i.hasNext());
    try {
        i.next();
        unreachable();
    } catch (IllegalStateException ex) {
    }
}
Also used : IntegerRange(org.apache.tapestry5.commons.util.IntegerRange) Test(org.testng.annotations.Test)

Example 3 with IntegerRange

use of org.apache.tapestry5.commons.util.IntegerRange in project tapestry-5 by apache.

the class IntegerRangeTest method hash_code_and_equals.

@Test
public void hash_code_and_equals() {
    IntegerRange r1 = new IntegerRange(1, 100);
    IntegerRange r2 = new IntegerRange(1, 100);
    IntegerRange r3 = new IntegerRange(1, 10);
    assertEquals(r1.hashCode(), r2.hashCode());
    assertFalse(r1.hashCode() == r3.hashCode());
    assertTrue(r1.equals(r1));
    assertEquals(r1, r2);
    assertFalse(r1.equals(r3));
    assertFalse(r1.equals(this));
    assertFalse(r1.equals(null));
    assertFalse(r1.equals(new IntegerRange(3, 30)));
}
Also used : IntegerRange(org.apache.tapestry5.commons.util.IntegerRange) Test(org.testng.annotations.Test)

Example 4 with IntegerRange

use of org.apache.tapestry5.commons.util.IntegerRange in project tapestry-5 by apache.

the class IntegerRangeTest method start_same_as_finish.

@Test
public void start_same_as_finish() {
    IntegerRange r = new IntegerRange(3, 3);
    Iterator<Integer> i = r.iterator();
    assertTrue(i.hasNext());
    assertEquals(i.next().intValue(), 3);
    assertFalse(i.hasNext());
}
Also used : IntegerRange(org.apache.tapestry5.commons.util.IntegerRange) Test(org.testng.annotations.Test)

Example 5 with IntegerRange

use of org.apache.tapestry5.commons.util.IntegerRange in project tapestry-5 by apache.

the class PropertyConduitSourceImpl method build.

/**
 * Builds a subclass of {@link PropertyConduitDelegate} that implements the
 * get() and set() methods and overrides the
 * constructor. In a worst-case race condition, we may build two (or more)
 * conduits for the same
 * rootClass/expression, and it will get sorted out when the conduit is
 * stored into the cache.
 *
 * @param rootClass
 *         class of root object for expression evaluation
 * @param expression
 *         expression to be evaluated
 * @return the conduit
 */
private PropertyConduit build(final Class rootClass, String expression) {
    Tree tree = parse(expression);
    try {
        switch(tree.getType()) {
            case TRUE:
                return literalTrue;
            case FALSE:
                return literalFalse;
            case NULL:
                return literalNull;
            case INTEGER:
                return createLiteralConduit(Long.class, new Long(tree.getText()));
            case DECIMAL:
                return createLiteralConduit(Double.class, new Double(tree.getText()));
            case STRING:
                return createLiteralConduit(String.class, tree.getText());
            case RANGEOP:
                Tree fromNode = tree.getChild(0);
                Tree toNode = tree.getChild(1);
                if (fromNode.getType() != INTEGER || toNode.getType() != INTEGER)
                    break;
                int from = Integer.parseInt(fromNode.getText());
                int to = Integer.parseInt(toNode.getText());
                IntegerRange ir = new IntegerRange(from, to);
                return createLiteralConduit(IntegerRange.class, ir);
            case THIS:
                return createLiteralThisPropertyConduit(rootClass);
            default:
                break;
        }
        return proxyFactory.createProxy(InternalPropertyConduit.class, new PropertyConduitBuilder(rootClass, expression, tree)).newInstance();
    } catch (Exception ex) {
        throw new PropertyExpressionException(String.format("Exception generating conduit for expression '%s': %s", expression, ExceptionUtils.toMessage(ex)), expression, ex);
    }
}
Also used : InternalPropertyConduit(org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit) IntegerRange(org.apache.tapestry5.commons.util.IntegerRange) Tree(org.antlr.runtime.tree.Tree) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) IOException(java.io.IOException)

Aggregations

IntegerRange (org.apache.tapestry5.commons.util.IntegerRange)8 Test (org.testng.annotations.Test)7 InternalPropertyConduit (org.apache.tapestry5.beanmodel.internal.InternalPropertyConduit)3 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 IntegerHolder (org.apache.tapestry5.integration.app1.data.IntegerHolder)2 PropBindingFactoryTest (org.apache.tapestry5.internal.bindings.PropBindingFactoryTest)2 IOException (java.io.IOException)1 Tree (org.antlr.runtime.tree.Tree)1 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)1