List of usage examples for org.apache.commons.collections Predicate evaluate
public boolean evaluate(T object);
From source file:org.apache.cayenne.modeler.dialog.codegen.CodeGeneratorControllerBase.java
public boolean updateSelection(Predicate predicate) { boolean modified = false; for (Object classObj : classes) { boolean select = predicate.evaluate(classObj); if (classObj instanceof ObjEntity) { if (select) { if (selectedEntities.add(((ObjEntity) classObj).getName())) { modified = true;/*from w w w . j av a 2 s.c o m*/ } } else { if (selectedEntities.remove(((ObjEntity) classObj).getName())) { modified = true; } } } else if (classObj instanceof Embeddable) { if (select) { if (selectedEmbeddables.add(((Embeddable) classObj).getClassName())) { modified = true; } } else { if (selectedEmbeddables.remove(((Embeddable) classObj).getClassName())) { modified = true; } } } } if (modified) { firePropertyChange(SELECTED_PROPERTY, null, null); } return modified; }
From source file:org.apache.cayenne.xml.XMLUtil.java
private static Node firstMatch(NodeList list, Predicate predicate) { int len = list.getLength(); for (int i = 0; i < len; i++) { Node node = list.item(i); if (predicate.evaluate(node)) { return node; }// w w w.j a va 2 s . c o m } return null; }
From source file:org.apache.tajo.engine.function.FunctionLoader.java
private static Set<Method> findPublicStaticMethods(String packageName, Predicate predicate) { Set<Class> found = findFunctionCollections(packageName); Set<Method> filtered = Sets.newHashSet(); for (Class clazz : found) { for (Method method : clazz.getMethods()) { if (isPublicStaticMethod(method) && (predicate == null || predicate.evaluate(method))) { filtered.add(method);/*from ww w .j av a 2 s .c o m*/ } } } return filtered; }
From source file:org.apache.tajo.util.ClassUtil.java
private static boolean isMatched(Class clazz, Class targetClass, Predicate predicate) { return !clazz.isInterface() && (targetClass == null || isClassMatched(targetClass, clazz)) && (predicate == null || predicate.evaluate(clazz)); }
From source file:org.broad.igv.cbio.GeneNetwork.java
/** * Applies {@code predicate} to every element in {@code object}, and adds * any which return false to {@code rejectSet}. Intended for soft filtering. * There is an override here, where we never filter out a Node which * is marked as being part of the query/* www.j av a2 s . c o m*/ * * @param predicate * @param objects * @param rejectSet * @return * @throws IllegalStateException If the filters have been finalized. */ private int filter(Predicate predicate, Iterable<Node> objects, Set rejectSet) { if (filtersFinalized) { throw new IllegalStateException("Cannot filter after filtering has been finalized"); } int filtered = 0; for (Node v : objects) { String in_query = getNodeAttrValue(v, KEY, "IN_QUERY"); if (Boolean.parseBoolean(in_query)) { continue; } if (!predicate.evaluate(v)) { filtered += rejectSet.add(v) ? 1 : 0; } } return filtered; }
From source file:org.broad.igv.cbio.GeneNetworkTest.java
@Test public void testFilterGraph() throws Exception { GeneNetwork geneNetwork = new GeneNetwork(); assertTrue(geneNetwork.loadNetwork(TestUtils.DATA_DIR + "egfr_brca1.xml.gz") > 0); final String badname = "NA"; Predicate<Node> has_evidence = new Predicate<Node>() { public boolean evaluate(Node object) { String label = GeneNetwork.getNodeKeyData(object, "EXPERIMENTAL_TYPE"); return label != null && !label.equals(badname); }/* w w w .ja va 2 s . c o m*/ }; //Perform the filtering. //This is true if any modifications are made. assertTrue(geneNetwork.filterEdges(has_evidence) > 0); geneNetwork.finalizeFilters(); for (Node e : geneNetwork.edgeSet()) { assertTrue(has_evidence.evaluate(e)); } }
From source file:org.broad.igv.util.collections.CollUtils.java
/** * Filters the provided collection in place. Only those objects for which * predicate(object) returns true will be kept. Collection must support object * removal.//from w w w .ja va 2 s . c o m * * @param objects * @param predicate * @param <T> */ public static <T> void filter(Collection<? extends T> objects, Predicate<T> predicate) { if (objects == null) return; Iterator<? extends T> iter = objects.iterator(); while (iter.hasNext()) { T next = iter.next(); if (!predicate.evaluate(next)) { iter.remove(); } } }
From source file:org.broad.igv.util.collections.CollUtils.java
/** * Filters the provided collection in place. Only those objects for which * predicate(object) returns true will be kept. Collection must support object * removal.//from ww w .j a va2 s. c om * * @param objects * @param predicate * @param <T> */ public static <T> Collection<T> filteredCopy(Collection<? extends T> objects, Predicate<T> predicate) { if (objects == null) return null; Collection<T> coll = new ArrayList<T>(objects.size()); Iterator<? extends T> iter = objects.iterator(); while (iter.hasNext()) { T next = iter.next(); if (predicate.evaluate(next)) { coll.add(next); } } return coll; }
From source file:org.businessmanager.util.CollectionUtil.java
public static <T> List<T> predicateUnmodifiableSubList(List<T> sourceList, Predicate predicate) { List<T> resultList = new ArrayList<T>(); for (Iterator<T> it = sourceList.iterator(); it.hasNext();) { T curObj = it.next();/*from w ww .j ava2s. c om*/ if (predicate.evaluate(curObj)) { resultList.add(curObj); } } return new UnmodifiableList<T>(resultList); }
From source file:org.examproject.tweet.aspect.TweetServiceAspect.java
@After("execution(* org.examproject.tweet.service.TweetService.update(..))") public void updateAfter(JoinPoint jp) { LOG.debug("called."); Predicate jaPredicate = new IsContainJaKanaCodePredicate(); Predicate krPredicate = new IsContainKrHangulCodePredicate(); // set tweetService. TweetService tweetService = (TweetService) jp.getThis(); TweetDto tweetDto = tweetService.getCurrent(); String text = tweetDto.getText(); // contain japanese. if (jaPredicate.evaluate(text)) { return;//from ww w . j a v a 2s . c om } // contain korean. if (krPredicate.evaluate(text)) { // do permalinkService. PermalinkService permalinkService = (PermalinkService) context.getBean(PERMALINK_SERVICE_BEAN_ID); permalinkService.update(tweetDto); // do tagcrowdService. TagcrowdService tagcrowdService = (TagcrowdService) context.getBean(TAGCROWD_SERVICE_BEAN_ID); tagcrowdService.update(tweetDto); } }