Example usage for java.util.function Predicate test

List of usage examples for java.util.function Predicate test

Introduction

In this page you can find the example usage for java.util.function Predicate test.

Prototype

boolean test(T t);

Source Link

Document

Evaluates this predicate on the given argument.

Usage

From source file:com.meltmedia.dropwizard.etcd.json.EtcdDirectoryDao.java

/**
 * Updates the value of key, using the specified transform, if its current value matches predicate.
 * //from   w  w w.jav a  2  s .  c  om
 * @param key
 * @param precondition
 * @param transform
 * @return
 */
public Long update(String key, Predicate<T> precondition, Function<T, T> transform) {
    T currentValue = get(key);
    if (!precondition.test(currentValue)) {
        throw new EtcdDirectoryException(String.format("precondition failed while updating %s", key));
    }
    T nextValue = transform.apply(clone(currentValue));
    return put(key, nextValue, currentValue);
}

From source file:jef.tools.ArrayUtils.java

/**
 * //from   www  . j  a va2 s.com
 * 
 * @param source
 * @param filter
 * @return
 */
public static <T> List<T> filter(T[] source, Predicate<T> filter) {
    if (source == null)
        return Collections.emptyList();
    if (filter == null)
        return Arrays.asList(source);
    List<T> result = new ArrayList<T>(source.length);
    for (T t : source) {
        if (filter.test(t)) {
            result.add(t);
        }
    }
    return result;
}

From source file:org.jephyr.easyflow.instrument.AnalyzingMethodRefPredicateTest.java

@Test
public void testApplyParentPredicate() throws Exception {
    class C {/* ww w. j  a  va  2s.  c o  m*/

        void m() {
            m2();
        }

        void m2() {
        }
    }
    Predicate<MethodRef> predicate = new AnalyzingMethodRefPredicate(getBytes(C.class),
            t -> !t.getName().equals("m"));
    assertFalse(predicate.test(getMethodRef(C.class.getDeclaredMethod("m"))));
}

From source file:controller.PlayController.java

public List<Play> lambdaFilter(Predicate<Play> selector, List<Play> plays) {
    List<Play> list = plays.stream().filter(p -> selector.test(p)).collect(Collectors.toList());
    if (!list.isEmpty()) {
        return list;
    } else {/*from ww w . j  a v a 2  s. c o m*/
        return null;
    }
}

From source file:org.diorite.impl.PlayersManagerImpl.java

public void forEachExcept(final Player except, final Predicate<IPlayer> predicate,
        final Consumer<IPlayer> consumer) {
    //noinspection ObjectEquality
    this.players.values().stream().filter(p -> (p != except) && predicate.test(p)).forEach(consumer);
}

From source file:com.neatresults.mgnltweaks.app.status.ConfigStatusPresenter.java

private void filterData(NodeIterator iter, Predicate<Node> exists, Consumer<Node> total, Consumer<Node> fails)
        throws RepositoryException {
    while (iter.hasNext()) {
        Node n = iter.nextNode();
        total.accept(n);//from   w  w  w .  j  a  v a  2 s  .  co  m
        if (!exists.test(n)) {
            fails.accept(n);
        }
    }
}

From source file:org.apache.accumulo.core.conf.SiteConfiguration.java

public void getProperties(Map<String, String> props, Predicate<String> filter, boolean useDefaults) {
    if (useDefaults) {
        parent.getProperties(props, filter);
    }//from w  w w.j a  va  2  s .  c o  m
    config.keySet().forEach(k -> {
        if (filter.test(k))
            props.put(k, config.get(k));
    });
}

From source file:fr.landel.utils.commons.builder.EqualsBuilder2.java

/**
 * Append the super equals function.//from ww  w.  j  av a2  s  .c om
 * 
 * @param predicate
 *            the super predicate
 * @return the current builder
 */
public EqualsBuilder2<T> appendSuper(final Predicate<T> predicate) {
    if (this.isEqual) {
        this.builder.appendSuper(predicate.test(this.casted));
    }
    return this;
}

From source file:org.fenixedu.academic.ui.struts.action.coordinator.SearchDegreeLogAction.java

private void searchLogs(SearchDegreeLogBean bean) {
    final Predicate<DegreeLog> filter = bean.getFilters();
    final Collection<DegreeLog> validLogs = new HashSet<DegreeLog>();
    for (final DegreeLog log : bean.getDegree().getDegreeLogsSet()) {
        if (filter.test(log)) {
            validLogs.add(log);//from  w ww.  j  av  a  2 s . c om
        }
    }
    bean.setDegreeLogs(validLogs);
}

From source file:org.talend.dataprep.cache.file.FileSystemContentCache.java

private BiConsumer<Path, String> getEvictionConsumer(final Predicate<String> keyMatcher) {
    return (file, suffix) -> {
        try {//w ww  .j  a  va 2 s . co m
            if (keyMatcher.test(file.getFileName().toString())) {
                final Path evictedFile = Paths.get(file.toAbsolutePath().toString() + ".0");
                Files.move(file, evictedFile, REPLACE_EXISTING, ATOMIC_MOVE);
            }
        } catch (IOException e) {
            LOGGER.error("Unable to evict {}.", file.getFileName(), e);
        }
    };
}