/** * Creates a Predicate that invokes a method on the input object. * The method must return either a boolean or a non-null Boolean, * and have no parameters. If the input object is null, a * PredicateException is thrown. * <p> * For example, <code>PredicateUtils.invokerPredicate("isEmpty");</code> * will call the <code>isEmpty</code> method on the input object to * determine the predicate result. * * @see org.apache.commons.collections.functors.InvokerTransformer * @see org.apache.commons.collections.functors.TransformerPredicate * * @param methodName the method name to call on the input object, may not be null * @return the predicate * @throws IllegalArgumentException if the methodName is null. */ public static Predicate invokerPredicate(String methodName){ // reuse transformer as it has caching - this is lazy really, should have inner class here return asPredicate(InvokerTransformer.getInstance(methodName)); }
/** * Create a new Predicate that returns true if neither of the specified * predicates are true. * * @see org.apache.commons.collections.functors.NonePredicate * * @param predicate1 the first predicate, may not be null * @param predicate2 the second predicate, may not be null * @return the <code>neither</code> predicate * @throws IllegalArgumentException if either predicate is null */ public static Predicate neitherPredicate(Predicate predicate1, Predicate predicate2) { return nonePredicate(new Predicate[] { predicate1, predicate2 }); }
/** * Create a new Predicate that returns true if one, but not both, of the * specified predicates are true. * * @see org.apache.commons.collections.functors.OnePredicate * * @param predicate1 the first predicate, may not be null * @param predicate2 the second predicate, may not be null * @return the <code>either</code> predicate * @throws IllegalArgumentException if either predicate is null */ public static Predicate eitherPredicate(Predicate predicate1, Predicate predicate2) { return onePredicate(new Predicate[] { predicate1, predicate2 }); }
public void testNeitherPredicate() { assertEquals(false, PredicateUtils.neitherPredicate(PredicateUtils.truePredicate(), PredicateUtils.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.neitherPredicate(PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.neitherPredicate(PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.neitherPredicate(PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()).evaluate(null)); }
public void testEitherPredicate() { assertEquals(false, PredicateUtils.eitherPredicate(PredicateUtils.truePredicate(), PredicateUtils.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.eitherPredicate(PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.eitherPredicate(PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.eitherPredicate(PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()).evaluate(null)); }
public void testAndPredicate() { assertEquals(true, PredicateUtils.andPredicate(PredicateUtils.truePredicate(), PredicateUtils.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.andPredicate(PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()).evaluate(null)); }
public void testOnePredicate() { assertFalse(PredicateUtils.onePredicate( new Predicate[] {}).evaluate(null)); assertEquals(false, PredicateUtils.onePredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.onePredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.onePredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.onePredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.onePredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.onePredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()}).evaluate(null)); Collection coll = new ArrayList(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.onePredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(true, PredicateUtils.onePredicate(coll).evaluate(null));
public void testNonePredicate() { assertTrue(PredicateUtils.nonePredicate( new Predicate[] {}).evaluate(null)); assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.nonePredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.nonePredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()}).evaluate(null)); Collection coll = new ArrayList(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.nonePredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate());
public void testNotPredicateEx() { try { PredicateUtils.notPredicate(null); } catch (IllegalArgumentException ex) { return; } fail(); }
public boolean evaluate(Object arg0) { Predicate judgement = new NullPredicate(); if (predicates.size() == 1) { judgement = predicates.get(0); } else { if (conj == Conjunction.AND) { judgement = PredicateUtils.allPredicate(predicates); } else if (conj == Conjunction.OR) { judgement = PredicateUtils.anyPredicate(predicates); } } return judgement.evaluate(arg0); }
public void testNotPredicate() { assertNotNull(PredicateUtils.notPredicate(PredicateUtils.truePredicate())); assertEquals(false, PredicateUtils.notPredicate(PredicateUtils.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.notPredicate(PredicateUtils.truePredicate()).evaluate(cObject)); assertEquals(false, PredicateUtils.notPredicate(PredicateUtils.truePredicate()).evaluate(cString)); assertEquals(false, PredicateUtils.notPredicate(PredicateUtils.truePredicate()).evaluate(cInteger)); }
@Override @SuppressWarnings("unchecked") public Iterator<Object> get(String field) throws IllegalArgumentException { if(field == null){ throw new IllegalArgumentException("The parsed field MUST NOT be NULL"); } else if(field.isEmpty()){ throw new IllegalArgumentException("The parsed field MUST NOT be Empty"); } URI property = sesameFactory.createURI(field); return IteratorUtils.transformedIterator( IteratorUtils.filteredIterator( IteratorUtils.transformedIterator( model.filter(subject, property, null).iterator(), objectTransFormer), // get the object from the statement notPredicate(instanceofPredicate(BNode.class))), org.apache.stanbol.entityhub.model.sesame.ModelUtils.VALUE_TRANSFORMER); // transform the values }
public void testAllPredicateEx5() { PredicateUtils.allPredicate(Collections.EMPTY_LIST); }
public void testAnyPredicate() { assertFalse(PredicateUtils.anyPredicate( new Predicate[] {}).evaluate(null)); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(true, PredicateUtils.anyPredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.anyPredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()}).evaluate(null)); Collection coll = new ArrayList(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(true, PredicateUtils.anyPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate());
public void testAllPredicate() { assertTrue(PredicateUtils.allPredicate( new Predicate[] {}).evaluate(null)); assertEquals(true, PredicateUtils.allPredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.truePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.allPredicate(new Predicate[] { PredicateUtils.truePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.allPredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()}).evaluate(null)); assertEquals(false, PredicateUtils.allPredicate(new Predicate[] { PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()}).evaluate(null)); Collection coll = new ArrayList(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(true, PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.truePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.truePredicate()); assertEquals(false, PredicateUtils.allPredicate(coll).evaluate(null)); coll.clear(); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate()); coll.add(PredicateUtils.falsePredicate());
public void testAnyPredicateEx5() { PredicateUtils.anyPredicate(Collections.EMPTY_LIST); }
@SuppressWarnings("unchecked") public static DescribableList<GhprbExtension, GhprbExtensionDescriptor> getJobExtensions( GhprbTrigger trigger, Class<?>... types ) { // First get all global extensions DescribableList<GhprbExtension, GhprbExtensionDescriptor> copied = copyExtensions(trigger.getDescriptor().getExtensions()); // Remove extensions that are specified by job filterList(copied, PredicateUtils.notPredicate(InstanceofPredicate.getInstance(GhprbProjectExtension.class))); // Then get the rest of the extensions from the job copied = copyExtensions(copied, trigger.getExtensions()); // Filter extensions by desired interface filterList(copied, PredicateUtils.anyPredicate(createPredicate(types))); return copied; }
public void testOrPredicate() { assertEquals(true, PredicateUtils.orPredicate(PredicateUtils.truePredicate(), PredicateUtils.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.orPredicate(PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.orPredicate(PredicateUtils.falsePredicate(), PredicateUtils.truePredicate()).evaluate(null)); assertEquals(false, PredicateUtils.orPredicate(PredicateUtils.falsePredicate(), PredicateUtils.falsePredicate()).evaluate(null)); }
@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; }
public void testNullIsFalsePredicate() { assertEquals(false, PredicateUtils.nullIsFalsePredicate(PredicateUtils.truePredicate()).evaluate(null)); assertEquals(true, PredicateUtils.nullIsFalsePredicate(PredicateUtils.truePredicate()).evaluate(new Object())); assertEquals(false, PredicateUtils.nullIsFalsePredicate(PredicateUtils.falsePredicate()).evaluate(new Object())); }