List of usage examples for java.util.function Predicate test
boolean test(T t);
From source file:org.apache.metron.profiler.client.window.Window.java
/** * Compute the set of sorted (oldest to newest) window intervals relative to the passed timestamp * given inclusion and exclusion predicates. * * @param now/*w ww . ja v a2 s . co m*/ * @return */ public List<Range<Long>> toIntervals(long now) { List<Range<Long>> intervals = new ArrayList<>(); long startMillis = getStartMillis(now); long endMillis = getEndMillis(now); Iterable<Predicate<Long>> includes = getIncludes(now); Iterable<Predicate<Long>> excludes = getExcludes(now); //if we don't have a skip distance, then we just skip past everything to make the window dense long skipDistance = getSkipDistance().orElse(Long.MAX_VALUE); //if we don't have a window width, then we want the window to be completely dense. Optional<Long> binWidthOpt = getBinWidth(); long binWidth = binWidthOpt.isPresent() ? binWidthOpt.get() : endMillis - startMillis; for (long left = startMillis; left >= 0 && left + binWidth <= endMillis; left += skipDistance) { Range<Long> interval = Range.between(left, left + binWidth); boolean include = includes.iterator().hasNext() ? false : true; for (Predicate<Long> inclusionPredicate : includes) { include |= inclusionPredicate.test(left); } if (include) { for (Predicate<Long> exclusionPredicate : excludes) { include &= !exclusionPredicate.test(left); } } if (include) { intervals.add(interval); } } return intervals; }
From source file:org.opensingular.form.calculation.SimpleValueCalculation.java
default SimpleValueCalculation<RESULT> appendOn(Predicate<CalculationContext> condition, RESULT val) { return c -> { RESULT res = this.calculate(c); if (res != null) return res; return (condition.test(c)) ? val : null; };//from w w w . j ava 2 s . c om }
From source file:pt.ist.expenditureTrackingSystem.domain.organization.Unit.java
private static Unit findMatch(final Party party, final Predicate<Unit> predicate) { if (party != null && party.isUnit()) { final module.organization.domain.Unit unit = (module.organization.domain.Unit) party; if (unit.getExpenditureUnit() != null) { final Unit exUnit = unit.getExpenditureUnit(); if (predicate.test(exUnit)) { return exUnit; }/*from w w w.ja va2 s.c o m*/ } return unit.getChildAccountabilityStream() .filter(a -> a.getAccountabilityType() == ExpenditureTrackingSystem.getInstance() .getOrganizationalAccountabilityType()) .map(a -> findMatch(a.getChild(), predicate)).filter(u -> u != null).findAny().orElse(null); } return null; }
From source file:org.jmingo.document.id.IdFieldGenerator.java
private boolean applyFilters(Field field, Predicate<Field>... filters) { for (Predicate<Field> filter : Arrays.asList(filters)) { if (!filter.test(field)) { return false; }//w w w . ja v a 2 s. c om } return true; }
From source file:fr.landel.utils.assertor.utils.AssertorMap.java
private static <K, V> boolean match(final Map<K, V> map, final Predicate<Entry<K, V>> predicate, final boolean all, final EnumAnalysisMode analysisMode) { final Set<Entry<K, V>> entries = map.entrySet(); if (EnumAnalysisMode.STANDARD.equals(analysisMode)) { if (all) { for (final Entry<K, V> entry : entries) { if (!predicate.test(entry)) { return false; }/*from w w w . j a va 2 s .c o m*/ } return true; } else { for (final Entry<K, V> entry : entries) { if (predicate.test(entry)) { return true; } } return false; } } else { final Stream<Entry<K, V>> stream; if (EnumAnalysisMode.PARALLEL.equals(analysisMode)) { stream = entries.parallelStream(); } else { stream = entries.stream(); } if (all) { return stream.allMatch(predicate); } else { return stream.anyMatch(predicate); } } }
From source file:org.lendingclub.mercator.aws.ShadowAttributeRemover.java
protected List<String> getAttributesToRemove(JsonNode actual, JsonNode neo4j, Predicate<String> predicate) { List<String> list = Lists.newArrayList(); neo4j.fieldNames().forEachRemaining(n -> { if (n != null) { if (predicate.test(n)) { if (!actual.has(n)) { list.add(n);//w ww .j a v a2 s. c o m } } } }); return list; }
From source file:sagan.projects.support.BadgeController.java
private Optional<ProjectRelease> getRelease(Collection<ProjectRelease> projectReleases, Predicate<ProjectRelease> predicate) { Optional<ProjectRelease> first = projectReleases // .stream() // .filter(projectRelease -> predicate.test(projectRelease) && projectRelease.isCurrent()) // .findFirst();/*w w w .j a v a2 s. c om*/ if (first.isPresent()) { return first; } return projectReleases // .stream() // .filter(projectRelease -> predicate.test(projectRelease)) // .findFirst(); }
From source file:org.jephyr.easyflow.instrument.AnalyzingMethodRefPredicateTest.java
@Test(expectedExceptions = IllegalArgumentException.class) public void testApplyNonExistentMethod() throws Exception { Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(getClass()), TRUE_PREDICATE); predicate.test(new MethodRef("nonExistentMethod", "()V")); }
From source file:org.pgptool.gui.decryptedlist.impl.MonitoringDecryptedFilesServiceImpl.java
@Override public DecryptedFile findByEncryptedFile(String encryptedFile, Predicate<DecryptedFile> filter) { return getDecryptedFiles().stream() .filter(x -> x.getEncryptedFile().equals(encryptedFile) && filter.test(x)).findFirst().orElse(null); }
From source file:org.jephyr.easyflow.instrument.AnalyzingMethodRefPredicateTest.java
@Test public void testApplyMethodWithoutCalls() throws Exception { class C {/*from w w w . j a va 2 s. co m*/ void m() { } } Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class), TRUE_PREDICATE); assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m")))); }