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:onl.area51.httpd.action.Action.java

default Action filter(Predicate<Request> p) {
    return p == null ? this : r -> {
        if (p.test(r)) {
            apply(r);// w w  w  . j a v a2 s  . c om
        }
    };
}

From source file:de.vandermeer.skb.commons.Test_Predicates.java

@Test
public void testContainsStringsStartingWith() {
    Set<String> set = new HashSet<String>();
    set.add("/");
    set.add("/a");
    set.add("/a/b");
    set.add("/a/b/c");
    set.add("/a/b/c/d");
    set.add("/a/b/c/e");
    set.add("/a/b/y");
    set.add("/a/b/y/w");
    set.add("/a/b/y/z");

    Predicate<StrBuilder> containsString = Predicates.CONTAINS_STRINGS_STARTING_WITH(set);

    assertTrue(containsString.test(new StrBuilder("/")));
    assertTrue(containsString.test(new StrBuilder("/a")));
    assertTrue(containsString.test(new StrBuilder("/a/b")));

    assertTrue(containsString.test(new StrBuilder("/a/b/c")));
    assertFalse(containsString.test(new StrBuilder("/a/b/c/d")));
    assertFalse(containsString.test(new StrBuilder("/a/b/c/e")));

    assertTrue(containsString.test(new StrBuilder("/a/b/y")));
    assertFalse(containsString.test(new StrBuilder("/a/b/y/w")));
    assertFalse(containsString.test(new StrBuilder("/a/b/y/z")));
}

From source file:fr.landel.utils.assertor.utils.AssertorMap.java

private static <M extends Map<K, V>, K, V, T> boolean contains(final M map, final Iterable<T> objects,
        final Predicate<T> predicate, final boolean all, final boolean not,
        final EnumAnalysisMode analysisMode) {

    long found = 0;

    if (EnumAnalysisMode.STANDARD.equals(analysisMode)) {
        for (T object : objects) {
            if (predicate.test(object)) {
                ++found;//w  w w . ja  v  a2s  .  c o  m
            }
        }
    } else {
        found = StreamSupport.stream(objects.spliterator(), EnumAnalysisMode.PARALLEL.equals(analysisMode))
                .filter(predicate).count();
    }

    return HelperAssertor.isValid(all, not, found, IterableUtils.size(objects));
}

From source file:jef.tools.ArrayUtils.java

/**
 * ???List/*from www . j  av  a 2 s. c  om*/
 * 
 * @param <T>
 * @param list
 * @param filter
 * @return
 */
public static <T> List<T> doSelect(Iterable<T> list, Predicate<T> filter) {
    ArrayList<T> result = new ArrayList<T>();
    for (T o : list) {
        if (filter.test(o)) {
            result.add(o);
        }
    }
    return result;
}

From source file:uk.gov.gchq.koryphe.impl.predicate.Or.java

@Override
public boolean test(final I input) {
    for (final Predicate<I> predicate : components) {
        try {/*from ww  w. j  a va  2  s.c o  m*/
            if (predicate.test(input)) {
                return true;
            }
        } catch (final ClassCastException e) {
            // This may occur if the predicate was given a tuple1 and the tuple1 was automatically unpacked.
            if (predicate instanceof TupleAdaptedPredicate && !(input instanceof Tuple)) {
                if (((TupleAdaptedPredicate) predicate).getPredicate().test(input)) {
                    return true;
                }
            } else {
                throw e;
            }
        }
    }
    return false;
}

From source file:org.jbpm.workbench.pr.client.editors.instance.list.ProcessInstanceListPresenterTest.java

protected static void testProcessInstanceStatusCondition(Predicate<ProcessInstanceSummary> predicate,
        Integer... validStatutes) {
    List<Integer> allStatus = Lists.newArrayList(ProcessInstance.STATE_ABORTED, ProcessInstance.STATE_ACTIVE,
            ProcessInstance.STATE_COMPLETED, ProcessInstance.STATE_PENDING, ProcessInstance.STATE_SUSPENDED);
    final List<Integer> validStatuses = asList(validStatutes);
    allStatus.removeAll(validStatuses);//  w  w  w .  j a  v  a  2  s  .  co  m

    allStatus.forEach(s -> assertFalse(predicate.test(createProcessInstanceSummary(1l, s))));
    validStatuses.forEach(s -> assertTrue(predicate.test(createProcessInstanceSummary(1l, s))));
}

From source file:org.jactr.io.resolver.ASTResolver.java

/**
 * return a list of all the commonTrees for this chunktype and its parents
 * sorted in dependency order, with chunkType's commonTree last
 * //from   w  w  w. ja va  2  s  .  c  o m
 * @param chunkType
 * @return
 */
@SuppressWarnings("unchecked")
static protected List<CommonTree> toOrderedAST(IChunkType chunkType, Set<IChunkType> alreadyConverted,
        Predicate<IChunkType> chunkTypeFilter, Predicate<IChunk> chunkFilter) {
    if (alreadyConverted.contains(chunkType)) {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Already converted " + chunkType);
        return Collections.EMPTY_LIST;
    }

    ArrayList<CommonTree> rtn = new ArrayList<CommonTree>();
    Collection<IChunkType> parents = chunkType.getSymbolicChunkType().getParents();
    // if (parent != null)
    for (IChunkType parent : parents)
        if (chunkTypeFilter.test(parent)) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("resolving parent " + parent);
            rtn.addAll(toOrderedAST(parent, alreadyConverted, chunkTypeFilter, chunkFilter));
        }

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Resolving " + chunkType);
    alreadyConverted.add(chunkType);

    if (chunkTypeFilter.test(chunkType))
        rtn.add(toAST(chunkType, chunkFilter));
    return rtn;
}

From source file:org.pentaho.database.service.ServiceLoaderDatabaseDialectProviderTest.java

@Test
public void testUsableFilterNoLog() {
    Log log = mock(Log.class);
    when(log.isDebugEnabled()).thenReturn(false);
    AbstractDatabaseDialect dialect = mock(AbstractDatabaseDialect.class);
    IDatabaseDialect iDatabaseDialect = mock(IDatabaseDialect.class);
    when(iDatabaseDialect.getNativeDriver()).thenReturn(Object.class.getCanonicalName())
            .thenReturn("fake.class");
    when(dialect.isUsable()).thenReturn(true).thenReturn(false);
    Predicate<IDatabaseDialect> filter = dialectProvider.usableFilter(log);
    assertTrue(filter.test(dialect));
    assertFalse(filter.test(dialect));/*from  ww  w  .  j  a  v a2s  .com*/
    assertTrue(filter.test(iDatabaseDialect));
    assertFalse(filter.test(iDatabaseDialect));
    verify(log, never()).debug(anyString());
}

From source file:ai.grakn.test.EngineTestBase.java

protected void waitForScheduler(ClusterManager clusterManager, Predicate<Scheduler> fn) throws Exception {
    int runs = 0;

    while (!fn.test(clusterManager.getScheduler()) && runs < 50) {
        Thread.sleep(100);// ww w  . j a va2 s .  co  m
        runs++;
    }

    System.out.println(
            "wait done, runs " + Integer.toString(runs) + " scheduler " + clusterManager.getScheduler());
}

From source file:org.pentaho.database.service.ServiceLoaderDatabaseDialectProviderTest.java

@Test
public void testUsableFilterLog() {
    Log log = mock(Log.class);
    when(log.isDebugEnabled()).thenReturn(true);
    AbstractDatabaseDialect dialect = mock(AbstractDatabaseDialect.class);
    IDatabaseType type = mock(IDatabaseType.class);
    IDatabaseDialect iDatabaseDialect = mock(IDatabaseDialect.class);
    when(iDatabaseDialect.getNativeDriver()).thenReturn(Object.class.getCanonicalName());
    when(iDatabaseDialect.getDatabaseType()).thenReturn(type);
    when(dialect.getDatabaseType()).thenReturn(type);
    when(dialect.isUsable()).thenReturn(true).thenReturn(false);
    Predicate<IDatabaseDialect> filter = dialectProvider.usableFilter(log);
    assertTrue(filter.test(dialect));
    verify(log, times(1)).debug(anyString());
    assertFalse(filter.test(dialect));//from  w ww  .j a v a2 s. c  o  m
    verify(log, times(3)).debug(anyString());
    assertTrue(filter.test(iDatabaseDialect));
    verify(log, times(4)).debug(anyString());
    iDatabaseDialect = mock(IDatabaseDialect.class);
    when(iDatabaseDialect.getNativeDriver()).thenReturn("fake.class");
    when(iDatabaseDialect.getDatabaseType()).thenReturn(type);
    assertFalse(filter.test(iDatabaseDialect));
    verify(log, times(6)).debug(anyString());
}