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

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

Introduction

In this page you can find the example usage for org.apache.commons.collections15 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:facade.collections.CollectionInPlaceProxy.java

public CollectionProxy<T> select(Predicate<T> pred) {
    Iterator<T> it = collection.iterator();
    while (it.hasNext()) {
        T t = it.next();//from w w w . j a  v a2 s.c om
        if (!pred.evaluate(t)) {
            it.remove();
        }
    }
    return this;
}

From source file:com.diversityarrays.dalclient.DalUtil.java

public static List<DalResponseRecord> collectResponseRecords(DalResponse response,
        final Predicate<String> tagNamePredicate) throws DalResponseFormatException, DalResponseException {
    final List<DalResponseRecord> result = new ArrayList<>();
    response.visitResults(new DalResponseRecordVisitor() {
        @Override//w ww.  j  av  a  2 s  .co m
        public boolean visitResponseRecord(String resultTagName, DalResponseRecord data) {
            if (tagNamePredicate == null || tagNamePredicate.evaluate(resultTagName)) {
                result.add(data);
            }
            return true;
        }
    });
    return result;
}

From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java

/**
 * Returns <code>true</code> if this vertex in this graph is included 
 * in the collections of elements to be rendered, and <code>false</code> otherwise.
 * @param context the vertex and graph to be queried
 * @return <code>true</code> if this vertex is 
 * included in the collections of elements to be rendered, <code>false</code>
 * otherwise.// www.  j  av  a  2 s .  c  o m
 */
protected boolean isVertexRendered(Context<Graph<V, E>, V> context) {
    Predicate<Context<Graph<V, E>, V>> vertexIncludePredicate = vv.getRenderContext()
            .getVertexIncludePredicate();
    return vertexIncludePredicate == null || vertexIncludePredicate.evaluate(context);
}

From source file:com.diversityarrays.kdxplore.trials.MyTrialExportHelper.java

@Override
public void visitTraitInstancesForTrial(int trialId, boolean withTraits,
        Predicate<TraitInstance> traitInstanceVisitor) throws IOException {
    WithTraitOption withTraitOption = withTraits ? WithTraitOption.ALL_WITH_TRAITS
            : WithTraitOption.ALL_WITHOUT_TRAITS;
    Predicate<TraitInstance> visitor = new Predicate<TraitInstance>() {
        @Override/*w  ww  .j  ava 2s .c  om*/
        public boolean evaluate(TraitInstance ti) {
            Boolean result = Boolean.TRUE;
            if (traitIds.contains(ti.getTraitId())) {
                result = traitInstanceVisitor.evaluate(ti);
            }
            return result;
        }
    };
    kdsmartDatabase.visitTraitInstancesForTrial(trialId, withTraitOption, visitor);
}

From source file:edu.uci.ics.jung.io.PajekNetReader.java

/**
 * Returns the first line read from <code>br</code> for which <code>p</code> 
 * returns <code>true</code>, or <code>null</code> if there is no
 * such line.//  www  .  ja v a  2  s.com
 * @throws IOException
 */
protected String skip(BufferedReader br, Predicate<String> p) throws IOException {
    while (br.ready()) {
        String curLine = br.readLine();
        if (curLine == null)
            break;
        curLine = curLine.trim();
        if (p.evaluate(curLine))
            return curLine;
    }
    return null;
}

From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java

/**
 * Returns <code>true</code> if this edge and its endpoints
 * in this graph are all included in the collections of
 * elements to be rendered, and <code>false</code> otherwise.
 * @param context the edge and graph to be queried
 * @return <code>true</code> if this edge and its endpoints are all
 * included in the collections of elements to be rendered, <code>false</code>
 * otherwise.//www.  ja  va  2 s. c  o m
 */
protected boolean isEdgeRendered(Context<Graph<V, E>, E> context) {
    Predicate<Context<Graph<V, E>, V>> vertexIncludePredicate = vv.getRenderContext()
            .getVertexIncludePredicate();
    Predicate<Context<Graph<V, E>, E>> edgeIncludePredicate = vv.getRenderContext().getEdgeIncludePredicate();
    Graph<V, E> g = context.graph;
    E e = context.element;
    boolean edgeTest = edgeIncludePredicate == null || edgeIncludePredicate.evaluate(context);
    Pair<V> endpoints = g.getEndpoints(e);
    V v1 = endpoints.getFirst();
    V v2 = endpoints.getSecond();
    boolean endpointsTest = vertexIncludePredicate == null
            || (vertexIncludePredicate.evaluate(Context.<Graph<V, E>, V>getInstance(g, v1))
                    && vertexIncludePredicate.evaluate(Context.<Graph<V, E>, V>getInstance(g, v2)));
    return edgeTest && endpointsTest;
}

From source file:edu.uci.ics.jung.io.CustomPajekNetReader.java

/**
 * Returns the first line read from <code>br</code> for which <code>p</code>
 * returns <code>true</code>, or <code>null</code> if there is no such line.
 *
 * @throws IOException// www  .j av  a2 s.  c  o  m
 */
protected String skip(BufferedReader br, Predicate<String> p) throws IOException {
    while (br.ready()) {
        String curLine = br.readLine();
        if (curLine == null) {
            break;
        }
        curLine = curLine.trim();
        if (p.evaluate(curLine)) {
            return curLine;
        }
    }
    return null;
}

From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java

protected void scanArtifactsManifests(Predicate<Pair<URL, Manifest>> manifestHandler) {
    ClassLoader loader = ExtendedClassUtils.getDefaultClassLoader(getClass());
    try {/*  w  w w.  j  a  va2s  . c  o m*/
        for (Enumeration<URL> manifests = loader.getResources(JarFile.MANIFEST_NAME); (manifests != null)
                && manifests.hasMoreElements();) {
            URL url = manifests.nextElement();
            try {
                Manifest manifest = ManifestUtils.loadManifest(url);
                if (manifestHandler.evaluate(Pair.of(url, manifest))) {
                    logger.info("Scanning stopped by handler at URL=" + url.toExternalForm());
                    break;
                }
            } catch (Exception e) {
                logger.warn(e.getClass().getSimpleName() + " while handle URL=" + url.toExternalForm() + ": "
                        + e.getMessage());
            }
        }
    } catch (IOException e) {
        logger.warn("Failed (" + e.getClass().getSimpleName() + ") to get manifests URLs: " + e.getMessage());
    }
}

From source file:com.diversityarrays.kdxplore.curate.CurationTableModel.java

protected List<Integer> collectColumnIndices(Predicate<ValueRetriever<?>> predicate) {
    List<Integer> result = new ArrayList<>();
    for (int vfIndex = valueRetrievers.size(); --vfIndex >= 0;) {
        ValueRetriever<?> vr = valueRetrievers.get(vfIndex);
        if (predicate.evaluate(vr)) {
            result.add(vfIndex);/*from w  w  w  . j  a  v a  2 s .c om*/
        }
    }
    return result;
}

From source file:com.diversityarrays.kdxplore.curate.CurationTableModel.java

public void setTemporaryValue(CurationCellId ccid, Comparable<?> value) {

    Predicate<PlotOrSpecimen> predicate = new Predicate<PlotOrSpecimen>() {
        @Override// w  w w . java 2  s. c o m
        public boolean evaluate(PlotOrSpecimen pos) {
            return ccid.specimenNumber == pos.getSpecimenNumber() && ccid.plotId == pos.getPlotId();
        }

    };

    int foundRow = -1;
    for (int row = 0; row < plotOrSpecimens.size(); ++row) {
        PlotOrSpecimen pos = plotOrSpecimens.get(row);
        if (predicate.evaluate(pos)) {
            foundRow = row;
            break;
        }
    }

    if (foundRow >= 0) {
        Integer column = getColumnIndexForTraitInstance(ccid.traitInstance);
        if (column != null) {
            Point pt = new Point(column, foundRow);
            if (value == null) {
                temporaryValues.remove(pt);
            } else {
                temporaryValues.put(pt, value);
            }

            this.fireTableCellUpdated(foundRow, column);
        }
    }
}