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

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

Introduction

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

Prototype

public EqualPredicate(final T object) 

Source Link

Document

Constructor that performs no validation.

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 www.jav a2  s. co 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/*ww w.j a v  a  2 s  . 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));
}

From source file:com.feilong.core.util.CollectionsUtilTest.java

@Test
public void testSelectPredicate1() {
    List<Long> list = toList(1L, 1L, 2L, 3L);
    assertThat(CollectionsUtil.select(list, new EqualPredicate<Long>(1L)), contains(1L, 1L));
    assertEquals(emptyList(), CollectionsUtil.select(null, new EqualPredicate<Long>(1L)));
}

From source file:com.link_intersystems.lang.reflect.criteria.ClassCriteriaTest.java

@SuppressWarnings("unchecked")
@Test//ww w .  j  av a  2s  .co  m
public void visitAllFilter() {
    classCriteria.setTraverseStrategy(TraverseStrategy.DEPTH_FIRST);
    classCriteria.setSelection(ClassType.INTERFACES);
    classCriteria.add(ReflectFacade.getIsInterfacePredicate());
    classCriteria.add(NotPredicate
            .notPredicate(EqualPredicate.equalPredicate(GenericSubSubWithMultipleInterfaces.class)));
    classCriteria.setTraverseClassesUniquely(false);
    Iterator<Class<?>> iterator = classCriteria.getIterable(GenericSubSubWithMultipleInterfaces.class)
            .iterator();

    List<Class<?>> interfaces = IteratorUtils.toList(iterator);
    Collection<Class<?>> expectedInterfaces = new ArrayList<Class<?>>(Arrays.asList(GenericSubInterface.class,
            GenericInterface_Types_A_B_C.class, GenericInterface_Types_A_B_C.class));
    for (Class<?> interf : interfaces) {
        assertTrue("Unexpected " + interf + " in interator", expectedInterfaces.remove(interf));
    }
    assertTrue("Iterator does not iterator over the interfaces " + expectedInterfaces,
            expectedInterfaces.isEmpty());
}