All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.progrm_jarvis.javacommons.util.function.IntPredicate Maven / Gradle / Ivy

package ru.progrm_jarvis.javacommons.util.function;

import lombok.NonNull;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.function.Predicate;

/**
 * Represents a predicate (boolean-valued function) of one argument.
 * This is the primitive type specialization of {@link Predicate} for {@code int}.
 *
 * @see Predicate non-primitive generic equivalent
 */
@FunctionalInterface
public interface IntPredicate extends Predicate<@NotNull Integer>,
        java.util.function.IntPredicate {

    /**
     * Evaluates this predicate on the given argument.
     *
     * @param value the input argument
     * @return {@code true} if the input argument matches the predicate or {@code false} otherwise
     */
    boolean testAsInt(int value);

    @Override
    default boolean test(final int value) {
        return testAsInt(value);
    }

    @Override
    @Contract("null -> fail")
    default boolean test(final @NotNull Integer value) {
        return testAsInt(value.intValue());
    }

    /**
     * 

Returns a composed predicate that represents a short-circuiting logical AND of this predicate and another. * When evaluating the composed predicate, if this predicate is {@code false}, * then the {@code other} predicate is not evaluated.

*

Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated.

* * @param other a predicate that will be logically-ANDed with this predicate * @return a composed predicate that represents the short-circuiting logical AND * of this predicate and the {@code other} predicate * * @throws NullPointerException if other is {@code null} */ @Contract(value = "null -> fail; _ -> _", pure = true) default @NotNull IntPredicate and(final @NonNull IntPredicate other) { return value -> testAsInt(value) && other.testAsInt(value); } @Override @Contract(value = "null -> fail; _ -> _", pure = true) default @NotNull IntPredicate and(final @NonNull Predicate< @NotNull ? super Integer> other) { return value -> testAsInt(value) && other.test(value); } @Override @Contract(value = "null -> fail; _ -> _", pure = true) default @NotNull IntPredicate and(final @NonNull java.util.function.IntPredicate other) { return value -> testAsInt(value) && other.test(value); } /** *

Returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. * When evaluating the composed predicate, if this predicate is {@code true}, * then the {@code other} predicate is not evaluated.

*

Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of this predicate throws an exception, the * {@code other} predicate will not be evaluated.

* * @param other a predicate that will be logically-ORed with this predicate * @return a composed predicate that represents the short-circuiting logical OR * of this predicate and the {@code other} predicate * * @throws NullPointerException if other is {@code null} */ @Contract(value = "null -> fail; _ -> _", pure = true) default @NotNull IntPredicate or(final @NonNull IntPredicate other) { return value -> testAsInt(value) || other.testAsInt(value); } @Override @Contract(value = "null -> fail; _ -> _", pure = true) default @NotNull IntPredicate or(final @NonNull Predicate< @NotNull ? super Integer> other) { return value -> testAsInt(value) || other.test(value); } @Override @Contract(value = "null -> fail; _ -> _", pure = true) default @NotNull IntPredicate or(final @NonNull java.util.function.IntPredicate other) { return value -> testAsInt(value) || other.test(value); } @Override @Contract(value = "-> _", pure = true) default @NotNull IntPredicate negate() { return value -> !testAsInt(value); } /** * Returns a predicate that tests if two arguments are equal. * * @param value value with which to compare the tested one * @return a predicate that tests if two arguments are equal */ @Contract(value = "_ -> _", pure = true) static @NotNull IntPredicate isEqual(final int value) { return tested -> tested == value; } /** * Returns a predicate that tests if two arguments are not equal. * * @param value value with which to compare the tested one * @return a predicate that tests if two arguments are not equal */ @Contract(value = "_ -> _", pure = true) static @NotNull IntPredicate isNotEqual(final int value) { return tested -> tested != value; } /** * Creates a predicate which is always {@code true}. * * @return predicate which is always {@code true} */ @Contract(value = "-> _", pure = true) static @NotNull DoublePredicate alwaysTrue() { return value -> true; } /** * Creates a predicate which is always {@code false}. * * @return predicate which is always {@code false} */ @Contract(value = "-> _", pure = true) static @NotNull DoublePredicate alwaysFalse() { return value -> false; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy