Ignore:
Timestamp:
2016-03-26T11:30:54+01:00 (8 years ago)
Author:
Don-vip
Message:

fix #12680 - Documentation and cleanup on predicates (patch by michael2402, modified)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Predicates.java

    r9246 r10040  
    1414
    1515    private Predicates() {
     16    }
     17
     18    /**
     19     * Creates a predicate that returns true every time.
     20     * @param <T> The type of the predicate.
     21     * @return A predicate returning <code>true</code>
     22     * @since 10040
     23     */
     24    public static <T> Predicate<T> alwaysTrue() {
     25        return new Predicate<T>() {
     26            @Override
     27            public boolean evaluate(T object) {
     28                return true;
     29            }
     30        };
     31    }
     32
     33    /**
     34     * Creates a predicate that returns false every time.
     35     * @param <T> The type of the predicate.
     36     * @return A predicate returning <code>false</code>
     37     * @since 10040
     38     */
     39    public static <T> Predicate<T> alwaysFalse() {
     40        return new Predicate<T>() {
     41            @Override
     42            public boolean evaluate(T object) {
     43                return false;
     44            }
     45        };
    1646    }
    1747
     
    4272            public boolean evaluate(T obj) {
    4373                return Objects.equals(obj, ref);
     74            }
     75        };
     76    }
     77
     78    /**
     79     * Creates a new predicate that checks if elements are exactly of that class.
     80     * @param <T> The predicate type.
     81     * @param clazz The class the elements must have.
     82     * @return A predicate.
     83     */
     84    public static <T> Predicate<T> isOfClass(final Class<? extends T> clazz) {
     85        return new Predicate<T>() {
     86            @Override
     87            public boolean evaluate(T obj) {
     88                return obj != null && obj.getClass() == clazz;
    4489            }
    4590        };
Note: See TracChangeset for help on using the changeset viewer.