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

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

Introduction

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

Prototype

Predicate

Source Link

Usage

From source file:edu.asu.mgb.gui.GUIUtil.java

/**
 * Obtains the vertex filter by student;
 * @param student/*w ww  . j  ava  2s . c o  m*/
 * @return 
 */
public static VertexPredicateFilter getVertexPredicateFilter(final int student) {
    return new VertexPredicateFilter(new Predicate<State>() {
        @Override
        public boolean evaluate(State s) {
            return s.isStudentInState(student);
        }
    });
}

From source file:net.itransformers.topologyviewer.gui.EdgeFilterFactory.java

public static EdgePredicateFilter<String, String> createEdgeFilter(final FilterType filter,
        final Map<String, DataMatcher> matcherMap, final Map<String, GraphMLMetadata<String>> edgeMetadata) {
    return new EdgePredicateFilter<String, String>(new Predicate<String>() {
        public boolean evaluate(String edge) {
            try {
                if (filter == null)
                    return true;

                List<IncludeType> includes = filter.getInclude();
                String filterType = filter.getType();

                if (filterType == null) {
                    filterType = "or";
                }/*from   w  ww.j a v a2 s.  c  o m*/
                boolean hasEdgeInlcude = false;

                for (IncludeType include : includes) {

                    if (ForType.EDGE.equals(include.getFor())) {
                        String matcher = include.getMatcher();
                        if (matcher == null) {
                            matcher = "default";
                        }
                        final String dataKey = include.getDataKey();
                        if (dataKey == null) { // lets include all edges
                            hasEdgeInlcude = true;

                            continue;
                        }

                        final GraphMLMetadata<String> stringGraphMLMetadata = edgeMetadata.get(dataKey);
                        if (stringGraphMLMetadata == null) {
                            logger.error("Can not find metadata for key: " + dataKey);
                        }
                        String value = null;
                        if (stringGraphMLMetadata != null) {
                            final Transformer<String, String> transformer = stringGraphMLMetadata.transformer;
                            value = transformer.transform(edge);

                        }
                        if (value != null) {
                            String[] dataValues = value.split(",");
                            String includeDataValue = include.getDataValue();

                            //Circle around the actual values and perform the datamatch
                            DataMatcher matcherInstance = matcherMap.get(matcher);

                            boolean hasToInclude = false;

                            if ("and".equals(filterType)) {
                                for (String dataValue : dataValues) {
                                    // boolean matchResult = ;
                                    hasEdgeInlcude = false;
                                    if (matcherInstance.compareData(dataValue, includeDataValue)) {
                                        logger.debug("Edge selected: " + edge + " by filter " + filter.getName()
                                                + " with include " + include.getDataKey() + " with value "
                                                + dataValue);
                                        hasEdgeInlcude = true;
                                    }
                                }

                                if (!hasEdgeInlcude) {
                                    return false;
                                }
                                //If we have an "or" filter

                            } else {
                                for (String dataValue : dataValues) {
                                    if (matcherInstance.compareData(dataValue, includeDataValue)) {
                                        logger.debug("Edge " + edge + " has been selected from filter "
                                                + filter.getName() + " by property " + include.getDataKey()
                                                + " with value " + dataValue);
                                        return true;

                                    }

                                }
                            }
                        }

                    }

                }
                //Finally if the has to include flag is set include
                if (!hasEdgeInlcude) {
                    System.out.println("Edge " + edge + " has not been selected");
                    return false;

                } else {
                    System.out.println("Edge " + edge + " has been selected");

                    return true;
                }
            } catch (RuntimeException rte) {
                rte.printStackTrace();
                return false;
            }
        }
    });
}

From source file:edu.asu.mgb.gui.GUIUtil.java

/**
 * Obtains the edge filter by student//from   w ww  .  ja  v a2  s.com
 * @param student
 * @return 
 */
public static EdgePredicateFilter getEdgePredicateFilter(final int student) {
    return new EdgePredicateFilter<>(new Predicate<Action>() {
        @Override
        public boolean evaluate(Action a) {
            return a.isStudentInACtion(student);
        }
    });
}

From source file:net.itransformers.topologyviewer.gui.VertexFilterFactory.java

static VertexPredicateFilter<String, String> createVertexFilter(final FilterType filter,
        final Map<String, DataMatcher> matcherMap, final Map<String, GraphMLMetadata<String>> vertexMetadata,
        final Graph<String, String> graph1) {
    return new VertexPredicateFilter<String, String>(new Predicate<String>() {
        public boolean evaluate(String v) {
            if (graph1.getIncidentEdges(v).isEmpty()) {
                return false;
            } else {
                if (filter == null)
                    return true;
                List<IncludeType> includes = filter.getInclude();
                String filterType = filter.getType();

                if (filterType == null) {
                    filterType = "or";
                }//from w w w. j  a  va2 s  .co m
                boolean hasNodeInlcude = false;

                for (IncludeType include : includes) {
                    if (ForType.NODE.equals(include.getFor())) {

                        String matcher = include.getMatcher();
                        if (matcher == null) {
                            matcher = "default";
                        }
                        if (include.getClassType() == null) {

                            final String dataKey = include.getDataKey();
                            //include all nodes
                            if (dataKey == null) {
                                hasNodeInlcude = true;
                                continue;
                            }
                            //the evaluated node dosn't have that dataKey
                            if (vertexMetadata.get(dataKey) == null) {
                                logger.debug("No data is defined in vertex metadata for dataKey=" + dataKey);
                                continue;
                            }
                            //the evaluated node has that dataKey
                            String value = vertexMetadata.get(dataKey).transformer.transform(v);
                            //Evaluate only if the value is not null
                            if (value != null) {
                                //Evaluate multiplicity e.g multiple values for single data key split by commas
                                String[] dataValues = value.split(",");

                                //get the value from the include filter
                                String includeDataValue = include.getDataValue();

                                //Circle around the actual values and perform the datamatch
                                DataMatcher matcherInstance = matcherMap.get(matcher);
                                //If we have an "and" filter
                                if ("and".equals(filterType)) {
                                    for (String dataValue : dataValues) {
                                        // boolean matchResult = ;
                                        hasNodeInlcude = false;
                                        if (matcherInstance.compareData(dataValue, includeDataValue)) {
                                            logger.debug("Node selected: " + v + " by filter "
                                                    + filter.getName() + " with include " + include.getDataKey()
                                                    + " with value " + dataValue);
                                            hasNodeInlcude = true;
                                        }
                                    }

                                    if (!hasNodeInlcude) {
                                        return false;
                                    }
                                    //If we have an "or" filter

                                } else {
                                    for (String dataValue : dataValues) {
                                        if (matcherInstance.compareData(dataValue, includeDataValue)) {
                                            logger.debug("Node " + v + " has been selected from filter "
                                                    + filter.getName() + " by property " + include.getDataKey()
                                                    + " with value " + dataValue);
                                            hasNodeInlcude = true;
                                        } else {
                                            logger.debug("Node" + v + "  has not been selected from filter "
                                                    + filter.getName() + " by property " + include.getDataKey()
                                                    + " with value " + dataValue);

                                        }

                                    }
                                }
                            }
                        } else {
                            //We have totally custom filter from class
                            String type = include.getClassType();
                            Class<?> includeClazz;
                            try {
                                includeClazz = Class.forName(type);
                                VertexIncluder includeInst = (VertexIncluder) includeClazz.newInstance();
                                boolean hasToInlcude = includeInst.hasToInclude(v, vertexMetadata, graph1);

                                if ("and".equals(filterType)) {
                                    if (!hasToInlcude) {
                                        return false;
                                    }
                                } else {

                                    if (hasToInlcude) {
                                        hasNodeInlcude = true;
                                    }
                                }

                            } catch (ClassNotFoundException e) {
                                e.printStackTrace();
                                return false;
                            } catch (InstantiationException e) {
                                e.printStackTrace();
                                return false;
                            } catch (IllegalAccessException e) {
                                e.printStackTrace();
                                return false;
                            }

                        }
                    }
                }
                //Finally if the has to include flag is set include
                if (!hasNodeInlcude) {
                    logger.info("Node " + v + " has not been selected");
                    return false;

                } else {
                    logger.info("Node " + v + " has been selected");

                    return true;
                }
            }
        }
    });
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.samplelister.SampleSetListingQueryFullTableScan.java

public Iterable<SampleRecord> getSamples(final LongSet sampleIds) {
    return new Iterable<SampleRecord>() {
        public Iterator<SampleRecord> iterator() {
            return new FilterIterator<SampleRecord>(query.getSamples(databaseInstanceId),
                    new Predicate<SampleRecord>() {
                        public boolean evaluate(SampleRecord sample) {
                            return sampleIds.contains(sample.id);
                        }//from   w  ww .j ava  2s  .  com
                    });
        }
    };
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.common.PropertiesSetListingQueryFullTableScan.java

public Iterable<GenericEntityPropertyRecord> getEntityPropertyGenericValues(final LongSet entityIDs) {
    return new Iterable<GenericEntityPropertyRecord>() {
        public Iterator<GenericEntityPropertyRecord> iterator() {
            return new FilterIterator<GenericEntityPropertyRecord>(query.getEntityPropertyGenericValues(),
                    new Predicate<BaseEntityPropertyRecord>() {
                        public boolean evaluate(BaseEntityPropertyRecord baseSample) {
                            return entityIDs.contains(baseSample.entity_id);
                        }/*from ww w  .ja v a  2 s.  co  m*/
                    });
        }
    };
}

From source file:gov.nih.nci.cabig.caaers.service.synchronizer.report.ConcomitantMedicationSynchronizer.java

public void migrate(ExpeditedAdverseEventReport src, ExpeditedAdverseEventReport dest,
        DomainObjectImportOutcome<ExpeditedAdverseEventReport> outcome) {
    List<ConcomitantMedication> newConmeds = new ArrayList<ConcomitantMedication>();
    List<ConcomitantMedication> existingConmeds = new ArrayList<ConcomitantMedication>();
    if (dest.getConcomitantMedications() != null)
        existingConmeds.addAll(dest.getConcomitantMedications());

    if (src.getConcomitantMedications() != null) {
        for (ConcomitantMedication conMed : src.getConcomitantMedications()) {
            final ConcomitantMedication xmlConmed = conMed;
            ConcomitantMedication found = CollectionUtils.find(existingConmeds,
                    new Predicate<ConcomitantMedication>() {
                        public boolean evaluate(ConcomitantMedication concomitantMedication) {
                            return StringUtils.equals(concomitantMedication.getAgentName(),
                                    xmlConmed.getAgentName());
                        }/* w ww  .ja v  a 2  s.  com*/
                    });
            if (found != null) {
                found.setEndDate(xmlConmed.getEndDate());
                found.setStartDate(xmlConmed.getStartDate());
                found.setStillTakingMedications(xmlConmed.getStillTakingMedications());
                //remove the pre-existing condition found
                existingConmeds.remove(found);
            } else {
                newConmeds.add(xmlConmed);
            }
        }
    }

    //remove unwanted
    for (ConcomitantMedication unwanted : existingConmeds) {
        dest.getConcomitantMedications().remove(unwanted);
    }

    //add newly added
    for (ConcomitantMedication newPc : newConmeds) {
        dest.addConcomitantMedication(newPc);
    }

}

From source file:com.bluexml.tools.graph.engines.jung.transformer.GraphFilter.java

public static <V, E> Graph<V, E> applyEdgesFilter(final Graph<V, E> graph, String edgesfilter) {
    logger.debug("Apply Edges Filter" + edgesfilter);
    if (!edgesfilter.equals("")) {

        final List<String[]> l = new ArrayList<String[]>();

        String[] split = edgesfilter.split(",");
        for (String string : split) {
            l.add(string.split(">"));
        }//from   w  w  w.j  ava 2  s. c o  m

        Predicate<E> edge_pred = new Predicate<E>() {

            public boolean evaluate(E object) {
                V source = graph.getSource(object);
                V dest = graph.getDest(object);
                boolean sok = false;
                for (String[] strings : l) {
                    if (testClassName(source, strings[0].trim())) {
                        sok = true;
                        break;
                    }
                }
                boolean dok = false;
                for (String[] strings : l) {
                    if (testClassName(dest, strings[1].trim())) {
                        dok = true;
                        break;
                    }
                }

                return sok && dok;
            }
        };

        EdgePredicateFilter<V, E> pred = new EdgePredicateFilter<V, E>(edge_pred);
        return pred.transform(graph);
    } else {
        return graph;
    }
}

From source file:ch.algotrader.entity.security.CombinationImpl.java

@Override
public Component getComponentBySecurity(final Security security) {

    // find the component to the specified security
    return CollectionUtils.find(getComponents(), new Predicate<Component>() {
        @Override/*from   ww w.j a v a2s  . c om*/
        public boolean evaluate(Component component) {
            return security.equals(component.getSecurity());
        }
    });
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister.DatasetSetListingQueryFullTableScan.java

public Iterable<DatasetRecord> getDatasets(final LongSet datasetIds) {
    return new Iterable<DatasetRecord>() {
        public Iterator<DatasetRecord> iterator() {
            return new FilterIterator<DatasetRecord>(query.getDatasets(databaseInstanceId),
                    new Predicate<DatasetRecord>() {
                        public boolean evaluate(DatasetRecord dataset) {
                            return datasetIds.contains(dataset.id);
                        }/*w  w w. jav a  2 s  . c o  m*/
                    });
        }
    };
}