java.util.function.BiPredicate Java Examples
The following examples show how to use
java.util.function.BiPredicate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OOITBuilder.java From jolie with GNU Lesser General Public License v2.1 | 6 votes |
public void visit( CompareConditionNode n ) { n.leftExpression().accept( this ); Expression left = currExpression; n.rightExpression().accept( this ); Scanner.TokenType opType = n.opType(); final BiPredicate< Value, Value > operator = opType == Scanner.TokenType.EQUAL ? CompareOperators.EQUAL : opType == Scanner.TokenType.NOT_EQUAL ? CompareOperators.NOT_EQUAL : opType == Scanner.TokenType.LANGLE ? CompareOperators.MINOR : opType == Scanner.TokenType.RANGLE ? CompareOperators.MAJOR : opType == Scanner.TokenType.MINOR_OR_EQUAL ? CompareOperators.MINOR_OR_EQUAL : opType == Scanner.TokenType.MAJOR_OR_EQUAL ? CompareOperators.MAJOR_OR_EQUAL : null; Objects.requireNonNull( operator ); currExpression = new CompareCondition( left, currExpression, operator ); }
Example #2
Source File: CopyOnWriteAsyncContextMap.java From servicetalk with Apache License 2.0 | 6 votes |
@Nullable @Override public Key<?> forEach(final BiPredicate<Key<?>, Object> consumer) { if (!consumer.test(keyOne, valueOne)) { return keyOne; } if (!consumer.test(keyTwo, valueTwo)) { return keyTwo; } if (!consumer.test(keyThree, valueThree)) { return keyThree; } if (!consumer.test(keyFour, valueFour)) { return keyFour; } if (!consumer.test(keyFive, valueFive)) { return keyFive; } return consumer.test(keySix, valueSix) ? null : keySix; }
Example #3
Source File: AveragableTest.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Check if all fields are the same/similar after cloning; goes through all super class fields, too * relies {@link #specialEquals} map or Objects{@link #equals(Object)} */ private void testEqualityOfClone(Class<? extends Averagable> aClass, Averagable original, Averagable clone) { Class c = aClass; while (Averagable.class.isAssignableFrom(c)) { for (Field field : c.getDeclaredFields()) { field.setAccessible(true); try { Object originalField = field.get(original); Object clonedField = field.get(clone); if (!NULL_CHECK_EQUALS.test(originalField, clonedField)) { fail("Cloning field " + field + " failed: unexpected (non) null value " + originalField + "/" + clonedField); } if (originalField == null) { continue; } Class<?> ofc = originalField.getClass(); BiPredicate<Object, Object> equals = specialEquals.getOrDefault(ofc, Objects::equals); assertTrue("Cloning field " + field + " failed", equals.test(originalField, clonedField)); } catch (IllegalAccessException e) { // ignore } } c = c.getSuperclass(); } }
Example #4
Source File: HelpContentHolder.java From sailfish-core with Apache License 2.0 | 6 votes |
private Optional<TreeNode> findNode(List<TreeNode> root, boolean recursive, BiPredicate<TreeNode, HelpJsonContainer> filter) { for (TreeNode node : ObjectUtils.defaultIfNull(root, Collections.<TreeNode>emptyList())) { HelpJsonContainer data = getContainer(node); if (data == null) { continue; } if (filter.test(node, data)) { return Optional.of(node); } if (recursive && CollectionUtils.isNotEmpty(node.getChildren())) { Optional<TreeNode> treeNode = findNode(node.getChildren(), true, filter); if (treeNode.isPresent()) { return treeNode; } } } return Optional.empty(); }
Example #5
Source File: LocalAppEngineServerBehaviour.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** * Starts the development server. * * @param mode the launch mode (see ILaunchManager.*_MODE constants) */ void startDevServer(String mode, RunConfiguration devServerRunConfiguration, Path javaHomePath, MessageConsoleStream outputStream, MessageConsoleStream errorStream) throws CoreException, CloudSdkNotFoundException { BiPredicate<InetAddress, Integer> portInUse = (addr, port) -> { Preconditions.checkArgument(port >= 0, "invalid port"); return SocketUtil.isPortInUse(addr, port); }; checkPorts(devServerRunConfiguration, portInUse); setServerState(IServer.STATE_STARTING); setMode(mode); // Create dev app server instance initializeDevServer(outputStream, errorStream, javaHomePath); // Run server try { devServer.run(devServerRunConfiguration); } catch (AppEngineException ex) { Activator.logError("Error starting server: " + ex.getMessage()); //$NON-NLS-1$ stop(true); } }
Example #6
Source File: FluxJoin.java From reactor-core with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") JoinSubscription(CoreSubscriber<? super R> actual, Function<? super TLeft, ? extends Publisher<TLeftEnd>> leftEnd, Function<? super TRight, ? extends Publisher<TRightEnd>> rightEnd, BiFunction<? super TLeft, ? super TRight, ? extends R> resultSelector) { this.actual = actual; this.cancellations = Disposables.composite(); this.queue = Queues.unboundedMultiproducer().get(); this.queueBiOffer = (BiPredicate) queue; this.lefts = new LinkedHashMap<>(); this.rights = new LinkedHashMap<>(); this.leftEnd = leftEnd; this.rightEnd = rightEnd; this.resultSelector = resultSelector; ACTIVE.lazySet(this, 2); }
Example #7
Source File: KafkaStream.java From arcusplatform with Apache License 2.0 | 6 votes |
public KafkaStream<K, V> whileMatches(BiPredicate<? super K, ? super V> predicate) { BiPredicate<? super K, ? super V> keepGoing; if(this.keepGoing.isPresent()) { final BiPredicate<? super K, ? super V> delegate = this.keepGoing.get(); keepGoing = (k, v) -> delegate.test(k, v) && predicate.test(k, v); } else { keepGoing = predicate; } return new KafkaStream<K, V>( config, keyDeserializer, valueDeserializer, Optional.of(keepGoing), filter ); }
Example #8
Source File: EqualsHelperTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testEqualsCustom () { final MutableBoolean aPredCalled = new MutableBoolean (false); final BiPredicate <String, String> aPredicate = (x, y) -> { aPredCalled.set (true); return true; }; assertTrue (EqualsHelper.equalsCustom (null, null, aPredicate)); assertFalse (aPredCalled.booleanValue ()); assertFalse (EqualsHelper.equalsCustom ("a", null, aPredicate)); assertFalse (aPredCalled.booleanValue ()); assertFalse (EqualsHelper.equalsCustom (null, "a", aPredicate)); assertFalse (aPredCalled.booleanValue ()); // Predicate is only called here assertTrue (EqualsHelper.equalsCustom ("b", "a", aPredicate)); assertTrue (aPredCalled.booleanValue ()); }
Example #9
Source File: CollectionUtils.java From fastjgame with Apache License 2.0 | 6 votes |
/** * 移除map中符合条件的元素,并对删除的元素执行后续的操作 * * @param map 必须是可修改的map * @param predicate 过滤条件,为真的删除 * @param then 元素删除之后执行的逻辑 * @param <K> the type of key * @param <V> the type of value * @return 删除的元素数量 */ public static <K, V> int removeIfAndThen(final Map<K, V> map, final BiPredicate<? super K, ? super V> predicate, BiConsumer<K, V> then) { if (map.size() == 0) { return 0; } int removeNum = 0; // entry在调用remove之后不可再访问,因此需要将key-value保存下来 Map.Entry<K, V> kvEntry; K k; V v; Iterator<Map.Entry<K, V>> itr = map.entrySet().iterator(); while (itr.hasNext()) { kvEntry = itr.next(); k = kvEntry.getKey(); v = kvEntry.getValue(); if (predicate.test(k, v)) { itr.remove(); removeNum++; then.accept(k, v); } } return removeNum; }
Example #10
Source File: QueryTest.java From mewbase with MIT License | 6 votes |
@Test(expected = NoSuchElementException.class) public void testNoSuchBinder() throws Exception { final BinderStore TEST_BINDER_STORE = BinderStore.instance(createConfig()); QueryManager mgr = QueryManager.instance(TEST_BINDER_STORE); final String NON_EXISTENT_BINDER = "Junk"; BiPredicate<BsonObject,KeyVal<String,BsonObject>> identity = (ctx, kv) -> true; mgr.queryBuilder(). named(TEST_QUERY_NAME). from(NON_EXISTENT_BINDER). filteredBy(identity). create(); }
Example #11
Source File: Types.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Form the union of two closures */ public List<Type> union(List<Type> cl1, List<Type> cl2, BiPredicate<Type, Type> shouldSkip) { if (cl1.isEmpty()) { return cl2; } else if (cl2.isEmpty()) { return cl1; } else if (shouldSkip.test(cl1.head, cl2.head)) { return union(cl1.tail, cl2.tail, shouldSkip).prepend(cl1.head); } else if (cl1.head.tsym.precedes(cl2.head.tsym, this)) { return union(cl1.tail, cl2, shouldSkip).prepend(cl1.head); } else if (cl2.head.tsym.precedes(cl1.head.tsym, this)) { return union(cl1, cl2.tail, shouldSkip).prepend(cl2.head); } else { // unrelated types return union(cl1.tail, cl2, shouldSkip).prepend(cl1.head); } }
Example #12
Source File: AnnotationsScanner.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private static <C, R> R processMethod(C context, Method source, SearchStrategy searchStrategy, AnnotationsProcessor<C, R> processor, @Nullable BiPredicate<C, Class<?>> classFilter) { switch (searchStrategy) { case DIRECT: case INHERITED_ANNOTATIONS: return processMethodInheritedAnnotations(context, source, processor, classFilter); case SUPERCLASS: return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(), processor, classFilter, source, false); case EXHAUSTIVE: return processMethodHierarchy(context, new int[] {0}, source.getDeclaringClass(), processor, classFilter, source, true); } throw new IllegalStateException("Unsupported search strategy " + searchStrategy); }
Example #13
Source File: JSList.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
public JSList(List srcmodel, Function<T, String> mapper, Function<String, T> onAdd, BiPredicate<String, String> predicate) { this.onAdd = onAdd; this.mapper = mapper; fltrmodel = new FilterModel(srcmodel, mapper, predicate); setLayout(new java.awt.BorderLayout()); topBar = new TopBar(fltrmodel::doFilter); add(topBar, java.awt.BorderLayout.NORTH); listPanel = new ListPanel(fltrmodel, mapper); add(listPanel, java.awt.BorderLayout.CENTER); setSize(300, 380); }
Example #14
Source File: MonoSequenceEqual.java From reactor-core with Apache License 2.0 | 5 votes |
EqualCoordinator(CoreSubscriber<? super Boolean> actual, int prefetch, Publisher<? extends T> first, Publisher<? extends T> second, BiPredicate<? super T, ? super T> comparer) { this.actual = actual; this.first = first; this.second = second; this.comparer = comparer; firstSubscriber = new EqualSubscriber<>(this, prefetch); secondSubscriber = new EqualSubscriber<>(this, prefetch); }
Example #15
Source File: ContentPreviewerFactoryBuilder.java From armeria with Apache License 2.0 | 5 votes |
/** * Sets the specified {@link BiPredicate} to produce the text preview when the predicate * returns {@code true}. */ public ContentPreviewerFactoryBuilder text( BiPredicate<? super RequestContext, ? super HttpHeaders> predicate) { requireNonNull(predicate, "predicate"); previewSpecsBuilder.add(new PreviewSpec(predicate, PreviewMode.TEXT, null)); return this; }
Example #16
Source File: SMap.java From jane with GNU Lesser General Public License v3.0 | 5 votes |
public boolean foreachFilter(BiPredicate<K, V> filter, Predicate<S> consumer) { for (Entry<K, V> entry : _map.entrySet()) { K k = entry.getKey(); V v = entry.getValue(); if (filter.test(k, v) && !consumer.test(safe(k, v))) return false; } return true; }
Example #17
Source File: Types.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Collect types into a new closure (using a @code{ClosureHolder}) */ public Collector<Type, ClosureHolder, List<Type>> closureCollector(boolean minClosure, BiPredicate<Type, Type> shouldSkip) { return Collector.of(() -> new ClosureHolder(minClosure, shouldSkip), ClosureHolder::add, ClosureHolder::merge, ClosureHolder::closure); }
Example #18
Source File: DeepEquals.java From aggregate-persistence with Apache License 2.0 | 5 votes |
private BiPredicate<DualObject, RecursiveObject> getCompareFunction(DualObject dualObject) { if (dualObject.shouldUseEqualMethod()) { return this::compareByEquals; } else if (dualObject.isContainer()) { return this::compareContainer; } else if (shouldUseCustomEquals(dualObject)) { return this::compareByCustomEquals; } else if (shouldUseComparator(dualObject)) { return this::compareByComparator; } return null; }
Example #19
Source File: UncheckedTest.java From Strata with Apache License 2.0 | 5 votes |
@Test public void test_biPredicate_fail2() { BiPredicate<String, String> a = Unchecked.biPredicate((t, u) -> { throw new Exception(); }); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> a.test("A", "B")); }
Example #20
Source File: FluxDistinctFuseable.java From reactor-core with Apache License 2.0 | 5 votes |
FluxDistinctFuseable(Flux<? extends T> source, Function<? super T, ? extends K> keyExtractor, Supplier<C> collectionSupplier, BiPredicate<C, K> distinctPredicate, Consumer<C> cleanupCallback) { super(source); this.keyExtractor = Objects.requireNonNull(keyExtractor, "keyExtractor"); this.collectionSupplier = Objects.requireNonNull(collectionSupplier, "collectionSupplier"); this.distinctPredicate = Objects.requireNonNull(distinctPredicate, "distinctPredicate"); this.cleanupCallback = Objects.requireNonNull(cleanupCallback, "cleanupCallback"); }
Example #21
Source File: Files.java From mojito with Apache License 2.0 | 5 votes |
public static Stream<Path> find(Path start, int maxDepth, BiPredicate<Path, BasicFileAttributes> matcher, FileVisitOption... options) { try { return java.nio.file.Files.find(start, maxDepth, matcher, options); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #22
Source File: MapNodes.java From bifurcan with MIT License | 5 votes |
@Override public INode<K, V> remove(int shift, Object editor, int hash, K key, BiPredicate<K, K> equals) { if (hash != this.hash) { return this; } else { int idx = indexOf(key, equals); return idx < 0 ? this : new Collision<K, V>(hash, ArrayVector.remove(entries, idx, 2)); } }
Example #23
Source File: TuplesRecommendationFormat.java From RankSys with Mozilla Public License 2.0 | 5 votes |
private static <T> Stream<List<T>> groupAdjacent(Stream<T> tuples, BiPredicate<T, T> adjacent) { return StreamSupport.stream(spliteratorUnknownSize(new Iterator<List<T>>() { private final Iterator<T> it = tuples.iterator(); private List<T> nextList = new ArrayList<>(); @Override public boolean hasNext() { return !nextList.isEmpty() || it.hasNext(); } @Override public List<T> next() { List<T> list = nextList; nextList = new ArrayList<>(); if (it.hasNext()) { T t = it.next(); boolean adj = list.isEmpty() || adjacent.test(t, list.get(0)); while (adj && it.hasNext()) { list.add(t); t = it.next(); adj = adjacent.test(t, list.get(0)); } if (adj) { list.add(t); return list; } else { nextList.add(t); return list; } } else { return list; } } }, ORDERED), false); }
Example #24
Source File: IdempotentAsyncResponseHandler.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private IdempotentAsyncResponseHandler(TransformingAsyncResponseHandler<T> wrappedHandler, Supplier<R> newScopeSupplier, BiPredicate<R, R> newScopeInRangePredicate) { this.newScopeSupplier = newScopeSupplier; this.newScopeInRangePredicate = newScopeInRangePredicate; this.wrappedHandler = wrappedHandler; }
Example #25
Source File: PickOneAllIntegerTypesVolatile.java From paintera with GNU General Public License v2.0 | 5 votes |
public PickOneAllIntegerTypesVolatile(final Predicate<M> pickThird, final BiPredicate<M, M> pickSecond, final VI i) { super(); this.pickThird = pickThird; this.pickSecond = pickSecond; this.i = i; }
Example #26
Source File: EventEmitterTransformer.java From titus-control-plane with Apache License 2.0 | 5 votes |
EventEmitterTransformer( Function<T, K> keyFun, BiPredicate<T, T> valueComparator, Function<T, E> valueAddedEventMapper, Function<T, E> valueRemovedEventMapper, E snapshotEndEvent) { this.keyFun = keyFun; this.valueComparator = valueComparator; this.valueAddedEventMapper = valueAddedEventMapper; this.valueRemovedEventMapper = valueRemovedEventMapper; this.snapshotEndEvent = snapshotEndEvent; }
Example #27
Source File: NukerLegitHack.java From Wurst7 with GNU General Public License v3.0 | 5 votes |
private Mode(String name, Function<NukerHack, String> renderName, BiPredicate<NukerHack, BlockPos> validator) { this.name = name; this.renderName = renderName; this.validator = validator; }
Example #28
Source File: SerializedLambdaTest.java From hottub with GNU General Public License v2.0 | 5 votes |
public void testUnboundMR() throws IOException, ClassNotFoundException { class Moo { public boolean startsWithB(String s) { return s.startsWith("b"); } } @SuppressWarnings("unchecked") BiPredicate<Moo, String> mh1 = (BiPredicate<Moo, String> & Serializable) Moo::startsWithB; Consumer<BiPredicate<Moo, String>> b = p -> { assertTrue(p instanceof Serializable); assertTrue(p.test(new Moo(), "barf")); assertFalse(p.test(new Moo(), "arf")); }; assertSerial(mh1, b); }
Example #29
Source File: P46.java From 99-problems with MIT License | 5 votes |
public static String table(BiPredicate<Boolean, Boolean> f) { List<String> resultBuilder = new ArrayList<>(); resultBuilder.add("A B result"); for (boolean a : Arrays.asList(true, false)) { for (boolean b : Arrays.asList(true, false)) { resultBuilder.add(String.format("%-10s %-10s %s", a, b, f.test(a, b))); } } return resultBuilder.stream().collect(Collectors.joining("\n")); }
Example #30
Source File: ReactorExt.java From titus-control-plane with Apache License 2.0 | 5 votes |
/** * An operator that converts collection of value into an event stream. Subsequent collection versions * are compared against each other and add/remove events are emitted accordingly. */ public static <K, T, E> Function<Flux<List<T>>, Publisher<E>> eventEmitter( Function<T, K> keyFun, BiPredicate<T, T> valueComparator, Function<T, E> valueAddedEventMapper, Function<T, E> valueRemovedEventMapper, E snapshotEndEvent) { return new EventEmitterTransformer<>(keyFun, valueComparator, valueAddedEventMapper, valueRemovedEventMapper, snapshotEndEvent); }