diff --git a/src/java/com/samskivert/util/Predicate.java b/src/java/com/samskivert/util/Predicate.java index 18e9aa34..a9089ebb 100644 --- a/src/java/com/samskivert/util/Predicate.java +++ b/src/java/com/samskivert/util/Predicate.java @@ -140,6 +140,26 @@ public abstract class Predicate protected Predicate _pred; } + /** + * Returns a type-safe reference to the shared instance of a predicate that always returns + * true. + */ + @SuppressWarnings("unchecked") + public static Predicate trueInstance () + { + return TRUE_INSTANCE; + } + + /** + * Returns a type-safe reference to the shared instance of a predicate that always returns + * false. + */ + @SuppressWarnings("unchecked") + public static Predicate falseInstance () + { + return FALSE_INSTANCE; + } + //-------------------------------------------------------------------- // Here's the sole abstract method in the Predicate class: @@ -290,4 +310,18 @@ public abstract class Predicate } }; } + + /** A shared predicate instance that always matches its input. */ + protected static final Predicate TRUE_INSTANCE = new Predicate() { + public boolean isMatch (Object object) { + return true; + } + }; + + /** A shared predicate instance that never matches its input. */ + protected static final Predicate FALSE_INSTANCE = new Predicate() { + public boolean isMatch (Object object) { + return false; + } + }; }