List of usage examples for java.util.function Predicate test
boolean test(T t);
From source file:org.jsweet.input.typescriptdef.ast.Scanner.java
@SuppressWarnings("unchecked") public <T extends Visitable> T getParent(Predicate<Visitable> predicate, Visitable from) { for (int i = this.stack.size() - 1; i >= 0; i--) { if (this.stack.get(i) == from) { for (int j = i - 1; j >= 0; j--) { if (predicate.test(this.stack.get(j))) { return (T) this.stack.get(j); }//w ww. j ava2 s . co m } return null; } } return null; }
From source file:at.gridtec.lambda4j.predicate.tri.obj.ObjBiBooleanPredicate.java
/** * Returns a composed {@link TriPredicate} that first applies the {@code before} functions to its input, and * then applies this predicate to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given function, and of composed predicate * @param <B> The type of the argument to the second given predicate, and of composed predicate * @param <C> The type of the argument to the third given predicate, and of composed predicate * @param before1 The first function to apply before this predicate is applied * @param before2 The second predicate to apply before this predicate is applied * @param before3 The third predicate to apply before this predicate is applied * @return A composed {@code TriPredicate} that first applies the {@code before} functions to its input, and then * applies this predicate to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. *//*from w w w . ja va2 s . c o m*/ @Nonnull default <A, B, C> TriPredicate<A, B, C> compose(@Nonnull final Function<? super A, ? extends T> before1, @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> test(before1.apply(a), before2.test(b), before3.test(c)); }
From source file:at.gridtec.lambda4j.predicate.tri.obj.BiObjBooleanPredicate.java
/** * Returns a composed {@link TriPredicate} that first applies the {@code before} functions to its input, and * then applies this predicate to the result. * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation. * * @param <A> The type of the argument to the first given function, and of composed predicate * @param <B> The type of the argument to the second given function, and of composed predicate * @param <C> The type of the argument to the third given predicate, and of composed predicate * @param before1 The first function to apply before this predicate is applied * @param before2 The second function to apply before this predicate is applied * @param before3 The third predicate to apply before this predicate is applied * @return A composed {@code TriPredicate} that first applies the {@code before} functions to its input, and then * applies this predicate to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is able to handle every type. *//*www.j a va 2s . c om*/ @Nonnull default <A, B, C> TriPredicate<A, B, C> compose(@Nonnull final Function<? super A, ? extends T> before1, @Nonnull final Function<? super B, ? extends U> before2, @Nonnull final Predicate<? super C> before3) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); Objects.requireNonNull(before3); return (a, b, c) -> test(before1.apply(a), before2.apply(b), before3.test(c)); }
From source file:org.opencb.opencga.storage.mongodb.variant.MongoDBVariantStoragePipeline.java
private BatchFileOperation getBatchFileOperation(List<BatchFileOperation> batches, Predicate<BatchFileOperation> filter) { for (int i = batches.size() - 1; i >= 0; i--) { BatchFileOperation op = batches.get(i); if (filter.test(op)) { return op; }//from w w w .jav a 2 s. c o m } return null; }
From source file:it.polimi.diceH2020.SPACE4CloudWS.core.CoarseGrainedOptimizer.java
private List<Triple<Integer, Optional<Double>, Boolean>> alterUntilBreakPoint(SolutionPerJob solPerJob, Function<Integer, Integer> updateFunction, Function<Double, Double> fromResult, Predicate<Double> feasibilityCheck, Predicate<Double> stoppingCondition, BiPredicate<Double, Double> incrementCheck, Predicate<Integer> vmCheck) { List<Triple<Integer, Optional<Double>, Boolean>> lst = new ArrayList<>(); Optional<Double> previous = Optional.empty(); boolean shouldKeepGoing = true; while (shouldKeepGoing) { Pair<Optional<Double>, Long> simulatorResult = dataProcessor.simulateClass(solPerJob); Optional<Double> maybeResult = simulatorResult.getLeft(); Optional<Double> interestingMetric = maybeResult.map(fromResult); Integer nVM = solPerJob.getNumberVM(); lst.add(new ImmutableTriple<>(nVM, maybeResult, interestingMetric.filter(feasibilityCheck).isPresent())); boolean terminationCriterion = !checkState(); logger.trace("terminationCriterion is " + terminationCriterion + " after checkState()"); terminationCriterion |= vmCheck.test(nVM); logger.trace("terminationCriterion is " + terminationCriterion + " after vmCheck.test()"); terminationCriterion |= interestingMetric.filter(stoppingCondition).isPresent(); logger.trace("terminationCriterion is " + terminationCriterion + " after filter"); if (previous.isPresent() && interestingMetric.isPresent() && (dataService.getScenario().getTechnology() != Technology.STORM || interestingMetric.get() == 0.0)) { terminationCriterion |= incrementCheck.test(previous.get(), interestingMetric.get()); }//from www . j ava2 s. c o m shouldKeepGoing = !terminationCriterion; previous = interestingMetric; if (dataService.getScenario().getTechnology() == Technology.STORM) { logger.trace(interestingMetric.orElse(Double.NaN) + " vs. " + solPerJob.getJob().getU()); } else { logger.trace(interestingMetric.orElse(Double.NaN) + " vs. " + solPerJob.getJob().getD()); } if (shouldKeepGoing) { String message = String.format("class %s -> num VM: %d, simulator result: %f, metric: %f", solPerJob.getId(), nVM, maybeResult.orElse(Double.NaN), interestingMetric.orElse(Double.NaN)); logger.info(message); solPerJob.updateNumberVM(updateFunction.apply(nVM)); } } return lst; }
From source file:com.haulmont.cuba.core.app.RdbmsStore.java
protected boolean needToApplyByPredicate(LoadContext context, Predicate<MetaClass> hasConstraints) { if (context.getView() == null) { MetaClass metaClass = metadata.getSession().getClassNN(context.getMetaClass()); return hasConstraints.test(metaClass); }/*w w w. j a va2s . c om*/ Session session = metadata.getSession(); for (Class aClass : collectEntityClasses(context.getView(), new HashSet<>())) { if (hasConstraints.test(session.getClassNN(aClass))) { return true; } } return false; }
From source file:org.sakaiproject.gradebookng.tool.model.GbGradebookData.java
private String formatColumnFlags(final GbStudentGradeInfo student, final Predicate<GbGradeInfo> predicate) { final StringBuilder sb = new StringBuilder(); for (final ColumnDefinition column : this.columns) { if (column instanceof AssignmentDefinition) { final AssignmentDefinition assignmentColumn = (AssignmentDefinition) column; final GbGradeInfo gradeInfo = student.getGrades().get(assignmentColumn.getAssignmentId()); if (gradeInfo != null && predicate.test(gradeInfo)) { sb.append('1'); } else { sb.append('0'); }/*from w w w . ja v a 2s . c om*/ } else { sb.append('0'); } } return sb.toString(); }
From source file:org.teavm.flavour.templates.parsing.Parser.java
private void parseTag(Tag tag, List<TemplateNode> result, Predicate<Element> filter) { if (tag instanceof StartTag) { StartTag startTag = (StartTag) tag; if (startTag.getStartTagType() == StartTagType.XML_PROCESSING_INSTRUCTION) { parseProcessingInstruction(startTag); } else if (startTag.getStartTagType() == StartTagType.NORMAL) { if (filter.test(tag.getElement())) { TemplateNode node = parseElement(tag.getElement()); if (node != null) { result.add(node);/*w ww. j ava2 s . co m*/ } } else { position = tag.getElement().getEnd(); } } } }
From source file:com.antsdb.saltedfish.sql.planner.Planner.java
public PlannerField findField(Predicate<FieldMeta> predicate) { PlannerField result = null;//w w w . j ava2 s . c om for (Node i : this.nodes.values()) { if (i.isParent) { continue; } for (PlannerField j : i.fields) { if (predicate.test(j)) { if (result != null) { throw new OrcaException("Column is ambiguous: " + j); } result = j; } } } if (result == null) { if (this.parent != null) { result = this.parent.findField(predicate); } } return result; }
From source file:org.jsweet.transpiler.candies.CandiesProcessor.java
private void extractCandy( // CandyDescriptor descriptor, // JarFile jarFile, // File javaOutputDirectory, // File tsDefOutputDirectory, // File jsOutputDirectory, // Predicate<String> isTsDefToBeExtracted) { logger.info("extract candy: " + jarFile.getName() + " javaOutputDirectory=" + javaOutputDirectory + " tsDefOutputDirectory=" + tsDefOutputDirectory + " jsOutputDir=" + jsOutputDirectory); jarFile.stream().filter(entry -> entry.getName().endsWith(".d.ts") && (entry.getName().startsWith("src/") || entry.getName().startsWith("META-INF/resources/"))) // .forEach(entry -> {//from www. ja v a2 s. co m File out; if (entry.getName().endsWith(".java")) { // RP: this looks like dead code... out = new File(javaOutputDirectory + "/" + entry.getName().substring(4)); } else if (entry.getName().endsWith(".d.ts")) { if (isTsDefToBeExtracted != null && !isTsDefToBeExtracted.test(entry.getName())) { return; } out = new File(tsDefOutputDirectory + "/" + entry.getName()); } else { out = null; } extractEntry(jarFile, entry, out); }); for (String jsFilePath : descriptor.jsFilesPaths) { JarEntry entry = jarFile.getJarEntry(jsFilePath); String relativeJsPath = jsFilePath.substring(descriptor.jsDirPath.length()); File out = new File(jsOutputDirectory, relativeJsPath); extractEntry(jarFile, entry, out); } }