Changeset 10582 in josm
- Timestamp:
- 2016-07-21T02:15:38+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Predicate.java
r8512 r10582 7 7 * @param <T> The objects type 8 8 * @since 3177 9 * @deprecated Use {@link java.util.function.Predicate} instead. 9 10 */ 10 public interface Predicate<T> { 11 @Deprecated 12 @FunctionalInterface 13 public interface Predicate<T> extends java.util.function.Predicate<T> { 11 14 12 15 /** … … 16 19 */ 17 20 boolean evaluate(T object); 21 22 @Override 23 default boolean test(T t) { 24 return evaluate(t); 25 } 18 26 } -
trunk/src/org/openstreetmap/josm/tools/Predicates.java
r10286 r10582 23 23 */ 24 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 }; 25 return o -> true; 31 26 } 32 27 … … 38 33 */ 39 34 public static <T> Predicate<T> alwaysFalse() { 40 return new Predicate<T>() { 41 @Override 42 public boolean evaluate(T object) { 43 return false; 44 } 45 }; 35 return o -> false; 46 36 } 47 37 … … 51 41 * @param predicate the predicate to negate 52 42 * @return the negation of {@code predicate} 43 * @deprecated Use {@link java.util.function.Predicate#negate()} 53 44 */ 45 @Deprecated 54 46 public static <T> Predicate<T> not(final Predicate<T> predicate) { 55 return new Predicate<T>() { 56 @Override 57 public boolean evaluate(T obj) { 58 return !predicate.evaluate(obj); 59 } 60 }; 47 return obj -> !predicate.evaluate(obj); 61 48 } 62 49 … … 68 55 */ 69 56 public static <T> Predicate<T> equalTo(final T ref) { 70 return new Predicate<T>() { 71 @Override 72 public boolean evaluate(T obj) { 73 return Objects.equals(obj, ref); 74 } 75 }; 57 return obj -> Objects.equals(obj, ref); 76 58 } 77 59 … … 85 67 public static <T> Predicate<T> isOfClass(final Class<? extends T> clazz) { 86 68 CheckParameterUtil.ensureParameterNotNull(clazz, "clazz"); 87 return new Predicate<T>() { 88 @Override 89 public boolean evaluate(T obj) { 90 return obj != null && obj.getClass() == clazz; 91 } 92 }; 69 return obj -> obj != null && obj.getClass() == clazz; 93 70 } 94 71 … … 103 80 public static <T> Predicate<T> isInstanceOf(final Class<? extends T> clazz) { 104 81 CheckParameterUtil.ensureParameterNotNull(clazz, "clazz"); 105 return new Predicate<T>() { 106 @Override 107 public boolean evaluate(T o) { 108 return clazz.isInstance(o); 109 } 110 }; 82 return o -> clazz.isInstance(o); 111 83 } 112 84 … … 117 89 */ 118 90 public static Predicate<String> stringMatchesPattern(final Pattern pattern) { 119 return new Predicate<String>() { 120 @Override 121 public boolean evaluate(String string) { 122 return pattern.matcher(string).matches(); 123 } 124 }; 91 return string -> pattern.matcher(string).matches(); 125 92 } 126 93 … … 131 98 */ 132 99 public static Predicate<String> stringContainsPattern(final Pattern pattern) { 133 return new Predicate<String>() { 134 @Override 135 public boolean evaluate(String string) { 136 return pattern.matcher(string).find(); 137 } 138 }; 100 return string -> pattern.matcher(string).find(); 139 101 } 140 102 … … 145 107 */ 146 108 public static Predicate<String> stringContains(final String pattern) { 147 return new Predicate<String>() { 148 @Override 149 public boolean evaluate(String string) { 150 return string.contains(pattern); 151 } 152 }; 109 return string -> string.contains(pattern); 153 110 } 154 111 … … 160 117 */ 161 118 public static Predicate<OsmPrimitive> hasTag(final String key, final String... values) { 162 return new Predicate<OsmPrimitive>() { 163 @Override 164 public boolean evaluate(OsmPrimitive p) { 165 return p.hasTag(key, values); 166 } 167 }; 119 return p -> p.hasTag(key, values); 168 120 } 169 121 … … 174 126 */ 175 127 public static Predicate<OsmPrimitive> hasKey(final String key) { 176 return new Predicate<OsmPrimitive>() { 177 @Override 178 public boolean evaluate(OsmPrimitive p) { 179 return p.hasKey(key); 180 } 181 }; 128 return p -> p.hasKey(key); 182 129 } 183 130 … … 189 136 */ 190 137 public static <T> Predicate<T> inCollection(final Collection<? extends T> target) { 191 return new Predicate<T>() { 192 @Override 193 public boolean evaluate(T object) { 194 return target.contains(object); 195 } 196 }; 138 return object -> target.contains(object); 197 139 } 198 140 … … 203 145 */ 204 146 public static <T> Predicate<T> isNull() { 205 return new Predicate<T>() { 206 @Override 207 public boolean evaluate(T object) { 208 return object == null; 209 } 210 }; 147 return object -> object == null; 211 148 } 212 149 -
trunk/src/org/openstreetmap/josm/tools/SubclassFilteredCollection.java
r9854 r10582 12 12 * Lets you iterate through those elements of a given collection that satisfy a 13 13 * certain condition (imposed by a predicate). 14 * <p> 15 * The behaviour of this class is undefined if the underlying collection is changed. 14 16 * @param <S> element type of the underlying collection 15 17 * @param <T> element type of filtered collection (and subclass of S). The predicate … … 20 22 21 23 private final Collection<? extends S> collection; 22 private final Predicate<? super S> predicate;24 private final java.util.function.Predicate<? super S> predicate; 23 25 private int size = -1; 24 26 … … 36 38 while (iterator.hasNext()) { 37 39 current = iterator.next(); 38 if (predicate. evaluate(current))40 if (predicate.test(current)) 39 41 return; 40 42 } … … 70 72 * @param collection The base collection to filter 71 73 * @param predicate The predicate to use as filter 74 * @deprecated Use java predicates instead. 72 75 */ 76 @Deprecated 73 77 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) { 74 88 this.collection = collection; 75 89 this.predicate = predicate; … … 98 112 return !iterator().hasNext(); 99 113 } 114 115 /** 116 * Create a new filtered collection without any constraints on the predicate type. 117 * @param <T> The collection type. 118 * @param collection The collection to filter. 119 * @param predicate The predicate to filter for. 120 * @return The filtered collection. It is a Collection<T>. 121 */ 122 public static <T> SubclassFilteredCollection<T, T> filter(Collection<T> collection, java.util.function.Predicate<T> predicate) { 123 return new SubclassFilteredCollection<T, T>(collection, predicate); 124 } 100 125 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r10570 r10582 58 58 import java.util.regex.Matcher; 59 59 import java.util.regex.Pattern; 60 import java.util.stream.Stream; 60 61 import java.util.zip.GZIPInputStream; 61 62 import java.util.zip.ZipEntry; … … 105 106 /** 106 107 * Tests whether {@code predicate} applies to at least one element from {@code collection}. 108 * <p> 109 * Note: you can use {@link Stream#anyMatch(java.util.function.Predicate)} instead. 107 110 * @param <T> type of items 108 111 * @param collection the collection … … 121 124 /** 122 125 * Tests whether {@code predicate} applies to all elements from {@code collection}. 126 * <p> 127 * Note: you can use {@link Stream#allMatch(java.util.function.Predicate)} instead. 123 128 * @param <T> type of items 124 129 * @param collection the collection … … 175 180 * @param predicate The predicate to filter for. 176 181 * @return The new {@link FilteredCollection} 177 */ 182 * @deprecated Use java predicates and {@link SubclassFilteredCollection#filter(Collection, java.util.function.Predicate)} instead. 183 */ 184 @Deprecated 178 185 @SuppressWarnings("unused") 179 186 public static <T> Collection<T> filter(Collection<? extends T> collection, Predicate<? super T> predicate) { … … 798 805 * @param <A> class of input objects 799 806 * @param <B> class of transformed objects 800 */ 807 * 808 * @deprecated Use java.util.function.Function instead. 809 */ 810 @Deprecated 801 811 public interface Function<A, B> { 802 812
Note:
See TracChangeset
for help on using the changeset viewer.