Ignore:
Timestamp:
2016-07-31T17:58:31+02:00 (8 years ago)
Author:
Don-vip
Message:

see #11390, fix #12890 - finish transition to Java 8 predicates/functions

File:
1 edited

Legend:

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

    r10689 r10691  
    5050import java.util.concurrent.ThreadFactory;
    5151import java.util.concurrent.atomic.AtomicLong;
     52import java.util.function.Predicate;
    5253import java.util.regex.Matcher;
    5354import java.util.regex.Pattern;
     
    106107     * @param predicate the predicate
    107108     * @return {@code true} if {@code predicate} applies to at least one element from {@code collection}
    108      * @deprecated use {@link Stream#anyMatch(java.util.function.Predicate)} instead.
     109     * @deprecated use {@link Stream#anyMatch(Predicate)} instead.
    109110     */
    110111    @Deprecated
    111112    public static <T> boolean exists(Iterable<? extends T> collection, Predicate<? super T> predicate) {
    112113        for (T item : collection) {
    113             if (predicate.evaluate(item)) {
     114            if (predicate.test(item)) {
    114115                return true;
    115116            }
     
    125126     * @param predicate the predicate
    126127     * @return {@code true} if {@code predicate} applies to all elements from {@code collection}
    127      * @deprecated use {@link Stream#allMatch(java.util.function.Predicate)} instead.
     128     * @deprecated use {@link Stream#allMatch(Predicate)} instead.
    128129     */
    129130    @Deprecated
    130131    public static <T> boolean forAll(Iterable<? extends T> collection, Predicate<? super T> predicate) {
    131         return !exists(collection, Predicates.not(predicate));
     132        return !exists(collection, predicate.negate());
    132133    }
    133134
     
    152153    public static <T> T find(Iterable<? extends T> collection, Predicate<? super T> predicate) {
    153154        for (T item : collection) {
    154             if (predicate.evaluate(item)) {
     155            if (predicate.test(item)) {
    155156                return item;
    156157            }
     
    169170    public static <T> T find(Iterable<? extends Object> collection, Class<? extends T> clazz) {
    170171        return (T) find(collection, Predicates.<Object>isInstanceOf(clazz));
    171     }
    172 
    173     /**
    174      * Creates a new {@link FilteredCollection}.
    175      * @param <T> The collection type.
    176      * @param collection The collection to filter.
    177      * @param predicate The predicate to filter for.
    178      * @return The new {@link FilteredCollection}
    179      * @deprecated Use java predicates and {@link SubclassFilteredCollection#filter(Collection, java.util.function.Predicate)} instead.
    180      */
    181     @Deprecated
    182     @SuppressWarnings("unused")
    183     public static <T> Collection<T> filter(Collection<? extends T> collection, Predicate<? super T> predicate) {
    184         // Diamond operator does not work with Java 9 here
    185         return new FilteredCollection<T>(collection, predicate);
    186172    }
    187173
     
    225211        int i = 0;
    226212        for (T item : collection) {
    227             if (predicate.evaluate(item))
     213            if (predicate.test(item))
    228214                return i;
    229215            i++;
     
    758744    public static String escapeReservedCharactersHTML(String s) {
    759745        return s == null ? "" : s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
    760     }
    761 
    762     /**
    763      * Represents a function that can be applied to objects of {@code A} and
    764      * returns objects of {@code B}.
    765      * @param <A> class of input objects
    766      * @param <B> class of transformed objects
    767      *
    768      * @deprecated Use java.util.function.Function instead.
    769      */
    770     @Deprecated
    771     @FunctionalInterface
    772     public interface Function<A, B> extends java.util.function.Function<A, B> {
    773 
    774         /**
    775          * Applies the function on {@code x}.
    776          * @param x an object of
    777          * @return the transformed object
    778          */
    779         @Override
    780         B apply(A x);
    781746    }
    782747
Note: See TracChangeset for help on using the changeset viewer.