Example usage for org.apache.commons.collections4.functors NotNullPredicate NotNullPredicate

List of usage examples for org.apache.commons.collections4.functors NotNullPredicate NotNullPredicate

Introduction

In this page you can find the example usage for org.apache.commons.collections4.functors NotNullPredicate NotNullPredicate.

Prototype

private NotNullPredicate() 

Source Link

Document

Restricted constructor.

Usage

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//from ww w. j a v a2 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: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. j  a  va2s.  c  om*/
 * {@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));
}