List of usage examples for java.util.function Predicate test
boolean test(T t);
From source file:org.talend.dataprep.filter.ObjectPredicateVisitor.java
@Override public Predicate<Object> visit(NotExpression notExpression) { final Predicate<Object> accept = (Predicate<Object>) notExpression.getExpression().accept(this); return m -> !accept.test(m); }
From source file:org.sonar.server.util.ClassLoaderUtils.java
/** * Finds directories and files within a given directory and its subdirectories. * * @param classLoader/*from www . java2 s . co m*/ * @param rootPath the root directory, for example org/sonar/sqale, or a file in this root directory, for example org/sonar/sqale/index.txt * @param predicate * @return a list of relative paths, for example {"org/sonar/sqale", "org/sonar/sqale/foo", "org/sonar/sqale/foo/bar.txt}. Never null. */ public static Collection<String> listResources(ClassLoader classLoader, String rootPath, Predicate<String> predicate) { String jarPath = null; JarFile jar = null; try { Collection<String> paths = Lists.newArrayList(); URL root = classLoader.getResource(rootPath); if (root != null) { checkJarFile(root); // Path of the root directory // Examples : // org/sonar/sqale/index.txt -> rootDirectory is org/sonar/sqale // org/sonar/sqale/ -> rootDirectory is org/sonar/sqale // org/sonar/sqale -> rootDirectory is org/sonar/sqale String rootDirectory = rootPath; if (StringUtils.substringAfterLast(rootPath, "/").indexOf('.') >= 0) { rootDirectory = StringUtils.substringBeforeLast(rootPath, "/"); } // strip out only the JAR file jarPath = root.getPath().substring(5, root.getPath().indexOf('!')); jar = new JarFile(URLDecoder.decode(jarPath, CharEncoding.UTF_8)); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.startsWith(rootDirectory) && predicate.test(name)) { paths.add(name); } } } return paths; } catch (Exception e) { throw Throwables.propagate(e); } finally { closeJar(jar, jarPath); } }
From source file:org.gradle.tooling.internal.provider.runner.PluginApplicationTracker.java
public boolean hasRunningPluginApplication(OperationIdentifier id, Predicate<? super PluginApplication> predicate) { return parentTracker.findClosestMatchingAncestor(id, parent -> { PluginApplication pluginApplication = runningPluginApplications.get(parent); return pluginApplication != null && predicate.test(pluginApplication); }) != null;//from w w w . j a v a2 s . com }
From source file:org.fenixedu.academic.ui.struts.action.teacher.SearchExecutionCourseLogAction.java
private void searchLogs(SearchExecutionCourseLogBean bean) { final Predicate<ExecutionCourseLog> filter = bean.getFilters(); final Collection<ExecutionCourseLog> validLogs = new HashSet<ExecutionCourseLog>(); for (final ExecutionCourseLog log : bean.getExecutionCourse().getExecutionCourseLogsSet()) { if (filter.test(log)) { validLogs.add(log);//www .j av a 2 s .c o m } } bean.setExecutionCourseLogs(validLogs); }
From source file:net.udidb.engine.ops.impls.help.HelpMessageProvider.java
private void getAllShortMessages(StringBuilder builder, Predicate<Map.Entry<String, HelpMessageDescriptor>> predicate) { boolean first = true; for (Map.Entry<String, HelpMessageDescriptor> entry : helpMessageDescriptors.entrySet()) { if (!predicate.test(entry)) { continue; }//from ww w . ja va2 s .c o m if (!first) { builder.append(NEWLINE); } else { first = false; } builder.append(entry.getKey()).append(" -- ").append(entry.getValue().shortMessage); } }
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.EmbeddingMetaData.java
/** * Returns the variables that fulfil the specified predicate. The variables are ordered by * their appearance in the entry mapping. * * @param predicate predicate for entry types * @return variables that fulfil the predicate *//*from w w w . j ava2 s . c o m*/ private List<String> getVariables(Predicate<EntryType> predicate) { return entryMapping.entrySet().stream().filter(entry -> predicate.test(entry.getKey().getRight())) .sorted(Comparator.comparingInt(Map.Entry::getValue)).map(entry -> entry.getKey().getLeft()) .collect(Collectors.toList()); }
From source file:de.vandermeer.skb.interfaces.transformers.ClusterElementTransformer.java
/** * Converts the input `iterable` to a collection applying a predicate and a transformation for each input element. * @param <T1> the from/source of the transformer (also the type for `iterable`) * @param <T2> the to/target of the transformer and the type of objects in the return collection * @param <T3> any type that extends T1 to no limit conversion to a single type * @param <S> the type of collection that should be returned * @param input `iterable` of input elements * @param transformer a transformer to apply for each input element before copying to the output * @param predicate a predicate to apply before transformation and copy of each input element (ignored if null) * @param strategy a strategy determining the type of output collection * @return an empty collection of type T2 or a collection of type T2 with transformed objects from the input collection * @throws NullPointerException if `input`, `transformer`, or `strategy` was null *///from w ww . j a v a2 s . c o m default <T1, T2, T3 extends T1, S extends Collection<T2>> S transform(Iterable<T3> input, Transformer<T1, T2> transformer, Predicate<T3> predicate, IsCollectionStrategy<S, T2> strategy) { Validate.notNull(input); Validate.notNull(transformer); Validate.notNull(strategy); S ret = strategy.get(); for (T3 t3 : input) { if (predicate != null && predicate.test(t3)) { ret.add(transformer.transform(t3)); } else if (predicate == null) { ret.add(transformer.transform(t3)); } } return ret; }
From source file:de.vandermeer.skb.interfaces.transformers.ClusterElementTransformer.java
/** * Converts the input `array` to a collection applying a predicate and a transformation for each input element. * @param <T1> the from/source of the transformer (also the type for the `array`) * @param <T2> the to/target of the transformer and the type of objects in the return collection * @param <T3> any type that extends T1 to no limit conversion to a single type * @param <S> the type of collection that should be returned * @param input `array` of input elements * @param transformer a transformer to apply for each input element before copying to the output * @param predicate a predicate to apply before transformation and copy of each input element (ignored if null) * @param strategy a strategy determining the type of output collection * @return an empty collection of type T2 or a collection of type T2 with transformed objects from the input collection * @throws NullPointerException if `input`, `transformer`, or `strategy` was null *//*from w w w . j av a 2 s. c o m*/ default <T1, T2, T3 extends T1, S extends Collection<T2>> S transform(T3[] input, Transformer<T1, T2> transformer, Predicate<T3> predicate, IsCollectionStrategy<S, T2> strategy) { Validate.notNull(input); Validate.notNull(transformer); Validate.notNull(strategy); S ret = strategy.get(); for (T3 t3 : input) { if (predicate != null && predicate.test(t3)) { ret.add(transformer.transform(t3)); } else if (predicate == null) { ret.add(transformer.transform(t3)); } } return ret; }
From source file:org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport.java
/** * Evaluate the {@code Predicate} on the method parameter type or on * the generic type within a reactive type wrapper. *///from w ww. j a v a 2s .c om protected boolean checkParameterType(MethodParameter parameter, Predicate<Class<?>> predicate) { Class<?> type = parameter.getParameterType(); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(type); if (adapter != null) { assertHasValues(adapter, parameter); type = parameter.nested().getNestedParameterType(); } return predicate.test(type); }
From source file:org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport.java
/** * Evaluate the {@code Predicate} on the method parameter type but raise an * {@code IllegalStateException} if the same matches the generic type * within a reactive type wrapper.//from ww w. j a v a2 s .c o m */ protected boolean checkParameterTypeNoReactiveWrapper(MethodParameter parameter, Predicate<Class<?>> predicate) { Class<?> type = parameter.getParameterType(); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(type); if (adapter != null) { assertHasValues(adapter, parameter); type = parameter.nested().getNestedParameterType(); } if (predicate.test(type)) { if (adapter == null) { return true; } throw buildReactiveWrapperException(parameter); } return false; }