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));
}
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) {
}
}
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)));
}
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());
}
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);
}
}
Aggregations