Skip to content

Commit

Permalink
Merge pull request #241 from JarvisCraft/functional-shorthands
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft authored Aug 31, 2021
2 parents 41e5685 + 6b65fc8 commit 3d2b151
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public interface ${className} extends Predicate${'<@NotNull ${wrapperType}>'}<#i
/**
* Creates a predicate which is always {@code true}.
*
* @return predicate which is always {@code true}.
* @return predicate which is always {@code true}
*/
@Contract(value = "-> _", pure = true)
static @NotNull DoublePredicate alwaysTrue() {
Expand All @@ -153,7 +153,7 @@ public interface ${className} extends Predicate${'<@NotNull ${wrapperType}>'}<#i
/**
* Creates a predicate which is always {@code false}.
*
* @return predicate which is always {@code false}.
* @return predicate which is always {@code false}
*/
@Contract(value = "-> _", pure = true)
static @NotNull DoublePredicate alwaysFalse() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ru.progrm_jarvis.javacommons.util.function;

import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import ru.progrm_jarvis.javacommons.annotation.Any;

import java.util.function.Predicate;

/**
* Common implementations of {@link Predicate}.
*/
@UtilityClass
public class Predicates {

/**
* Creates a predicate which is always {@code true}.
*
* @return predicate which is always {@code true}
*/
public <@Any T> @NotNull Predicate<T> alwaysTrue() {
return value -> true;
}

/**
* Creates a predicate which is always {@code false}.
*
* @return predicate which is always {@code false}
*/
public <@Any T> @NotNull Predicate<T> alwaysFalse() {
return value -> false;
}
}

0 comments on commit 3d2b151

Please sign in to comment.