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.jsweet.input.typescriptdef.ast.Scanner.java

@SuppressWarnings("unchecked")
public <T extends Visitable> List<T> getParents(Predicate<Visitable> predicate) {
    List<T> parents = new ArrayList<T>();
    for (int i = this.stack.size() - 1; i >= 0; i--) {
        if (predicate.test(this.stack.get(i))) {
            T t = (T) this.stack.get(i);
            parents.add(t);//from   w  w  w. j  a va2s . co m
        }
    }
    return parents;
}

From source file:at.gridtec.lambda4j.function.tri.conversion.TriBooleanToIntFunction.java

/**
 * Returns a composed {@link ToIntTriFunction} 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 <C> The type of the argument to the third 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
 * @param before3 The third predicate to apply before this function is applied
 * @return A composed {@code ToIntTriFunction} that first applies the {@code before} predicates to its input, and
 * then applies this function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 *///from  w w w .ja v a 2  s. co m
@Nonnull
default <A, B, C> ToIntTriFunction<A, B, C> compose(@Nonnull final Predicate<? super A> before1,
        @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (a, b, c) -> applyAsInt(before1.test(a), before2.test(b), before3.test(c));
}

From source file:at.gridtec.lambda4j.function.tri.conversion.TriBooleanToByteFunction.java

/**
 * Returns a composed {@link ToByteTriFunction} 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 <C> The type of the argument to the third 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
 * @param before3 The third predicate to apply before this function is applied
 * @return A composed {@code ToByteTriFunction} that first applies the {@code before} predicates to its input, and
 * then applies this function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 *//*from   ww  w  .j a v a2s. c o m*/
@Nonnull
default <A, B, C> ToByteTriFunction<A, B, C> compose(@Nonnull final Predicate<? super A> before1,
        @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (a, b, c) -> applyAsByte(before1.test(a), before2.test(b), before3.test(c));
}

From source file:at.gridtec.lambda4j.function.tri.conversion.TriBooleanToCharFunction.java

/**
 * Returns a composed {@link ToCharTriFunction} 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 <C> The type of the argument to the third 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
 * @param before3 The third predicate to apply before this function is applied
 * @return A composed {@code ToCharTriFunction} that first applies the {@code before} predicates to its input, and
 * then applies this function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 *///w w  w.ja  va  2s  . c o m
@Nonnull
default <A, B, C> ToCharTriFunction<A, B, C> compose(@Nonnull final Predicate<? super A> before1,
        @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (a, b, c) -> applyAsChar(before1.test(a), before2.test(b), before3.test(c));
}

From source file:at.gridtec.lambda4j.function.tri.conversion.TriBooleanToLongFunction.java

/**
 * Returns a composed {@link ToLongTriFunction} 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 <C> The type of the argument to the third 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
 * @param before3 The third predicate to apply before this function is applied
 * @return A composed {@code ToLongTriFunction} that first applies the {@code before} predicates to its input, and
 * then applies this function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 *//*w ww . jav  a  2  s .  c o m*/
@Nonnull
default <A, B, C> ToLongTriFunction<A, B, C> compose(@Nonnull final Predicate<? super A> before1,
        @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (a, b, c) -> applyAsLong(before1.test(a), before2.test(b), before3.test(c));
}

From source file:at.gridtec.lambda4j.function.tri.conversion.TriBooleanToFloatFunction.java

/**
 * Returns a composed {@link ToFloatTriFunction} 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 <C> The type of the argument to the third 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
 * @param before3 The third predicate to apply before this function is applied
 * @return A composed {@code ToFloatTriFunction} that first applies the {@code before} predicates to its input, and
 * then applies this function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 *///  www  . j a  v  a  2  s .c  om
@Nonnull
default <A, B, C> ToFloatTriFunction<A, B, C> compose(@Nonnull final Predicate<? super A> before1,
        @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (a, b, c) -> applyAsFloat(before1.test(a), before2.test(b), before3.test(c));
}

From source file:at.gridtec.lambda4j.function.tri.conversion.TriBooleanToShortFunction.java

/**
 * Returns a composed {@link ToShortTriFunction} 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 <C> The type of the argument to the third 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
 * @param before3 The third predicate to apply before this function is applied
 * @return A composed {@code ToShortTriFunction} that first applies the {@code before} predicates to its input, and
 * then applies this function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 *//*from   ww w .  j  av a2  s.  co m*/
@Nonnull
default <A, B, C> ToShortTriFunction<A, B, C> compose(@Nonnull final Predicate<? super A> before1,
        @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (a, b, c) -> applyAsShort(before1.test(a), before2.test(b), before3.test(c));
}

From source file:at.gridtec.lambda4j.function.tri.conversion.TriBooleanToDoubleFunction.java

/**
 * Returns a composed {@link ToDoubleTriFunction} 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 <C> The type of the argument to the third 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
 * @param before3 The third predicate to apply before this function is applied
 * @return A composed {@code ToDoubleTriFunction} that first applies the {@code before} predicates to its input, and
 * then applies this function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 *//*from   w  w w .j a  va 2  s  . c  om*/
@Nonnull
default <A, B, C> ToDoubleTriFunction<A, B, C> compose(@Nonnull final Predicate<? super A> before1,
        @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (a, b, c) -> applyAsDouble(before1.test(a), before2.test(b), before3.test(c));
}

From source file:fr.treeptik.cloudunit.docker.DockerContainerJSON.java

public DockerContainer start(DockerContainer dockerContainer, String hostIp) throws DockerJSONException {
    URI uri = null;/*  ww  w .  j  av  a  2 s  .c o m*/
    try {
        uri = new URIBuilder().setScheme(dockerEndpointMode).setHost(hostIp)
                .setPath("/containers/" + dockerContainer.getName() + "/start").build();
        JSONObject config = new JSONObject();

        config.put("Privileged", Boolean.FALSE);
        config.put("PublishAllPorts", Boolean.TRUE);

        JSONArray link = new JSONArray();
        if (dockerContainer.getLinks() != null) {
            link.addAll(dockerContainer.getLinks());
            config.put("Links", link);
        }

        if (dockerContainer.getVolumesFrom() != null) {
            JSONArray listVolumesFrom = new JSONArray();
            if (dockerContainer.getVolumesFrom() != null) {
                for (int i = 0, iMax = dockerContainer.getVolumesFrom().size(); i < iMax; i++) {
                    listVolumesFrom.add(dockerContainer.getVolumesFrom().get(i));
                }
            }
            config.put("VolumesFrom", listVolumesFrom);
        }

        if (dockerContainer.getPortsToOpen() != null) {
            JSONObject portsBinding = new JSONObject();
            dockerContainer.getPortsToOpen().stream().map(t -> t.toString() + "/tcp").forEach(
                    t -> portsBinding.put(t, Arrays.asList((new JSONObject(new HashMap<String, String>() {

                        private static final long serialVersionUID = 1L;

                        {
                            put("HostPort", portUtils.getARandomHostPorts(hostIp).toString());
                            put("HostIp", "0.0.0.0");
                        }
                    })))));

            config.put("PortBindings", portsBinding);
        }

        // ajout des volumes provenant de l'hote
        final List volumes = new ArrayList<String>() {
            {
                add("/etc/localtime:/etc/localtime:ro");
                add("/etc/timezone:/etc/timezone:ro");
            }
        };

        BooleanSupplier isRunningIntoKVM = () -> "true".equalsIgnoreCase(System.getenv().get("CU_KVM"));
        if (isRunningIntoKVM.getAsBoolean()) {
            volumes.add("/dev/urandom:/dev/urandom");
        }

        Predicate<String> isContainerGit = s -> s.contains("-git-");
        if (isContainerGit.test(dockerContainer.getName())) {
            volumes.add("/var/log/cloudunit/git/auth-" + dockerContainer.getId() + ":/var/log/cloudunit");
        }

        config.put("Binds", volumes);

        /**
         * Gestion du binding de port
         */
        JSONObject portBindsConfigJSONFinal = new JSONObject();
        if (dockerContainer.getPortBindings() != null) {
            /**
             * pour chaque ports  Binder (ex: 53/udp) on rcupre le
             * tableau avec les deux maps ex :- map1 = HostIp , 172.17.42.1
             * - map2 = HostPort , 53
             */
            for (Map.Entry<String, Map<String, String>[]> portKey : dockerContainer.getPortBindings()
                    .entrySet()) {

                logger.info("port/protocol to configure : " + portKey.getKey());

                // On convertie le tableau en list pour itrer dessus
                List<Map<String, String>> listOfMapsConfig = Arrays.asList(portKey.getValue());

                JSONObject portConfigJSON = new JSONObject();
                for (Map<String, String> portConfigMap : listOfMapsConfig) {
                    JSONArray portConfigJSONArray = new JSONArray();

                    // transfert HostIP and HostPort avec leur valeurs dans
                    // un JSONArray
                    for (Entry<String, String> hostBindingMap : portConfigMap.entrySet()) {
                        logger.info(hostBindingMap.getKey() + " : " + hostBindingMap.getValue());

                        portConfigJSON.put(hostBindingMap.getKey(), hostBindingMap.getValue());
                        portConfigJSONArray.add(portConfigJSON);
                    }
                    portBindsConfigJSONFinal.put(portKey.getKey(), portConfigJSONArray);
                    config.put("PortBindings", portBindsConfigJSONFinal);
                }
            }
        }

        int statusCode = client.sendPostForStart(uri, config.toJSONString(), "application/json");

        switch (statusCode) {
        case 304:
            throw new WarningDockerJSONException("container already started");
        case 404:
            throw new ErrorDockerJSONException("docker : no such container");
        case 500:
            throw new ErrorDockerJSONException("docker : error server");
        }
        dockerContainer = this.findOne(dockerContainer.getName(), hostIp);
    } catch (URISyntaxException | IOException e) {
        StringBuilder msgError = new StringBuilder(256);
        msgError.append(dockerContainer).append(",hostIP=").append(hostIp).append(",uri=").append(uri);
        logger.error("" + msgError, e);
        throw new FatalDockerJSONException("docker : error fatal");
    }
    return dockerContainer;

}

From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiBooleanToByteFunction.java

/**
 * Returns a composed {@link ToByteTriFunction} 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 <C> The type of the argument to the third 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
 * @param before3 The third predicate to apply before this function is applied
 * @return A composed {@code ToByteTriFunction} that first applies the {@code before} functions to its input, and
 * then applies this function to the result.
 * @throws NullPointerException If given argument is {@code null}
 * @implSpec The input argument of this method is able to handle every type.
 *//*from   www.j av  a 2 s.com*/
@Nonnull
default <A, B, C> ToByteTriFunction<A, B, C> compose(@Nonnull final Function<? super A, ? extends T> before1,
        @Nonnull final Predicate<? super B> before2, @Nonnull final Predicate<? super C> before3) {
    Objects.requireNonNull(before1);
    Objects.requireNonNull(before2);
    Objects.requireNonNull(before3);
    return (a, b, c) -> applyAsByte(before1.apply(a), before2.test(b), before3.test(c));
}