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:org.apache.hyracks.maven.license.GenerateFileMojo.java

private SortedMap<String, JarEntry> gatherMatchingEntries(JarFile jarFile, Predicate<JarEntry> filter) {
    SortedMap<String, JarEntry> matches = new TreeMap<>();
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        if (filter.test(entry)) {
            matches.put(entry.getName(), entry);
        }/*ww  w  .  ja v a2 s  .c o  m*/
    }
    return matches;
}

From source file:com.idrene.emefana.repositories.RepositoriesTest.java

void updateProvidersLambda(List<Provider> providers, Predicate<Provider> predicate,
        Consumer<Provider> setValues) {
    assertNotNull(providers);//from  w  w w  .  j  a va 2  s . c  o m
    assertTrue(providers.size() > 1);
    if (providers.stream().anyMatch(p -> predicate.test(p))) {
        providers.forEach(p -> setValues.accept(p));
        List<Provider> savedPvrs = providerRepository.save(providers);
        assertFalse(savedPvrs.stream().allMatch(predicate));
    }
}

From source file:org.eclipse.hono.service.http.AbstractHttpEndpoint.java

/**
 * Gets a response handler that implements the default behavior for responding to an HTTP request.
 * <p>//from  w ww  . j a  v a  2  s  .co  m
 * The default behavior is as follows:
 * <ol>
 * <li>Set the status code on the response.</li>
 * <li>If the status code represents an error condition (i.e. the code is &gt;= 400),
 * then the JSON object passed in to the returned handler is written to the response body.</li>
 * <li>Otherwise, if the given filter evaluates to {@code true} for the status code,
 * the JSON object is written to the response body and the given custom handler is
 * invoked (if not {@code null}).</li>
 * </ol>
 * 
 * @param ctx The routing context of the request.
 * @param successfulOutcomeFilter A predicate that evaluates to {@code true} for the status code(s) representing a
 *                           successful outcome.
 * @param customHandler An (optional) handler for post processing the HTTP response, e.g. to set any additional HTTP
 *                        headers. The handler <em>must not</em> write to response body. May be {@code null}.
 * @return The created handler for processing responses.
 * @throws NullPointerException If routing context or filter is {@code null}.
 */
protected final BiConsumer<Integer, JsonObject> getDefaultResponseHandler(final RoutingContext ctx,
        final Predicate<Integer> successfulOutcomeFilter, final Handler<HttpServerResponse> customHandler) {

    Objects.requireNonNull(successfulOutcomeFilter);
    final HttpServerResponse response = ctx.response();

    return (status, jsonResult) -> {
        response.setStatusCode(status);
        if (status >= 400) {
            HttpUtils.setResponseBody(response, jsonResult);
        } else if (successfulOutcomeFilter.test(status)) {
            HttpUtils.setResponseBody(response, jsonResult);
            if (customHandler != null) {
                customHandler.handle(response);
            }
        }
        response.end();
    };
}

From source file:org.elasticsearch.upgrades.RecoveryIT.java

private String getNodeId(Predicate<Version> versionPredicate) throws IOException {
    Response response = client().performRequest("GET", "_nodes");
    ObjectPath objectPath = ObjectPath.createFromResponse(response);
    Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
    for (String id : nodesAsMap.keySet()) {
        Version version = Version.fromString(objectPath.evaluate("nodes." + id + ".version"));
        if (versionPredicate.test(version)) {
            return id;
        }/* w  ww.  ja  v a 2  s. c om*/
    }
    return null;
}

From source file:at.gridtec.lambda4j.function.bi.obj.ObjBooleanFunction.java

/**
 * Returns a composed {@link BiFunction2} that first applies the {@code before} functions to its input, and
 * then applies this function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <A> The type of the argument to the first given function, and of composed function
 * @param <B> The type of the argument to the second given predicate, and of composed function
 * @param before1 The first function to apply before this function is applied
 * @param before2 The second predicate to apply before this function is applied
 * @return A composed {@code BiFunction2} that first applies the {@code before} functions to its input, and then
 * applies this function to the result.//from w  w w  .j  a va2  s . c om
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 */
@Nonnull
default <A, B> BiFunction2<A, B, R> compose(@Nonnull final Function<? super A, ? extends T> before1,
        @Nonnull final Predicate<? super B> before2) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    return (a, b) -> apply(before1.apply(a), before2.test(b));
}

From source file:at.gridtec.lambda4j.function.bi.BiBooleanFunction.java

/**
 * Returns a composed {@link BiFunction2} that first applies the {@code before} predicates to its input, and
 * then applies this function to the result.
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 *
 * @param <A> The type of the argument to the first given predicate, and of composed function
 * @param <B> The type of the argument to the second given predicate, and of composed function
 * @param before1 The first predicate to apply before this function is applied
 * @param before2 The second predicate to apply before this function is applied
 * @return A composed {@code BiFunction2} that first applies the {@code before} predicates to its input, and then
 * applies this function to the result./*from  w  ww  . j a  va2  s  .  c  o  m*/
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 */
@Nonnull
default <A, B> BiFunction2<A, B, R> compose(@Nonnull final Predicate<? super A> before1,
        @Nonnull final Predicate<? super B> before2) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    return (a, b) -> apply(before1.test(a), before2.test(b));
}

From source file:org.pentaho.metaverse.api.analyzer.kettle.step.SubtransAnalyzer.java

/**
 * Checks to see if the sub trans has any RowFromResult steps in it.
 * If so, it will link the original field node to the fields created in the RowFromResult step in the sub trans
 * @param originalFieldNode incoming stream field node to the TransExecutorStep
 * @param subTransMeta TransMeta of the transformation to be executed by the TransExecutor step
 * @param descriptor Descriptor to use as a basis
 * @param fieldPredicate predicate to determine if this is the sub field to link with
 * @param step StepMeta of the step in the subtrans to link to
 * @param rfrm RowsFromResultMeta of the step to link to
 * @param subTransStepNode IMetaverseNode representing the step in the subtrans to link to
 * @return true if a field matching the fieldPredicate was found in the subtrans, false otherwise
 *//* w  w w  .  j av  a 2s  .c om*/
private boolean linkUsedFieldToStepField(IMetaverseNode originalFieldNode, TransMeta subTransMeta,
        IComponentDescriptor descriptor, Predicate<String> fieldPredicate, StepMeta step,
        RowsFromResultMeta rfrm, IMetaverseNode subTransStepNode) {
    try {
        RowMetaInterface rowMetaInterface = rfrm.getParentStepMeta().getParentTransMeta().getStepFields(step);
        for (int i = 0; i < rowMetaInterface.getFieldNames().length; i++) {
            String field = rowMetaInterface.getFieldNames()[i];
            if (fieldPredicate.test(field)) {
                // Create the descriptor for the trans field that is derived from the incoming result field
                IComponentDescriptor stepFieldDescriptor = new MetaverseComponentDescriptor(field,
                        DictionaryConst.NODE_TYPE_TRANS_FIELD, subTransStepNode, descriptor.getContext());

                // Create the node
                IMetaverseNode subTransField = stepAnalyzer.createFieldNode(stepFieldDescriptor,
                        rowMetaInterface.getValueMeta(i), step.getName(), false);

                // Add the link
                stepAnalyzer.getMetaverseBuilder().addLink(originalFieldNode, DictionaryConst.LINK_DERIVES,
                        subTransField);

                // no need to keep looking for a match on field name, we just handled it.
                return true;
            }
        }
    } catch (KettleStepException e) {
        log.warn(Messages.getString("WARN.SubtransAnalyzer.RowsFromResultNotFound", subTransMeta.getName()), e);
    }
    return false;
}

From source file:fish.payara.maven.plugins.micro.StopMojo.java

private String getLineFromJpsOutput(final Runtime re, Predicate<String> linePredicate) throws IOException {
    String jpsPath = "jps";
    if (toolchain != null) {
        jpsPath = toolchain.findTool("jps");
    }/*from  w w w  . ja  v a 2 s  .  c om*/
    Process jpsProcess = re.exec(jpsPath + " -v");
    InputStream inputStream = jpsProcess.getInputStream();
    try (BufferedReader in = new BufferedReader(new InputStreamReader(inputStream))) {
        String line;
        while ((line = in.readLine()) != null) {
            if (linePredicate.test(line)) {
                return line;
            }
        }
        return null;
    }
}

From source file:org.starnub.starnubserver.connections.player.session.PlayerSession.java

private static void sendPacketToGroup(Packet packet, Predicate<PlayerSession> filter, boolean flush) {
    Players connectedPlayers = Connections.getInstance().getCONNECTED_PLAYERS();
    int onlinePlayers = connectedPlayers.size();
    if (onlinePlayers > 0) {
        ByteBuf byteBufPacket = packet.packetToMessageEncoder();
        if (onlinePlayers > 1) {
            int refCountChange = onlinePlayers - 1;
            byteBufPacket.retain(refCountChange);
        }//from  w  w w .ja va2s  . co  m
        int remotePlayers = 0;
        if (filter != null) {
            for (PlayerSession playerSession : connectedPlayers.values()) {
                boolean notFilter = filter.test(playerSession);
                if (notFilter) {
                    if (playerSession.getCONNECTION_TYPE() == ConnectionType.PROXY_IN_GAME) {
                        ChannelHandlerContext ctx = playerSession.getCONNECTION().getCLIENT_CTX();
                        if (flush) {
                            ctx.writeAndFlush(byteBufPacket, ctx.voidPromise());
                        } else {
                            ctx.write(byteBufPacket, ctx.voidPromise());
                        }
                    } else {
                        sendRemote(playerSession, packet);
                        remotePlayers++;
                    }
                }
            }
        } else {
            for (PlayerSession playerSession : connectedPlayers.values()) {
                if (playerSession.getCONNECTION_TYPE() == ConnectionType.PROXY_IN_GAME) {
                    ChannelHandlerContext ctx = playerSession.getCONNECTION().getCLIENT_CTX();
                    if (flush) {
                        ctx.writeAndFlush(byteBufPacket, ctx.voidPromise());
                    } else {
                        ctx.write(byteBufPacket, ctx.voidPromise());
                    }
                } else {
                    sendRemote(playerSession, packet);
                    remotePlayers++;
                }
            }
        }
        if (remotePlayers > 0) {
            byteBufPacket.release(remotePlayers);
        }
    }
}

From source file:dk.dma.ais.view.rest.QueryParameterHelper.java

public BiPredicate<AisPacketSource, TargetInfo> getSourceAndTargetPredicate() {
    final Predicate<AisPacketSource> ps = getSourcePredicate();
    final Predicate<TargetInfo> pt = getTargetPredicate();
    return new BiPredicate<AisPacketSource, TargetInfo>() {
        @Override//w  w  w.  ja  v a2s .c o m
        public boolean test(AisPacketSource t, TargetInfo u) {
            return ps.test(t) && pt.test(u);
        }
    };
}