public void testEqualPredicate() { assertSame(PredicateUtils.nullPredicate(), PredicateUtils.equalPredicate(null)); assertNotNull(PredicateUtils.equalPredicate(new Integer(6))); assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(null)); assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cObject)); assertEquals(false, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cString)); assertEquals(true, PredicateUtils.equalPredicate(new Integer(6)).evaluate(cInteger)); }
public void testFind() { Predicate testPredicate = PredicateUtils.equalPredicate("d"); Object test = CollectionUtils.find(collectionA, testPredicate); assertTrue(test.equals("d")); testPredicate = PredicateUtils.equalPredicate("de"); test = CollectionUtils.find(collectionA, testPredicate); assertTrue(test == null); assertEquals(CollectionUtils.find(null,testPredicate), null); assertEquals(CollectionUtils.find(collectionA, null), null); }
public void testTransformedPredicate() { assertEquals(true, PredicateUtils.transformedPredicate( TransformerUtils.nopTransformer(), PredicateUtils.truePredicate()).evaluate(new Object())); Map map = new HashMap(); map.put(Boolean.TRUE, "Hello"); Transformer t = TransformerUtils.mapTransformer(map); Predicate p = PredicateUtils.equalPredicate("Hello"); assertEquals(false, PredicateUtils.transformedPredicate(t, p).evaluate(null)); assertEquals(true, PredicateUtils.transformedPredicate(t, p).evaluate(Boolean.TRUE)); try { PredicateUtils.transformedPredicate(null, null); fail(); } catch (IllegalArgumentException ex) {} }
MockClosure b = new MockClosure(); ClosureUtils.switchClosure( new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Closure[] {a, b}).execute("WELL"); assertEquals(0, a.count); b = new MockClosure(); ClosureUtils.switchClosure( new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Closure[] {a, b}).execute("HELLO"); assertEquals(1, a.count); MockClosure c = new MockClosure(); ClosureUtils.switchClosure( new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Closure[] {a, b}, c).execute("WELL"); assertEquals(0, a.count); b = new MockClosure(); Map map = new HashMap(); map.put(PredicateUtils.equalPredicate("HELLO"), a); map.put(PredicateUtils.equalPredicate("THERE"), b); ClosureUtils.switchClosure(map).execute(null); assertEquals(0, a.count); b = new MockClosure(); map = new HashMap(); map.put(PredicateUtils.equalPredicate("HELLO"), a); map.put(PredicateUtils.equalPredicate("THERE"), b);
new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Transformer[] {a, b}).transform("WELL")); assertEquals("A", TransformerUtils.switchTransformer( new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Transformer[] {a, b}).transform("HELLO")); assertEquals("B", TransformerUtils.switchTransformer( new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Transformer[] {a, b}).transform("THERE")); new Predicate[] {PredicateUtils.equalPredicate("HELLO"), PredicateUtils.equalPredicate("THERE")}, new Transformer[] {a, b}, c).transform("WELL")); map.put(PredicateUtils.equalPredicate("HELLO"), a); map.put(PredicateUtils.equalPredicate("THERE"), b); assertEquals(null, TransformerUtils.switchTransformer(map).transform("WELL")); assertEquals("A", TransformerUtils.switchTransformer(map).transform("HELLO"));
@SuppressWarnings("unchecked") private Iterator<String> wrapIterator(final Iterator<String> keysIterator) { final String childNodeKey = childNodeKey(""); if (StringUtils.isEmpty(childNodeKey)) { return keysIterator; } final FilterIterator filterIterator = new FilterIterator(keysIterator, PredicateUtils.notPredicate(PredicateUtils.equalPredicate(childNodeKey))); AbstractIteratorDecorator iteratorDecorator = new AbstractIteratorDecorator(filterIterator) { @Override public Object next() { String key = (String) super.next(); String stripKey; if (!key.startsWith(childNodeKey)) { stripKey = key; } else { stripKey = key.substring(childNodeKey.length()+1); } return stripKey; } }; return iteratorDecorator; }