List of usage examples for org.apache.commons.collections4 Predicate Predicate
Predicate
From source file:de.tor.tribes.util.VillageUtils.java
public static Village[] getVillagesByContinent(Village[] pVillages, final Integer[] pContinents, Comparator<Village> pComparator) { if (pContinents == null || pContinents.length == 0) { return pVillages; }/*from w ww .java2 s . c om*/ List<Village> villages = new LinkedList<>(); Collections.addAll(villages, pVillages); CollectionUtils.filter(villages, new Predicate() { @Override public boolean evaluate(Object o) { return ArrayUtils.contains(pContinents, ((Village) o).getContinent()); } }); if (pComparator != null) { Collections.sort(villages, pComparator); } return villages.toArray(new Village[villages.size()]); }
From source file:de.tor.tribes.util.attack.StandardAttackManager.java
public boolean containsElementByIcon(final int pIcon) { Object result = CollectionUtils.find(getAllElements(), new Predicate() { @Override// www . j a v a2 s. c o m public boolean evaluate(Object o) { return ((StandardAttack) o).getIcon() == pIcon; } }); return result != null; }
From source file:io.github.tjg1.library.norilib.SearchResult.java
/** * Remove images with the given set of {@link Tag}s from this SearchResult. * * @param tags Tags to remove.//from w w w. ja v a2 s. c om */ public void filter(final Tag... tags) { // Don't waste time filtering against an empty array. if (tags == null || tags.length == 0) { return; } // Don't filter tags searched for by the user. final Collection<Tag> tagList = CollectionUtils.removeAll(Arrays.asList(tags), Arrays.asList(query)); // Remove images containing filtered tags. CollectionUtils.filter(images, new Predicate<Image>() { @Override public boolean evaluate(Image image) { return !CollectionUtils.containsAny(Arrays.asList(image.tags), tagList); } }); reorderImagePageOffsets(); }
From source file:com.feilong.core.util.predicate.BeanPredicateUtil.java
/** * Contains predicate.//w w w. j a v a 2s .c o m * * <p> * {@link PropertyUtil#getProperty(Object, String)} <code>propertyName</code>,{@link java.util.Collection#contains(Object) * Collection.contains} ?<code>values</code>?. * </p> * * @param <T> * the generic type * @param <V> * the value type * @param propertyName * T??,Possibly indexed and/or nested name of the property to be modified,?? * <a href="../../bean/BeanUtil.html#propertyName">propertyName</a> * @param propertyValueList * the property value list * @return <code>propertyName</code> null, {@link NullPointerException}<br> * <code>propertyName</code> blank, {@link IllegalArgumentException}<br> * @see java.util.Collection#contains(Object) */ public static <T, V> Predicate<T> containsPredicate(final String propertyName, final Collection<V> propertyValueList) { return new BeanPredicate<T>(propertyName, new Predicate<V>() { @Override public boolean evaluate(V propertyValue) { return isNullOrEmpty(propertyValueList) ? false : propertyValueList.contains(propertyValue); } }); }
From source file:de.tor.tribes.types.TargetInformation.java
public boolean addAttack(final Village pSource, final Date pArrive, UnitHolder pUnit, boolean fake, boolean snob) { List<TimedAttack> attacksFromSource = timedAttacks.get(pSource); if (attacksFromSource == null) { attacksFromSource = new LinkedList<>(); timedAttacks.put(pSource, attacksFromSource); }/*from w ww. jav a 2s. co m*/ Object result = CollectionUtils.find(attacksFromSource, new Predicate() { @Override public boolean evaluate(Object o) { TimedAttack t = (TimedAttack) o; return t.getSource().equals(pSource) && t.getlArriveTime().equals(pArrive.getTime()); } }); if (result == null) { TimedAttack a = new TimedAttack(pSource, pArrive); a.setPossibleFake(fake); a.setPossibleSnob(snob); a.setUnit(pUnit); attacksFromSource.add(a); Collections.sort(attacksFromSource, SOSRequest.ARRIVE_TIME_COMPARATOR); updateAttackInfo(); return true; } return false; }
From source file:eu.openanalytics.rpooli.RPooliServer.java
public RPooliNode findNodeById(final String nodeId) { return find(getNodes(), new Predicate<RPooliNode>() { @Override// w w w .j a v a 2 s. co m public boolean evaluate(final RPooliNode node) { return node.getId().equals(nodeId); } }); }
From source file:io.github.tjg1.library.norilib.SearchResult.java
/** * Remove images not in the given set of {@link Image.SafeSearchRating} from this SearchResult. * * @param safeSearchRatings SafeSearch ratings to remove. *///from www . j a v a 2 s. c o m public void filter(final Image.SafeSearchRating... safeSearchRatings) { // Don't waste time filtering against an empty array. if (safeSearchRatings == null || safeSearchRatings.length == 0) { return; } // Concert filtered rating array to List final List<Image.SafeSearchRating> ratingList = Arrays.asList(safeSearchRatings); // Remove images containing filtered ratings. CollectionUtils.filter(images, new Predicate<Image>() { @Override public boolean evaluate(Image image) { return ratingList.contains(image.safeSearchRating); } }); reorderImagePageOffsets(); }
From source file:com.wiiyaya.provider.main.service.impl.RoleServiceImpl.java
@Override @Transactional(rollbackFor = BusinessException.class) public void updateRole(RoleDto roleDto) throws BusinessException { Role roleDb = roleDao.findOne(roleDto.getId()); if (roleDb == null) { throw new BusinessException(MainConstant.ERROR_ROLE_NOT_FOUND); }/*from ww w . j a v a 2 s .com*/ roleDb.setName(roleDto.getName()); roleDb.setVersion(roleDto.getVersion()); if (CollectionUtils.isNotEmpty(roleDto.getPrivilegeIds())) { for (Iterator<Privilege> itDb = roleDb.getPrivileges().iterator(); itDb.hasNext();) { final Privilege privilegeDb = itDb.next(); boolean existInPage = IterableUtils.matchesAny(roleDto.getPrivilegeIds(), new Predicate<Long>() { @Override public boolean evaluate(Long object) { return privilegeDb.getId().equals(object); } }); if (!existInPage) { itDb.remove(); } } roleDb.getPrivileges().addAll(privilegeDao.findAll(roleDto.getPrivilegeIds())); } else { roleDb.getPrivileges().clear(); } roleDao.save(roleDb); }
From source file:de.micromata.genome.gwiki.pagelifecycle_1_0.jobs.GWikiPlcReleaseJob.java
/** * Collect and filter contents in branch * /*from ww w.jav a2 s. co m*/ * @param branch * @return */ private Collection<GWikiElement> getBranchContents(final String branch) { final Matcher<String> blackListMatcher = new BooleanListRulesFactory<String>() .createMatcher("*intern/*,*admin/*"); final List<GWikiElement> branchContent = wikiContext.getElementFinder() .getPages(new MatcherBase<GWikiElementInfo>() { private static final long serialVersionUID = -6020166500681050082L; @Override public boolean match(GWikiElementInfo ei) { String tid = ei.getProps().getStringValue(GWikiPropKeys.TENANT_ID); return StringUtils.equals(branch, tid); } }); Collection<GWikiElement> filteredBranchContent = CollectionUtils.select(branchContent, new Predicate<GWikiElement>() { @Override public boolean evaluate(GWikiElement object) { return !blackListMatcher.match(object.getElementInfo().getId()); } }); return filteredBranchContent; }
From source file:com.link_intersystems.lang.reflect.criteria.ElementCriteria.java
/** * Takes the iterator and wraps it into a filtering iterator that applies * the selection requirements as they are configured via * {@link #setResult(Result)}.//from ww w.j ava 2 s .com * * @param <T> * @param iterator * @return an {@link Iterator} that selects the elements of the given * {@link Iterator} according to selection as specified by * {@link #setResult(Result)}. * * @since 1.0.0.0 */ protected Iterator<T> applySelectionFilter(final Iterator<T> iterator) { Iterator<T> result = null; switch (select) { case FIRST: Predicate<Object> firstPredicate = new Predicate<Object>() { private boolean first = true; public boolean evaluate(Object object) { if (first) { first = false; return true; } return false; } }; result = IteratorUtils.filteredIterator(iterator, firstPredicate); break; case LAST: Predicate<Object> lastElementPredicate = new Predicate<Object>() { public boolean evaluate(Object object) { return !iterator.hasNext(); } }; result = IteratorUtils.filteredIterator(iterator, lastElementPredicate); break; case ALL: result = iterator; break; } return result; }