List of usage examples for org.apache.commons.collections15 Predicate evaluate
public boolean evaluate(T object);
From source file:com.diversityarrays.kdxplore.data.kdx.CurationData.java
public Map<PlotOrSpecimen, KdxSample> getEditStateSamplesByPlotOrSpecimen(TraitInstance ti, Predicate<Plot> plotFilter) { Map<PlotOrSpecimen, KdxSample> result = new HashMap<>(plots.size()); for (Plot plot : plots) { if (plotFilter == null || plotFilter.evaluate(plot)) { for (Integer psnum : plot.getSpecimenNumbers(PlotOrSpecimen.INCLUDE_PLOT)) { PlotOrSpecimen pos = plot.getPlotOrSpecimen(psnum); KdxSample sm = getEditStateSampleFor(ti, pos); if (sm != null) { result.put(pos, sm); }//from w w w . jav a2s . c o m } } } return result; }
From source file:com.diversityarrays.kdxplore.data.kdx.CurationData.java
public Map<Plot, Map<Integer, KdxSample>> getEditStateSamplesByPlot(TraitInstance ti, Predicate<Plot> plotFilter) { Map<Plot, Map<Integer, KdxSample>> result = new HashMap<>(plots.size()); for (Plot plot : plots) { if (plotFilter == null || plotFilter.evaluate(plot)) { for (Integer psnum : plot.getSpecimenNumbers(PlotOrSpecimen.INCLUDE_PLOT)) { PlotOrSpecimen pos = plot.getPlotOrSpecimen(psnum); KdxSample sm = getEditStateSampleFor(ti, pos); if (sm != null) { Map<Integer, KdxSample> map = result.get(plot); if (map == null) { map = new HashMap<>(); result.put(plot, map); }/* w ww. j a v a 2 s . co m*/ map.put(psnum, sm); } } } } return result; }
From source file:org.drugis.common.beans.FilteredObservableList.java
protected <F> int findFirstIndex(final List<F> list, final Predicate<F> filter) { for (int i = 0; i < list.size(); ++i) { if (filter.evaluate(list.get(i))) { return i; }// www. j a v a 2 s . c o m } return -1; }
From source file:org.jcodec.containers.mp4.boxes.MovieBox.java
public void filterTracks(Predicate<TrakBox> pred) { Iterator<Box> it = boxes.iterator(); while (it.hasNext()) { Box next = it.next();/*from w ww .j a v a 2 s . c o m*/ if ((next instanceof TrakBox) && !pred.evaluate((TrakBox) next)) it.remove(); } }
From source file:org.springframework.jdbc.repo.impl.jdbc.RawPropertiesRepoImpl.java
@Override @Transactional(readOnly = true)//from w ww .j a v a 2s.c o m public List<String> findEntities(final String propName, final Predicate<? super Serializable> predicate) { if (StringUtils.isEmpty(propName)) { throw new IllegalArgumentException( "findEntities(" + getEntityClass().getSimpleName() + ") no property specified"); } if (predicate == null) { throw new IllegalArgumentException( "findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "] no predicate"); } final Set<String> internalIdsSet = new HashSet<String>(); final Set<String> matchingSet = jdbcAccessor.query("SELECT " + PROPS_TABLE_ALIAS + "." + PROP_OWNER_COL + " AS " + PROP_OWNER_COL + " ," + PROPS_TABLE_ALIAS + "." + PROP_NAME_COL + " AS " + PROP_NAME_COL + " ," + PROPS_TABLE_ALIAS + "." + PROP_TYPE_COL + " AS " + PROP_TYPE_COL + " ," + PROPS_TABLE_ALIAS + "." + PROP_VALUE_COL + " AS " + PROP_VALUE_COL + " ," + ENTITIES_TABLE_ALIAS + "." + ENTITY_ID_COL + " AS " + ENTITY_ID_COL + " FROM " + ENTITY_PROPERTIES_TABLE + " AS " + PROPS_TABLE_ALIAS + " INNER JOIN " + IDENTIFIED_ENTITIES_TABLE + " AS " + ENTITIES_TABLE_ALIAS + " ON " + ENTITIES_TABLE_ALIAS + "." + INTERNAL_ID_COL + " = " + PROPS_TABLE_ALIAS + "." + PROP_OWNER_COL + " AND " + ENTITIES_TABLE_ALIAS + "." + ENTITY_TYPE_COL + " = :" + ENTITY_TYPE_COL + " AND " + PROPS_TABLE_ALIAS + "." + PROP_NAME_COL + " = :" + PROP_NAME_COL, new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER) { private static final long serialVersionUID = 1L; { put(ENTITY_TYPE_COL, getEntityClass().getSimpleName()); put(PROP_NAME_COL, propName); } }, new ResultSetExtractor<Set<String>>() { @Override @SuppressWarnings("synthetic-access") public Set<String> extractData(ResultSet rs) throws SQLException, DataAccessException { while (rs.next()) { int rowNum = rs.getRow(); Pair<String, Serializable> rowValue = valueMapper.mapRow(rs, rowNum); String rowName = rowValue.getLeft(); String ownerId = rs.getString(ENTITY_ID_COL); // just for safety if (ExtendedStringUtils.safeCompare(propName, rowName, false) != 0) { logger.warn("findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "]" + " mismatched property name at row " + rowNum + " for owner=" + ownerId + ": " + rowName); continue; } Serializable propValue = rowValue.getRight(); if (!predicate.evaluate(propValue)) { if (logger.isTraceEnabled()) { logger.trace("findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "]" + " skip row " + rowNum + " value=" + propValue + " for owner=" + ownerId); } continue; } if (StringUtils.isEmpty(ownerId)) { throw new SQLException("findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "]" + " no owner for row " + rowNum + " on matching value=" + propValue); } if (logger.isTraceEnabled()) { logger.trace("findEntities(" + getEntityClass().getSimpleName() + ")[" + propName + "]" + " matched row " + rowNum + " value=" + propValue + " for owner=" + ownerId); } if (!internalIdsSet.add(ownerId)) { continue; // debug breakpoint } } return internalIdsSet; } }); if (ExtendedCollectionUtils.isEmpty(matchingSet)) { return Collections.emptyList(); } else { return new ArrayList<String>(matchingSet); } }