List of usage examples for java.util.function Predicate and
default Predicate<T> and(Predicate<? super T> other)
From source file:com.epam.ta.reportportal.core.item.history.TestItemsHistoryHandlerImpl.java
@Override public List<TestItemHistoryElement> getItemsHistory(String projectName, String[] startPointsIds, int historyDepth, boolean showBrokenLaunches) { Project project = projectRepository.findOne(projectName); BusinessRule.expect(project, Predicates.notNull()).verify(ErrorType.PROJECT_NOT_FOUND, projectName); Predicate<Integer> greaterThan = t -> t > MIN_HISTORY_DEPTH_BOUND; Predicate<Integer> lessThan = t -> t < MAX_HISTORY_DEPTH_BOUND; String historyDepthMessage = "Items history depth should be greater than '" + MIN_HISTORY_DEPTH_BOUND + "' and lower than '" + MAX_HISTORY_DEPTH_BOUND + "'"; BusinessRule.expect(historyDepth, greaterThan.and(lessThan)).verify(UNABLE_LOAD_TEST_ITEM_HISTORY, historyDepthMessage);/* w ww.ja va2 s .c o m*/ BusinessRule.expect(startPointsIds.length, t -> t < MAX_HISTORY_SIZE_BOUND).verify( UNABLE_LOAD_TEST_ITEM_HISTORY, "History size should be less than '" + MAX_HISTORY_SIZE_BOUND + "' test items."); List<String> listIds = Lists.newArrayList(startPointsIds); List<TestItem> itemsForHistory = historyServiceStrategy.loadItems(listIds); historyServiceStrategy.validateItems(itemsForHistory, listIds, projectName); List<Launch> launches = historyServiceStrategy.loadLaunches(historyDepth, itemsForHistory.get(0).getLaunchRef(), projectName, showBrokenLaunches); List<String> historyLaunchesIds = launches.stream().map(Launch::getId).collect(Collectors.toList()); List<TestItem> history = testItemRepository.loadItemsHistory(itemsForHistory, historyLaunchesIds, loadParentIds(itemsForHistory.get(0), historyLaunchesIds)); Map<String, List<TestItem>> groupedItems = history.stream() .collect(Collectors.groupingBy(TestItem::getLaunchRef)); return launches.stream().map(launch -> buildHistoryElement(launch, groupedItems.get(launch.getId()))) .collect(Collectors.toList()); }
From source file:com.tsguild.pumpingunitdb.dao.UnitDaoReal.java
@Override public List<Unit> searchUnits(Map<SearchTerm, String> criteria) { Map<Integer, Unit> unitMap = new HashMap<>(); //ArrayList<Unit>asdt =new ArrayList<>(); for (Unit u : jdbcTemplate.query(SQL_SELECT_ALL_UNITS, new UnitMapper())) { unitMap.put(u.getTrackingNumber(), u); }//from w w w . j a va2 s . co m ; String makeCriteria = criteria.get(SearchTerm.MAKE); String modelCriteria = criteria.get(SearchTerm.MODEL); String sizeCriteria = criteria.get(SearchTerm.SIZE); String serialCriteria = criteria.get(SearchTerm.SERIAL_NUMBER); String weightsCriteria = criteria.get(SearchTerm.WEIGHTS); String notesCriteria = criteria.get(SearchTerm.NOTES); // Declare all the predicate conditions Predicate<Unit> makeMatches; Predicate<Unit> modelMatches; Predicate<Unit> sizeMatches; Predicate<Unit> serialMatches; Predicate<Unit> weightsMatches; Predicate<Unit> notesMatches; // Placeholder predicate - always returns true. Used for search terms // that are empty Predicate<Unit> truePredicate = (c) -> { return true; }; // Assign values to predicates. If a given search term is empty, just // assign the default truePredicate, otherwise assign the predicate that // properly filters for the given term. makeMatches = (makeCriteria == null || makeCriteria.isEmpty()) ? truePredicate : (c) -> c.getMake().equals(makeCriteria); modelMatches = (modelCriteria == null || modelCriteria.isEmpty()) ? truePredicate : (c) -> c.getModel().equals(modelCriteria); sizeMatches = (sizeCriteria == null || sizeCriteria.isEmpty()) ? truePredicate : (c) -> c.getSize().equals(sizeCriteria); serialMatches = (serialCriteria == null || serialCriteria.isEmpty()) ? truePredicate : (c) -> c.getSerialNumber().equals(serialCriteria); weightsMatches = (weightsCriteria == null || weightsCriteria.isEmpty()) ? truePredicate : (c) -> c.getWeights().equals(weightsCriteria); notesMatches = (notesCriteria == null || notesCriteria.isEmpty()) ? truePredicate : (c) -> c.getNotes().equals(notesCriteria); // Return the list of Contacts that match the given criteria. To do this we // just AND all the predicates together in a filter operation. return unitMap.values().stream().filter(makeMatches.and(modelMatches).and(sizeMatches).and(serialMatches) .and(weightsMatches).and(notesMatches)).collect(Collectors.toList()); }
From source file:org.mycore.common.MCRUtils.java
/** * merges to HashSets of MyCoreIDs after specific rules * //from w w w . j ava 2s .c o m * @see #COMMAND_OR * @see #COMMAND_AND * @see #COMMAND_XOR * @param set1 * 1st HashSet to be merged * @param set2 * 2nd HashSet to be merged * @param operation * available COMMAND_XYZ * @return merged HashSet * @deprecated use {@link Stream}s for this */ @Deprecated public static <T> HashSet<T> mergeHashSets(HashSet<? extends T> set1, HashSet<? extends T> set2, char operation) { Predicate<T> inSet1 = set1::contains; Predicate<T> inSet2 = set2::contains; Predicate<T> op; switch (operation) { case COMMAND_OR: op = t -> true;//inSet1.or(inSet2); break; case COMMAND_AND: op = inSet1.and(inSet2); break; case COMMAND_XOR: op = inSet1.and(inSet2).negate(); break; default: throw new IllegalArgumentException("operation not permited: " + operation); } return Stream.concat(set1.stream(), set2.stream()).filter(op) .collect(Collectors.toCollection(HashSet::new)); }
From source file:org.nuxeo.enrichers.RelationDocumentsContentEnricher.java
@Override public void write(JsonGenerator jg, DocumentModel document) throws IOException { Principal principal = ctx.getSession(document).getSession().getPrincipal(); try (SessionWrapper wrapper = ctx.getSession(document)) { String id = document.getId(); new UnrestrictedSessionRunner(wrapper.getSession()) { @Override/*from w w w . ja v a 2 s . c o m*/ public void run() { // control the graph depth try (Closeable resource = ctx.wrap().controlDepth().open()) { StringBuilder query = new StringBuilder("SELECT * FROM "); query.append("DefaultRelation").append(" WHERE ").append("relation:source").append("=") .append(NXQL.escapeString(id)).append(Operator.OR.toString()) .append(" " + "relation:target" + " ").append("=").append(NXQL.escapeString(id)); DocumentModelList relations = session.query(query.toString()); Predicate<DocumentModel> canReadSourceDocument = doc -> session.hasPermission(principal, new IdRef((String) doc.getPropertyValue("relation:source")), SecurityConstants.READ); Predicate<DocumentModel> canReadTargetDocument = doc -> session.hasPermission(principal, new IdRef((String) doc.getPropertyValue("relation:target")), SecurityConstants.READ); Predicate<DocumentModel> canReadRelatedDocuments = canReadSourceDocument .and(canReadTargetDocument); DocumentModelList accessableRelations = relations.stream().filter(canReadRelatedDocuments) .collect(Collectors.toCollection(DocumentModelListImpl::new)); jg.writeFieldName(NAME); // delegate the marshalling to Nuxeo Platform writeEntity(accessableRelations, jg); } catch (MaxDepthReachedException e) { // do not apply enricher } catch (IOException e) { LOG.error(e, e); } } }.runUnrestricted(); } }
From source file:org.opencb.opencga.storage.core.variant.adaptors.VariantDBAdaptorTest.java
public long filterPopulation(QueryResult<Variant> queryResult, Predicate<Variant> filterVariants, Predicate<Map<String, PopulationFrequency>> predicate) { queryResult.getResult().forEach(variant -> { assertNotNull(variant);/*from w w w . ja v a 2 s. com*/ assertNotNull("In " + variant, variant.getAnnotation()); // assertNotNull("In " + variant, variant.getAnnotation().getPopulationFrequencies()); }); Set<String> expectedVariants = allVariants.getResult().stream() .filter(filterVariants.and(variant -> variant.getAnnotation() != null)).filter(variant -> { Map<String, PopulationFrequency> map; if (variant.getAnnotation().getPopulationFrequencies() == null) { map = Collections.emptyMap(); } else { map = new HashMap<>(); for (PopulationFrequency p : variant.getAnnotation().getPopulationFrequencies()) { map.put(p.getStudy() + ":" + p.getPopulation(), p); } } return predicate.test(map); }).map(Variant::toString).collect(Collectors.toSet()); assertTrue("Expect to get at least one result", expectedVariants.size() > 0); for (String variant : expectedVariants) { Set<String> result = queryResult.getResult().stream().map(Variant::toString) .collect(Collectors.toSet()); if (!result.contains(variant)) { System.out.println("variant missing = " + variant); } } for (Variant variant : queryResult.getResult()) { if (!expectedVariants.contains(variant.toString())) { System.out.println("variant not suppose to be = " + variant); } } assertEquals(expectedVariants.size(), queryResult.getNumResults()); long count = queryResult.getResult().stream().map(variant -> { Map<String, PopulationFrequency> map; if (variant.getAnnotation().getPopulationFrequencies() == null) { map = Collections.emptyMap(); } else { map = new HashMap<>(); for (PopulationFrequency p : variant.getAnnotation().getPopulationFrequencies()) { map.put(p.getStudy() + ":" + p.getPopulation(), p); } } return map; }).filter(predicate.negate()).count(); assertEquals(0, count); return count; }
From source file:org.talend.dataprep.api.filter.SimpleFilterService.java
/** * Create a predicate that do a logical AND between 2 filters * * @param nodeContent The node content/*from w ww . java 2s . com*/ * @param rowMetadata Row metadata to used to obtain information (valid/invalid, types...) * @return the AND predicate */ private Predicate<DataSetRow> createAndPredicate(final JsonNode nodeContent, RowMetadata rowMetadata) { checkValidMultiPredicate(nodeContent); final Predicate<DataSetRow> leftFilter = buildFilter(nodeContent.get(0), rowMetadata); final Predicate<DataSetRow> rightFilter = buildFilter(nodeContent.get(1), rowMetadata); return leftFilter.and(rightFilter); }
From source file:org.talend.dataprep.filter.ObjectPredicateVisitor.java
@Override public Predicate<Object> visit(AndExpression andExpression) { final Expression[] expressions = andExpression.getExpressions(); if (expressions.length > 0) { Predicate<Object> predicate = (Predicate<Object>) expressions[0].accept(this); for (int i = 1; i < expressions.length; i++) { predicate = predicate.and((Predicate<Object>) expressions[i].accept(this)); }/*from w w w .ja va 2 s . c o m*/ return predicate; } else { return m -> true; } }
From source file:org.talend.dataprep.transformation.actions.common.CompileDataSetRowAction.java
/** * Get the row filter from parameters./*w w w . j a v a 2 s. com*/ * * @param parameters the transformation parameters * @param rowMetadata Row metadata to used to obtain information (valid/invalid, types...) * @return A {@link Predicate filter} for data set rows. */ private Predicate<DataSetRow> getFilter(Map<String, String> parameters, RowMetadata rowMetadata) { final String filterAsString = parameters.get(ImplicitParameters.FILTER.getKey()); final Predicate<DataSetRow> predicate = getFilterService().build(filterAsString, rowMetadata); if (scope == ScopeCategory.CELL || scope == ScopeCategory.LINE) { final Long rowId; final String rowIdAsString = parameters.get(ImplicitParameters.ROW_ID.getKey()); if (StringUtils.isNotBlank(rowIdAsString)) { rowId = Long.parseLong(rowIdAsString); } else { rowId = null; } final Predicate<DataSetRow> rowFilter = r -> Objects.equals(r.getTdpId(), rowId); return predicate.and(rowFilter); } else { return predicate; } }
From source file:org.talend.tql.bean.BeanPredicateVisitor.java
@Override public Predicate<T> visit(AndExpression andExpression) { final Expression[] expressions = andExpression.getExpressions(); if (expressions.length > 0) { Predicate<T> predicate = expressions[0].accept(this); for (int i = 1; i < expressions.length; i++) { predicate = predicate.and(expressions[i].accept(this)); }/*w ww . j ava 2 s . c o m*/ return predicate; } else { return m -> true; } }
From source file:org.talend.tql.bean.BeanPredicateVisitor.java
@Override public Predicate<T> visit(FieldBetweenExpression fieldBetweenExpression) { fieldBetweenExpression.getField().accept(this); final Method[] methods = currentMethods.pop(); fieldBetweenExpression.getLeft().accept(this); fieldBetweenExpression.getRight().accept(this); final String right = literals.pop(); final String left = literals.pop(); Predicate<T> predicate; if (fieldBetweenExpression.isLowerOpen()) { predicate = gt(left, methods);//from ww w. j a v a2 s .c o m } else { predicate = gte(left, methods); } if (fieldBetweenExpression.isUpperOpen()) { predicate = predicate.and(lt(right, methods)); } else { predicate = predicate.and(lte(right, methods)); } return predicate; }