List of usage examples for java.util.function BiPredicate test
boolean test(T t, U u);
From source file:fr.landel.utils.assertor.utils.AssertorMap.java
private static <M extends Map<K, V>, K, V, T> boolean hasInOrder(final M map, final Iterable<T> objects, final boolean not, final EnumAnalysisMode analysisMode, final BiPredicate<Entry<K, V>, T> entriesEqualChecker, final Class<T> objectsClass) { int found = 0; final int size1 = map.size(); final int size2 = IterableUtils.size(objects); if (size1 < size2) { return not; }/*from w w w. jav a 2 s. c om*/ final Set<Entry<K, V>> entries1 = map.entrySet(); final List<T> entries2 = IterableUtils.toList(objects); if (EnumAnalysisMode.STANDARD.equals(analysisMode)) { for (Entry<K, V> entry1 : entries1) { if (found < size2) { if (entriesEqualChecker.test(entry1, entries2.get(found))) { ++found; } else if (found > 0) { found = 0; } } } } else { final AtomicInteger count = new AtomicInteger(0); final Stream<Entry<K, V>> stream; if (EnumAnalysisMode.PARALLEL.equals(analysisMode)) { stream = entries1.parallelStream(); } else { stream = entries1.stream(); } stream.forEachOrdered(o -> { int inc = count.get(); if (inc < size2) { if (entriesEqualChecker.test(o, entries2.get(inc))) { count.incrementAndGet(); } else if (inc > 0) { count.set(0); } } }); found = count.get(); } return not ^ (found == size2); }
From source file:org.openhab.tools.analysis.checkstyle.BuildPropertiesCheck.java
/** * Checks if a property contains all expected values and logs messages if some of the expected values are missing * * @param propertyValue - the value of the property * @param expectedPropertyValues - expected values * @param strictSyntax - if set to true, the values should end with "/", otherwise they could end with */// www . j a v a 2s . c om private List<String> findMissingValues(IBuildEntry propertyValue, List<String> expectedPropertyValues, boolean strictSyntax, BiPredicate<List<String>, List<String>> condition) { List<String> values = Arrays.asList(propertyValue.getTokens()); if (!strictSyntax) { removeSubstringAtEnd(values, "/"); removeSubstringAtEnd(expectedPropertyValues, "/"); } if (expectedPropertyValues != null && values != null) { if (!condition.test(values, expectedPropertyValues)) { return removeAll(expectedPropertyValues, values); } } return Collections.emptyList(); }
From source file:com.intuit.wasabi.api.pagination.filters.PaginationFilter.java
/** * Gets a property from the object with the {@code propertyExtractor}. On failure (by NullPointerException) * {@code false} is returned./*from w ww . ja v a2 s . com*/ * <p> * If the property is {@code null}, {@code false} is returned. Otherwise the property is tested with the passed * {@code filterFunction} according to the passed filter value. * * @param object the object to be tested * @param filterValue the value to be tested with * @param propertyExtractor the property extractor * @param filterFunction the filter function * @param <V> the type of the object's property * @return false for failures and null-properties, otherwise the return value of the {@code filterFunction} */ /*test*/ final <V> boolean filterByProperty(T object, String filterValue, Function<T, V> propertyExtractor, BiPredicate<V, String> filterFunction) { V property; try { property = propertyExtractor.apply(object); } catch (NullPointerException ignored) { return false; } return property != null && filterFunction.test(property, filterValue); }
From source file:com.netflix.imfutility.conversion.SilentConversionChecker.java
private void checkParameter(ResourceContextParameters param, ConversionParameterNameType conversionParam, ContextInfo contextInfo, BiPredicate<String, String> equality) throws ConversionNotAllowedException { String destinationParamValue = getDestinationValue(conversionParam, param); if (destinationParamValue == null || destinationParamValue.isEmpty()) { return;//from ww w .j ava2s.c o m } if (contextProvider.getResourceContext().hasResourceParameter(param, contextInfo)) { String paramValue = contextProvider.getResourceContext().getParameterValue(param, contextInfo); if (!equality.test(paramValue, destinationParamValue)) { throw new ConversionNotAllowedException(param.getName(), paramValue, destinationParamValue, contextInfo.getSequenceUuid()); } } }
From source file:at.gridtec.lambda4j.predicate.bi.BiPredicate2.java
/** * Returns a composed {@link BiPredicate2} that represents a short-circuiting logical XOR of this predicate and * another. Any exceptions thrown during evaluation of either predicate is relayed to the caller; if evaluation of * this {@code BiPredicate2} throws an exception, the {@code other} predicate will not be evaluated. * * @param other A {@code BiPredicate2} that will be logically-XORed with this one * @return A composed {@code BiPredicate2} that represents the short-circuiting logical XOR of this predicate and * the {@code other} predicate./* w ww . j a v a 2 s . co m*/ * @throws NullPointerException If given argument is {@code null} * @see #and(BiPredicate) * @see #or(BiPredicate) */ @Nonnull default BiPredicate2<T, U> xor(@Nonnull final BiPredicate<? super T, ? super U> other) { Objects.requireNonNull(other); return (t, u) -> test(t, u) ^ other.test(t, u); }
From source file:at.gridtec.lambda4j.predicate.bi.BiPredicate2.java
/** * Returns a composed {@link BiPredicate2} that represents a short-circuiting logical AND of this predicate and * another. When evaluating the composed predicate, if this predicate is {@code false}, then the {@code other} * predicate is not evaluated.//from w ww .j a v a 2s . c om * <p> * Any exceptions thrown during evaluation of either predicate is relayed to the caller; if evaluation of this * {@code BiPredicate2} throws an exception, the {@code other} predicate will not be evaluated. * * @param other A {@code BiPredicate2} that will be logically-ANDed with this one * @return A composed {@code BiPredicate2} that represents the short-circuiting logical AND of this predicate and * the {@code other} predicate. * @throws NullPointerException If given argument is {@code null} * @see #or(BiPredicate) * @see #xor(BiPredicate) */ @Nonnull default BiPredicate2<T, U> and(@Nonnull final BiPredicate<? super T, ? super U> other) { Objects.requireNonNull(other); return (t, u) -> test(t, u) && other.test(t, u); }
From source file:at.gridtec.lambda4j.predicate.bi.BiPredicate2.java
/** * Returns a composed {@link BiPredicate2} that represents a short-circuiting logical OR of this predicate and * another. When evaluating the composed predicate, if this predicate is {@code true}, then the {@code other} * predicate is not evaluated.//from w w w. ja v a 2 s . co m * <p> * Any exceptions thrown during evaluation of either predicate is relayed to the caller; if evaluation of this * {@code BiPredicate2} throws an exception, the {@code other} predicate will not be evaluated. * * @param other A {@code BiPredicate2} that will be logically-ORed with this one * @return A composed {@code BiPredicate2} that represents the short-circuiting logical OR of this predicate and the * {@code other} predicate. * @throws NullPointerException If given argument is {@code null} * @see #and(BiPredicate) * @see #xor(BiPredicate) */ @Nonnull default BiPredicate2<T, U> or(@Nonnull final BiPredicate<? super T, ? super U> other) { Objects.requireNonNull(other); return (t, u) -> test(t, u) || other.test(t, u); }
From source file:org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport.java
/** * Evaluate the {@code Predicate} on the method parameter type if it has the * given annotation, nesting within {@link java.util.Optional} if necessary, * but raise an {@code IllegalStateException} if the same matches the generic * type within a reactive type wrapper.//w w w .j a v a2s . c o m */ protected <A extends Annotation> boolean checkAnnotatedParamNoReactiveWrapper(MethodParameter parameter, Class<A> annotationType, BiPredicate<A, Class<?>> typePredicate) { A annotation = parameter.getParameterAnnotation(annotationType); if (annotation == null) { return false; } parameter = parameter.nestedIfOptional(); Class<?> type = parameter.getNestedParameterType(); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(type); if (adapter != null) { assertHasValues(adapter, parameter); parameter = parameter.nested(); type = parameter.getNestedParameterType(); } if (typePredicate.test(annotation, type)) { if (adapter == null) { return true; } throw buildReactiveWrapperException(parameter); } return false; }
From source file:hudson.cli.DisablePluginCommandTest.java
/** * Helper method to check the output of a result with a specific method allowing two arguments ( * StringUtils::startsWith or StringUtils::contents). This method avoid to have it hardcoded the messages. We avoid * having to compose the descriptive text of the message by using a <i>stop</i> flag to ignore the last characters. * This method supposes that the descriptive text is at the last of the string. * @param result the result of the command. * @param method a method with two string arguments to check against * @param plugin the plugin printed outSetting the plugin and status as parameters, the method gets * the string printed using the/*from w w w . j av a 2 s. co m*/ * @param status the status printed out * @return true if the output has been checked against the method using the plugin and status args */ private boolean checkResultWith(CLICommandInvoker.Result result, BiPredicate<String, String> method, String plugin, PluginWrapper.PluginDisableStatus status) { String noMatterFollowingChars = "/!$stop"; String outExpected = Messages.DisablePluginCommand_StatusMessage(plugin, status, noMatterFollowingChars); outExpected = StringUtils.substringBefore(outExpected, noMatterFollowingChars); return method.test(result.stdout(), outExpected); }
From source file:org.briljantframework.array.AbstractArray.java
@Override public BooleanArray where(Array<T> other, BiPredicate<T, T> predicate) { Check.dimension(this, other); BooleanArray array = getArrayFactory().newBooleanArray(getShape()); for (int i = 0; i < size(); i++) { array.set(i, predicate.test(get(i), other.get(i))); }//from w w w .j a va 2 s .com return array; }