List of usage examples for org.apache.commons.collections4.functors AndPredicate AndPredicate
public AndPredicate(final Predicate<? super T> predicate1, final Predicate<? super T> predicate2)
From source file:com.link_intersystems.lang.reflect.ReflectFacade.java
/** * A {@link Predicate} that evaluates to true if it is evaluated against * {@link Member} objects and the {@link Member#getName()} is equal to the * memberName this Predicate was constructed with. * * @return {@link Predicate} that evaluates to true if the {@link Member}'s * name it is evaluated against is equal to the name that this * {@link MemberNamePredicate} was constructed with. * @since 1.0.0.0// w w w .j ava 2 s .c o m */ public static Predicate getMemberNamePredicate(String memberName) { Assert.notNull("memberName", memberName); class SerializableMemberNamePredicate implements SerializableReference<Predicate> { private static final long serialVersionUID = -625148437829360498L; private transient Predicate predicate; private final String memberName; public SerializableMemberNamePredicate(String memberName) { this.memberName = memberName; } public Predicate get() { if (predicate == null) { Method memberGetNameMethod = MethodUtils.getAccessibleMethod(Member.class, "getName", new Class<?>[0]); MethodInvokingTransformer member2NameTransformer = new MethodInvokingTransformer( memberGetNameMethod); Predicate propertyValuePredicate = AndPredicate .andPredicate(NotNullPredicate.notNullPredicate(), new EqualPredicate(memberName)); Predicate instance = TransformedPredicate.transformedPredicate(member2NameTransformer, propertyValuePredicate); Predicate memberNamePredicate = AndPredicate.andPredicate(NotNullPredicate.notNullPredicate(), instance); this.predicate = memberNamePredicate; } return predicate; } } return new SerializablePredicate(new SerializableMemberNamePredicate(memberName)); }
From source file:net.ontopia.topicmaps.impl.basic.index.OccurrenceIndex.java
@Override public Collection<OccurrenceIF> getOccurrences(String value, final LocatorIF datatype, final TopicIF occurrenceType) { return CollectionUtils.select(extractExactValues(occurs, value), new AndPredicate<>(new DataTypePredicate(datatype), new TypedPredicate(occurrenceType))); }
From source file:com.link_intersystems.lang.reflect.criteria.ElementCriteria.java
/** * Use the defined predicate as a filter when searching for elements. * Multiple calls to this method will combine the predicates with a logical * 'and' operator. The type of objects that the {@link Predicate} must be * able to handle is defined by subclasses. * * @param predicate/*from ww w .ja v a2 s.c om*/ * the predicate to use when filtering elements. The predicate * must implement {@link Serializable} to allow the * {@link ElementCriteria} to be serializable. For details take a * look at the {@link ElementCriteria} javadoc. * @see AndPredicate * @since 1.0.0.0 */ public void add(Predicate<T> predicate) { Assert.notNull("predicate", predicate); if (!(predicate instanceof Serializable)) { /* * We have to check if the predicate is a serializable. Of course * you can enforce it via generics by declaring a type T as "T * extends Predicate & Serializable". But this is not feasible * because the commons-util apis (like AndPredicate.getInstance(..)) * only return a predicate and a Predicate is not Serializable. So * if we would enforce it through generics all commons classes will * not work. */ throw new IllegalArgumentException("predicate must be Serializable"); } if (elementFilterPredicate == null) { elementFilterPredicate = predicate; } else { elementFilterPredicate = AndPredicate.andPredicate(elementFilterPredicate, predicate); } }
From source file:com.link_intersystems.lang.reflect.ReflectFacade.java
/** * A {@link Predicate} that evaluates to true if the object it is evaluated * against is a {@link Member} and that {@link Member}'s declaring class is * equal to the {@link Class} that this/*from w w w .ja v a2s. c o m*/ * {@link DeclaringClassMemberPredicate} was constructed with. * * @author Ren Link <a * href="mailto:rene.link@link-intersystems.com">[rene.link@link- * intersystems.com]</a> * @since 1.0.0.0 */ public static Predicate getDeclaringClassPredicate(Class<?> declaringClass) { Assert.notNull("declaringClass", declaringClass); class SerializableDeclaringClassPredicate implements SerializableReference<Predicate> { private static final long serialVersionUID = -625148437829360498L; private transient Predicate predicate; private final Class<?> declaringClass; public SerializableDeclaringClassPredicate(Class<?> declaringClass) { this.declaringClass = declaringClass; } public Predicate get() { if (predicate == null) { Method getDeclaringClassMethod = MethodUtils.getAccessibleMethod(Member.class, "getDeclaringClass", new Class<?>[0]); MethodInvokingTransformer member2NameTransformer = new MethodInvokingTransformer( getDeclaringClassMethod); Predicate propertyValuePredicate = AndPredicate .andPredicate(NotNullPredicate.notNullPredicate(), new EqualPredicate(declaringClass)); Predicate instance = TransformedPredicate.transformedPredicate(member2NameTransformer, propertyValuePredicate); Predicate memberNamePredicate = AndPredicate.andPredicate(NotNullPredicate.notNullPredicate(), instance); this.predicate = memberNamePredicate; } return predicate; } } return new SerializablePredicate(new SerializableDeclaringClassPredicate(declaringClass)); }