Changeset 10691 in josm for trunk/src/org/openstreetmap/josm


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

Location:
trunk/src/org/openstreetmap/josm
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r10608 r10691  
    2121import java.util.concurrent.locks.ReadWriteLock;
    2222import java.util.concurrent.locks.ReentrantReadWriteLock;
     23import java.util.function.Predicate;
    2324
    2425import org.openstreetmap.josm.Main;
     
    319320     * @since 10590
    320321     */
    321     public <T extends OsmPrimitive> Collection<T> getPrimitives(java.util.function.Predicate<? super OsmPrimitive> predicate) {
     322    public <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<? super OsmPrimitive> predicate) {
    322323        return new SubclassFilteredCollection<>(allPrimitives, predicate);
    323324    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r10680 r10691  
    896896                positionString = Utils.getPositionListString(position);
    897897                // if not all objects from the selection are member of this relation
    898                 if (selection.stream().anyMatch(Predicates.not(Predicates.inCollection(members)))) {
     898                if (selection.stream().anyMatch(Predicates.inCollection(members).negate())) {
    899899                    positionString += ",\u2717";
    900900                }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r10689 r10691  
    11351135        public Float aggregateList(List<?> lst) {
    11361136            final List<Float> floats = Utils.transform(lst, (Function<Object, Float>) x -> Cascade.convertTo(x, float.class));
    1137             final Collection<Float> nonNullList = SubclassFilteredCollection.filter(floats, Predicates.not(Predicates.isNull()));
     1137            final Collection<Float> nonNullList = SubclassFilteredCollection.filter(floats, Predicates.<Float>isNull().negate());
    11381138            return nonNullList.isEmpty() ? (Float) Float.NaN : computeMax ? Collections.max(nonNullList) : Collections.min(nonNullList);
    11391139        }
  • trunk/src/org/openstreetmap/josm/tools/FilteredCollection.java

    r10657 r10691  
    33
    44import java.util.Collection;
     5import java.util.function.Predicate;
    56
    67/**
     
    1718     * @param predicate The predicate to use as filter
    1819     */
    19     public FilteredCollection(Collection<? extends T> collection, java.util.function.Predicate<? super T> predicate) {
     20    public FilteredCollection(Collection<? extends T> collection, Predicate<? super T> predicate) {
    2021        super(collection, predicate);
    2122    }
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r10684 r10691  
    1616import java.util.List;
    1717import java.util.Set;
     18import java.util.function.Predicate;
    1819
    1920import org.openstreetmap.josm.Main;
     
    887888     * @return {@code true} if the node is inside the multipolygon
    888889     */
    889     public static boolean isNodeInsideMultiPolygon(Node node, Relation multiPolygon, java.util.function.Predicate<Way> isOuterWayAMatch) {
     890    public static boolean isNodeInsideMultiPolygon(Node node, Relation multiPolygon, Predicate<Way> isOuterWayAMatch) {
    890891        return isPolygonInsideMultiPolygon(Collections.singletonList(node), multiPolygon, isOuterWayAMatch);
    891892    }
     
    901902     * @return {@code true} if the polygon formed by nodes is inside the multipolygon
    902903     */
    903     public static boolean isPolygonInsideMultiPolygon(List<Node> nodes, Relation multiPolygon,
    904             java.util.function.Predicate<Way> isOuterWayAMatch) {
     904    public static boolean isPolygonInsideMultiPolygon(List<Node> nodes, Relation multiPolygon, Predicate<Way> isOuterWayAMatch) {
    905905        // Extract outer/inner members from multipolygon
    906906        final MultiPolygonMembers mpm = new MultiPolygonMembers(multiPolygon);
  • trunk/src/org/openstreetmap/josm/tools/Predicates.java

    r10594 r10691  
    44import java.util.Collection;
    55import java.util.Objects;
     6import java.util.function.Predicate;
    67import java.util.regex.Pattern;
    78
     
    3435    public static <T> Predicate<T> alwaysFalse() {
    3536        return o -> false;
    36     }
    37 
    38     /**
    39      * Returns the negation of {@code predicate}.
    40      * @param <T> type of items
    41      * @param predicate the predicate to negate
    42      * @return the negation of {@code predicate}
    43      * @deprecated Use {@link java.util.function.Predicate#negate()}
    44      */
    45     @Deprecated
    46     public static <T> Predicate<T> not(final Predicate<T> predicate) {
    47         return obj -> !predicate.evaluate(obj);
    4837    }
    4938
  • trunk/src/org/openstreetmap/josm/tools/SubclassFilteredCollection.java

    r10657 r10691  
    66import java.util.Iterator;
    77import java.util.NoSuchElementException;
     8import java.util.function.Predicate;
    89
    910/**
     
    2223
    2324    private final Collection<? extends S> collection;
    24     private final java.util.function.Predicate<? super S> predicate;
     25    private final Predicate<? super S> predicate;
    2526    private int size = -1;
    2627
     
    7273     * @param collection The base collection to filter
    7374     * @param predicate The predicate to use as filter
    74      * @deprecated Use java predicates instead.
     75     * @see #filter(Collection, Predicate) for an alternative way to construct this.
    7576     */
    76     @Deprecated
    7777    public SubclassFilteredCollection(Collection<? extends S> collection, Predicate<? super S> predicate) {
    78         this(collection, (java.util.function.Predicate<? super S>) predicate);
    79     }
    80 
    81     /**
    82      * Constructs a new {@code SubclassFilteredCollection}.
    83      * @param collection The base collection to filter
    84      * @param predicate The predicate to use as filter
    85      * @see #filter(Collection, java.util.function.Predicate) for an alternative way to construct this.
    86      */
    87     public SubclassFilteredCollection(Collection<? extends S> collection, java.util.function.Predicate<? super S> predicate) {
    8878        this.collection = collection;
    8979        this.predicate = predicate;
     
    120110     * @return The filtered collection. It is a {@code Collection<T>}.
    121111     */
    122     public static <T> SubclassFilteredCollection<T, T> filter(Collection<? extends T> collection, java.util.function.Predicate<T> predicate) {
     112    public static <T> SubclassFilteredCollection<T, T> filter(Collection<? extends T> collection, Predicate<T> predicate) {
    123113        return new SubclassFilteredCollection<>(collection, predicate);
    124114    }
  • 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.