Example usage for org.apache.commons.collections Predicate evaluate

List of usage examples for org.apache.commons.collections Predicate evaluate

Introduction

In this page you can find the example usage for org.apache.commons.collections Predicate evaluate.

Prototype

public boolean evaluate(T object);

Source Link

Document

Use the specified parameter to perform a test that returns true or false.

Usage

From source file:module.siadap.domain.wrappers.PartyWrapper.java

private List<Person> getParentPersons(Predicate predicate, AccountabilityType... types) {
    return getParty().getParentAccountabilityStream()
            .filter(a -> match(a, types) && (predicate == null || predicate.evaluate(a)))
            .map(a -> a.getParent()).filter(p -> p.isPerson()).map(p -> (Person) p)
            .collect(Collectors.toList());
}

From source file:net.sourceforge.fenixedu.presentationTier.util.CollectionFilter.java

public Set<T> filter(Set<T> elements) {
    Set<T> filtered;/*from   ww  w.ja v  a2 s .  com*/

    if (comparator == null) {
        filtered = new HashSet<T>();
    } else {
        filtered = new TreeSet<T>(comparator);
    }

    final Set<Predicate> predicates = getPredicates();

    if (predicates == null || predicates.isEmpty()) {
        filtered.addAll(elements);
        return Collections.unmodifiableSet(filtered);
    }
    Predicate predicate;
    if (predicates.size() == 1) {
        predicate = predicates.iterator().next();
    } else {
        predicate = AllPredicate.getInstance(predicates);
    }
    for (T element : elements) {
        if (predicate.evaluate(element)) {
            filtered.add(element);
        }
    }
    return Collections.unmodifiableSet(filtered);
}

From source file:de.softwareforge.pgpsigner.key.PublicKeyRing.java

private PublicKeyRing processMap(final Predicate predicate) {
    PublicKeyRing processedKeys = new PublicKeyRing();
    processedKeys.setRingFileName(getRingFileName());

    for (Map.Entry<KeyId, PublicKey> entry : keys.entrySet()) {
        if (predicate.evaluate(entry.getValue())) {
            processedKeys.putKey(entry.getKey(), entry.getValue());
        }/*w ww. j  ava2 s.c o  m*/
    }

    return processedKeys;
}

From source file:edu.uci.ics.jung.graph.impl.AbstractArchetypeGraph.java

protected void checkConstraints(Object o, Collection c) {
    for (Iterator iter = c.iterator(); iter.hasNext();) {
        Predicate p = (Predicate) iter.next();
        if (!p.evaluate(o)) {
            throw new ConstraintViolationException(
                    "Predicate " + p.getClass().getName() + " rejected " + o + ": " + p, p);
        }//from   ww w.  ja  v a  2  s.co  m
    }
}

From source file:lt.kape1395.jenkins.ditz.IssueDiffCollector.java

/**
 * Process an issue by updating required statistics of
 * project, release, component, etc./*from   w w w . j  av a 2 s  . c o m*/
 *
 * @param project
 *      Project for which the statistics are being collected.
 * @param sourceIssue
 *      Issue as it was in the previous build.
 *      It can be null, if not existed.
 * @param targetIssue
 *      Issue as is is in the current build.
 *      It can be bull, if was closed or deleted.
 * @param projectStats
 *      Project summary statistics.
 * @param releaseStats
 *      Statistics by release.
 * @param componentStats
 *      Statistics by component.
 */
protected void processIssue(Project project, Issue sourceIssue, Issue targetIssue,
        IssueStatCategory projectStats, Map<String, IssueStatCategory> releaseStats,
        Map<String, IssueStatCategory> componentStats) {
    Issue issue;
    IssueStats.StatField statField;

    log.fine("processIssue: src=" + sourceIssue + " dst=" + targetIssue);

    Predicate issueIsOpen = new IssueOpenPredicate();
    if (targetIssue != null) {
        targetIssue.setStatusChange(StatusChange.UNCHANGED);
    }

    if (issueIsOpen.evaluate(sourceIssue) && issueIsOpen.evaluate(targetIssue)) {
        statField = IssueStats.StatField.OPEN;
        issue = targetIssue;
        issue.setStatusChange(StatusChange.UNCHANGED);
    } else if (issueIsOpen.evaluate(sourceIssue)) {
        statField = IssueStats.StatField.CLOSED;
        issue = sourceIssue;
        if (targetIssue == null) {
            issue.setStatusChange(StatusChange.CLOSED);
            project.getIssues().add(issue);
        } else {
            targetIssue.setStatusChange(StatusChange.CLOSED);
        }
    } else if (issueIsOpen.evaluate(targetIssue)) {
        statField = IssueStats.StatField.NEW;
        issue = targetIssue;
        issue.setStatusChange(StatusChange.NEW);
    } else {
        project.getIssues().remove(targetIssue);
        return; // statistics should not be affected.
    }

    log.fine("processIssue: stat=" + statField + " " + issue);

    addToCategory(issue.getReleaseName(), releaseStats, statField);
    addToCategory(issue.getComponentName(), componentStats, statField);
    projectStats.getIssueStats().increment(statField);
}

From source file:lt.kape1395.jenkins.ditz.model.IssueInReleasePredicateTest.java

/**
 * Check all combinations.//  w  w w.j a  v a 2s .c  o m
 */
@Test
public void testEvaluate() {
    Predicate r0 = new IssueInReleasePredicate();
    Predicate r1 = new IssueInReleasePredicate(new Release("r1", "a"));

    Issue i0a = new Issue("a", "b", "c", "d", null);
    Issue i0b = new Issue("a", "b", "c", "d", "");
    Issue i1 = new Issue("a", "b", "c", "d", "r1");
    Issue i2 = new Issue("a", "b", "c", "d", "r2");

    assertThat(r0.evaluate(null), is(false));
    assertThat(r0.evaluate(getClass()), is(false));
    assertThat(r0.evaluate(i0a), is(true));
    assertThat(r0.evaluate(i0b), is(true));
    assertThat(r0.evaluate(i1), is(false));
    assertThat(r0.evaluate(i2), is(false));

    assertThat(r1.evaluate(null), is(false));
    assertThat(r1.evaluate(getClass()), is(false));
    assertThat(r1.evaluate(i0a), is(false));
    assertThat(r1.evaluate(i0b), is(false));
    assertThat(r1.evaluate(i1), is(true));
    assertThat(r1.evaluate(i2), is(false));
}

From source file:module.siadap.domain.wrappers.PartyWrapper.java

protected List<Unit> getParentUnits(Party partyToConsider, Predicate predicate, AccountabilityType... types) {
    return partyToConsider == null ? Collections.emptyList()
            : partyToConsider.getParentAccountabilityStream()
                    .filter(a -> match(a, types) && (predicate == null || predicate.evaluate(a)))
                    .map(a -> a.getParent()).filter(p -> p.isUnit()).map(p -> (Unit) p)
                    .collect(Collectors.toList());
}

From source file:module.siadap.domain.wrappers.PartyWrapper.java

protected List<Person> getChildPersons(Party partyToConsider, Predicate predicate,
        AccountabilityType... types) {/*from   w ww  .j  a  va  2 s  . c  o m*/
    return partyToConsider == null ? Collections.emptyList()
            : partyToConsider.getChildAccountabilityStream()
                    .filter(a -> match(a, types) && (predicate == null || predicate.evaluate(a)))
                    .map(a -> a.getChild()).filter(p -> p.isPerson()).map(p -> (Person) p)
                    .collect(Collectors.toList());
}

From source file:com.discovery.darchrow.util.CollectionsUtil.java

/**
 *  <code>objectCollection</code>,? ? <code>includePredicate</code> {@code propertyName}.
 *
 * @param <T>/*from  w w  w.j  av  a 2  s  .co  m*/
 *            the generic type
 * @param <O>
 *            the generic type
 * @param objectCollection
 *            the object collection
 * @param includePredicate
 *            ? ? <code>includePredicate</code>null ?Object
 * @param propertyName
 *            the property name
 * @return the map< t, integer>
 * @since 1.2.0
 */
public static <T, O> Map<T, Integer> groupCount(Collection<O> objectCollection, Predicate includePredicate,
        String propertyName) {
    if (Validator.isNullOrEmpty(objectCollection)) {
        throw new NullPointerException("objectCollection can't be null/empty!");
    }

    if (Validator.isNullOrEmpty(propertyName)) {
        throw new NullPointerException("the propertyName is null or empty!");
    }

    Map<T, Integer> map = new LinkedHashMap<T, Integer>();

    for (O o : objectCollection) {
        if (null != includePredicate) {
            //
            boolean continueFlag = !includePredicate.evaluate(o);

            if (continueFlag) {
                continue;
            }
        }

        T t = PropertyUtil.getProperty(o, propertyName);
        Integer count = map.get(t);
        if (null == count) {
            count = 0;
        }
        count = count + 1;

        map.put(t, count);
    }
    return map;
}

From source file:it.unimi.di.big.mg4j.mock.search.PayloadPredicateDocumentIterator.java

/** Creates a new payload document iterator over a given iterator.
 *
 * @param documentIterator the iterator to be filtered.
 * @param predicate a predicate.// w  w w .  j a v a  2s .co  m
 */
protected PayloadPredicateDocumentIterator(final IndexIterator documentIterator, final Predicate predicate) {
    this.documentIterator = documentIterator;
    this.predicate = predicate;
    indices.addAll(documentIterator.indices());
    try {
        long documentPointer;
        while ((documentPointer = documentIterator.nextDocument()) != END_OF_LIST) {
            for (Index index : indices) {
                if (predicate.evaluate(documentIterator.payload())) {
                    if (!index.hasPositions) {
                        addTrueIteratorDocument(documentPointer, index);
                        continue;
                    }
                    IntervalIterator intervalIterator = documentIterator.intervalIterator(index);
                    if (intervalIterator == IntervalIterators.TRUE) {
                        addTrueIteratorDocument(documentPointer, index);
                        continue;
                    }
                    if (intervalIterator == IntervalIterators.FALSE) {
                        addFalseIteratorDocument(documentPointer, index);
                        continue;
                    }
                    for (Interval interval; (interval = intervalIterator.nextInterval()) != null;) {
                        addIntervalForDocument(documentPointer, index, interval);
                    }
                }
            }
        }
        documentIterator.dispose();
        start(true);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}