Java 类org.apache.commons.collections.functors.InstanceofPredicate 实例源码

项目:jenkins-github-pull-request-comments    文件:Ghprc.java   
@SuppressWarnings("unchecked")
public static DescribableList<GhprcExtension, GhprcExtensionDescriptor> getJobExtensions(GhprcTrigger trigger, Class<?> ...types) {

    // First get all global extensions
    DescribableList<GhprcExtension, GhprcExtensionDescriptor> copied = copyExtensions(trigger.getDescriptor().getExtensions());

    // Remove extensions that are specified by job
    filterList(copied, PredicateUtils.notPredicate(InstanceofPredicate.getInstance(GhprcProjectExtension.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;
}
项目:opencucina    文件:HistorisedTypeCriteriaModifierTest.java   
/**
 * Checks that historic criteria are added to search
 */
@Test
public void modifySearchBean() {
    Map<String, Object> params = new HashMap<String, Object>();

    params.put(PersistableEntity.APPLICATION_TYPE, Foo.TYPE);

    SearchBean bean = modifier.doModify(searchbean, params);
    Collection<SearchCriterion> searchCriteria = bean.getCriteria();

    assertEquals(3, searchCriteria.size());

    // Expect three criterion added implicitly
    assertNotNull(CollectionUtils.find(searchCriteria,
            new AndPredicate(new InstanceofPredicate(InSearchCriterion.class),
                new AndPredicate(new BeanPropertyValueEqualsPredicate("name",
                        "token.domainObjectType"),
                    new AndPredicate(new BeanPropertyValueEqualsPredicate("value",
                            Collections.singleton(Foo.TYPE)),
                        new BeanPropertyValueEqualsPredicate("rootAlias",
                            SearchCriterionMarshaller.HISTORY_ALIAS))))));
    assertNotNull(CollectionUtils.find(searchCriteria,
            new AndPredicate(new InstanceofPredicate(JoinCriterion.class),
                new AndPredicate(new BeanPropertyValueEqualsPredicate("lhs", "id"),
                    new BeanPropertyValueEqualsPredicate("rhs", "token.domainObjectId")))));
    assertNotNull(CollectionUtils.find(searchCriteria,
            new AndPredicate(new BeanPropertyValueEqualsPredicate("rootAlias",
                    SearchCriterionMarshaller.HISTORY_ALIAS),
                new AndPredicate(new BeanPropertyValueEqualsPredicate(NAME_ALIAS, ID_PROPERTY),
                    new BeanPropertyValueEqualsPredicate("subSelect",
                        "select max(hr.id) from HistoryRecord hr where hr.token.domainObjectId = foo.id and hr.token.domainObjectType = 'Foo'")))));
}
项目:opencucina    文件:HistorisedEntityDescriptorCriteriaModifierTest.java   
/**
 * Checks that historic criteria are added to search
 */
@Test
public void modifySearchBean() {
    Map<String, Object> params = new HashMap<String, Object>();

    params.put(PersistableEntity.APPLICATION_TYPE, EntityDescriptor.class.getSimpleName());

    SearchBean bean = modifier.doModify(searchbean, params);
    Collection<SearchCriterion> searchCriteria = bean.getCriteria();

    assertEquals(3, searchCriteria.size());

    // Expect three criterion added implicitly, subjectAlias
    assertNotNull(CollectionUtils.find(searchCriteria,
            new AndPredicate(new InstanceofPredicate(JoinCriterion.class),
                new AndPredicate(new BeanPropertyValueEqualsPredicate("lhs",
                        EntityDescriptor.APPLICATION_TYPE_PROP),
                    new BeanPropertyValueEqualsPredicate("rhs", "token.domainObjectType")))));
    assertNotNull(CollectionUtils.find(searchCriteria,
            new AndPredicate(new InstanceofPredicate(JoinCriterion.class),
                new AndPredicate(new BeanPropertyValueEqualsPredicate("lhs", "id"),
                    new BeanPropertyValueEqualsPredicate("rhs", "token.domainObjectId")))));
    assertNotNull(CollectionUtils.find(searchCriteria,
            new AndPredicate(new BeanPropertyValueEqualsPredicate("rootAlias",
                    SearchCriterionMarshaller.HISTORY_ALIAS),
                new AndPredicate(new BeanPropertyValueEqualsPredicate(NAME_ALIAS, ID_PROPERTY),
                    new BeanPropertyValueEqualsPredicate("subSelect",
                        "select max(hr.id) from HistoryRecord hr where hr.token.domainObjectId = foo.id and hr.token.domainObjectType = " +
                        NameUtils.concat(ALIAS, EntityDescriptor.APPLICATION_TYPE_PROP))))));
}
项目:jenkins-github-pull-request-comments    文件:GhprcExtensionDescriptor.java   
private static void filterExtensions(DescriptorExtensionList<GhprcExtension, GhprcExtensionDescriptor> descriptors, Class<? extends GhprcExtensionType>... types) {
    List<Predicate> predicates = new ArrayList<Predicate>(types.length);
    for (Class<? extends GhprcExtensionType> type : types) {
        predicates.add(InstanceofPredicate.getInstance(type));

    }
    Predicate anyPredicate = PredicateUtils.anyPredicate(predicates);
    for (GhprcExtensionDescriptor descriptor : descriptors) {
        if (!anyPredicate.evaluate(descriptor)) {
            descriptors.remove(descriptor);
        }
    }
}
项目:jenkins-github-pull-request-comments    文件:Ghprc.java   
private static List<Predicate> createPredicate(Class<?> ...types) {
    List<Predicate> predicates = new ArrayList<Predicate>(types.length);
    for (Class<?> type : types) {
        predicates.add(InstanceofPredicate.getInstance(type));
    }
    return predicates;
}
项目:jenkins-github-pull-request-comments    文件:Ghprc.java   
private static boolean addExtension(GhprcExtension extension, List<Predicate> predicates, Set<Class<?>> extSet) {
    for (Predicate predicate: predicates) {
        if (predicate.evaluate(extension)) {
            Class<?> clazz = ((InstanceofPredicate)predicate).getType();
            if (extSet.contains(clazz)) {
                return false;
            } else {
                extSet.add(clazz);
                return true;
            }
        }
    }
    return true;
}
项目:jenkins-github-pull-request-comments    文件:Ghprc.java   
public static void addIfMissing(DescribableList<GhprcExtension, GhprcExtensionDescriptor> extensions, GhprcExtension ext, Class<?> type) {
    Predicate predicate = InstanceofPredicate.getInstance(type);
    for (GhprcExtension extension : extensions) {
        if (predicate.evaluate(extension)){
            return;
        }
    }
    extensions.add(ext);
}