- Timestamp:
- 2016-07-31T17:58:31+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r10608 r10691 21 21 import java.util.concurrent.locks.ReadWriteLock; 22 22 import java.util.concurrent.locks.ReentrantReadWriteLock; 23 import java.util.function.Predicate; 23 24 24 25 import org.openstreetmap.josm.Main; … … 319 320 * @since 10590 320 321 */ 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) { 322 323 return new SubclassFilteredCollection<>(allPrimitives, predicate); 323 324 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r10680 r10691 896 896 positionString = Utils.getPositionListString(position); 897 897 // 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())) { 899 899 positionString += ",\u2717"; 900 900 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r10689 r10691 1135 1135 public Float aggregateList(List<?> lst) { 1136 1136 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()); 1138 1138 return nonNullList.isEmpty() ? (Float) Float.NaN : computeMax ? Collections.max(nonNullList) : Collections.min(nonNullList); 1139 1139 } -
trunk/src/org/openstreetmap/josm/tools/FilteredCollection.java
r10657 r10691 3 3 4 4 import java.util.Collection; 5 import java.util.function.Predicate; 5 6 6 7 /** … … 17 18 * @param predicate The predicate to use as filter 18 19 */ 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) { 20 21 super(collection, predicate); 21 22 } -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r10684 r10691 16 16 import java.util.List; 17 17 import java.util.Set; 18 import java.util.function.Predicate; 18 19 19 20 import org.openstreetmap.josm.Main; … … 887 888 * @return {@code true} if the node is inside the multipolygon 888 889 */ 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) { 890 891 return isPolygonInsideMultiPolygon(Collections.singletonList(node), multiPolygon, isOuterWayAMatch); 891 892 } … … 901 902 * @return {@code true} if the polygon formed by nodes is inside the multipolygon 902 903 */ 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) { 905 905 // Extract outer/inner members from multipolygon 906 906 final MultiPolygonMembers mpm = new MultiPolygonMembers(multiPolygon); -
trunk/src/org/openstreetmap/josm/tools/Predicates.java
r10594 r10691 4 4 import java.util.Collection; 5 5 import java.util.Objects; 6 import java.util.function.Predicate; 6 7 import java.util.regex.Pattern; 7 8 … … 34 35 public static <T> Predicate<T> alwaysFalse() { 35 36 return o -> false; 36 }37 38 /**39 * Returns the negation of {@code predicate}.40 * @param <T> type of items41 * @param predicate the predicate to negate42 * @return the negation of {@code predicate}43 * @deprecated Use {@link java.util.function.Predicate#negate()}44 */45 @Deprecated46 public static <T> Predicate<T> not(final Predicate<T> predicate) {47 return obj -> !predicate.evaluate(obj);48 37 } 49 38 -
trunk/src/org/openstreetmap/josm/tools/SubclassFilteredCollection.java
r10657 r10691 6 6 import java.util.Iterator; 7 7 import java.util.NoSuchElementException; 8 import java.util.function.Predicate; 8 9 9 10 /** … … 22 23 23 24 private final Collection<? extends S> collection; 24 private final java.util.function.Predicate<? super S> predicate;25 private final Predicate<? super S> predicate; 25 26 private int size = -1; 26 27 … … 72 73 * @param collection The base collection to filter 73 74 * @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. 75 76 */ 76 @Deprecated77 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 filter84 * @param predicate The predicate to use as filter85 * @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) {88 78 this.collection = collection; 89 79 this.predicate = predicate; … … 120 110 * @return The filtered collection. It is a {@code Collection<T>}. 121 111 */ 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) { 123 113 return new SubclassFilteredCollection<>(collection, predicate); 124 114 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r10689 r10691 50 50 import java.util.concurrent.ThreadFactory; 51 51 import java.util.concurrent.atomic.AtomicLong; 52 import java.util.function.Predicate; 52 53 import java.util.regex.Matcher; 53 54 import java.util.regex.Pattern; … … 106 107 * @param predicate the predicate 107 108 * @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. 109 110 */ 110 111 @Deprecated 111 112 public static <T> boolean exists(Iterable<? extends T> collection, Predicate<? super T> predicate) { 112 113 for (T item : collection) { 113 if (predicate. evaluate(item)) {114 if (predicate.test(item)) { 114 115 return true; 115 116 } … … 125 126 * @param predicate the predicate 126 127 * @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. 128 129 */ 129 130 @Deprecated 130 131 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()); 132 133 } 133 134 … … 152 153 public static <T> T find(Iterable<? extends T> collection, Predicate<? super T> predicate) { 153 154 for (T item : collection) { 154 if (predicate. evaluate(item)) {155 if (predicate.test(item)) { 155 156 return item; 156 157 } … … 169 170 public static <T> T find(Iterable<? extends Object> collection, Class<? extends T> clazz) { 170 171 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 @Deprecated182 @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 here185 return new FilteredCollection<T>(collection, predicate);186 172 } 187 173 … … 225 211 int i = 0; 226 212 for (T item : collection) { 227 if (predicate. evaluate(item))213 if (predicate.test(item)) 228 214 return i; 229 215 i++; … … 758 744 public static String escapeReservedCharactersHTML(String s) { 759 745 return s == null ? "" : s.replace("&", "&").replace("<", "<").replace(">", ">"); 760 }761 762 /**763 * Represents a function that can be applied to objects of {@code A} and764 * returns objects of {@code B}.765 * @param <A> class of input objects766 * @param <B> class of transformed objects767 *768 * @deprecated Use java.util.function.Function instead.769 */770 @Deprecated771 @FunctionalInterface772 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 of777 * @return the transformed object778 */779 @Override780 B apply(A x);781 746 } 782 747 -
trunk/test/unit/org/CustomMatchers.java
r9246 r10691 4 4 import java.awt.geom.Point2D; 5 5 import java.util.Collection; 6 import java.util.function.Predicate; 6 7 7 8 import org.hamcrest.CustomTypeSafeMatcher; … … 12 13 import org.openstreetmap.josm.data.coor.EastNorth; 13 14 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.tools.Predicate;15 15 16 16 /** … … 35 35 @Override 36 36 protected boolean matchesSafely(T item) { 37 return predicate. evaluate(item);37 return predicate.test(item); 38 38 } 39 39 -
trunk/test/unit/org/openstreetmap/josm/tools/PredicatesTest.java
r10553 r10691 9 9 import java.util.List; 10 10 import java.util.Properties; 11 import java.util.function.Predicate; 11 12 import java.util.regex.Pattern; 12 13 … … 38 39 public void testAlwaysTrue() { 39 40 Predicate<Object> alwaysTrue = Predicates.alwaysTrue(); 40 assertTrue(alwaysTrue. evaluate(new Object()));41 assertTrue(alwaysTrue. evaluate(Boolean.TRUE));41 assertTrue(alwaysTrue.test(new Object())); 42 assertTrue(alwaysTrue.test(Boolean.TRUE)); 42 43 } 43 44 … … 48 49 public void testAlwaysFalse() { 49 50 Predicate<Object> alwaysFalse = Predicates.alwaysFalse(); 50 assertFalse(alwaysFalse.evaluate(new Object())); 51 assertFalse(alwaysFalse.evaluate(Boolean.TRUE)); 52 } 53 54 /** 55 * Test {@link Predicates#not(Predicate)} 56 */ 57 @Test 58 public void testNot() { 59 Predicate<Boolean> not = Predicates.not(new Predicate<Boolean>() { 60 @Override 61 public boolean evaluate(Boolean object) { 62 return object; 63 } 64 }); 65 assertFalse(not.evaluate(Boolean.TRUE)); 66 assertTrue(not.evaluate(Boolean.FALSE)); 51 assertFalse(alwaysFalse.test(new Object())); 52 assertFalse(alwaysFalse.test(Boolean.TRUE)); 67 53 } 68 54 … … 74 60 Integer testObject = Integer.valueOf(1); 75 61 Predicate<Integer> equalTo = Predicates.equalTo(testObject); 76 assertTrue(equalTo. evaluate(testObject));77 assertTrue(equalTo. evaluate(Integer.valueOf(1)));62 assertTrue(equalTo.test(testObject)); 63 assertTrue(equalTo.test(Integer.valueOf(1))); 78 64 79 assertFalse(equalTo. evaluate(Integer.valueOf(2)));80 assertFalse(equalTo. evaluate(null));65 assertFalse(equalTo.test(Integer.valueOf(2))); 66 assertFalse(equalTo.test(null)); 81 67 } 82 68 … … 87 73 public void testIsOfClass() { 88 74 Predicate<Object> isOfClass = Predicates.<Object>isOfClass(Hashtable.class); 89 assertFalse(isOfClass. evaluate(null));90 assertFalse(isOfClass. evaluate(new Object()));91 assertFalse(isOfClass. evaluate(new Properties()));92 assertTrue(isOfClass. evaluate(new Hashtable<>()));75 assertFalse(isOfClass.test(null)); 76 assertFalse(isOfClass.test(new Object())); 77 assertFalse(isOfClass.test(new Properties())); 78 assertTrue(isOfClass.test(new Hashtable<>())); 93 79 } 94 80 … … 99 85 public void testIsInstanceOf() { 100 86 Predicate<Object> isInstanceOf = Predicates.<Object>isInstanceOf(Hashtable.class); 101 assertFalse(isInstanceOf. evaluate(null));102 assertFalse(isInstanceOf. evaluate(new Object()));103 assertTrue(isInstanceOf. evaluate(new Properties()));104 assertTrue(isInstanceOf. evaluate(new Hashtable<>()));87 assertFalse(isInstanceOf.test(null)); 88 assertFalse(isInstanceOf.test(new Object())); 89 assertTrue(isInstanceOf.test(new Properties())); 90 assertTrue(isInstanceOf.test(new Hashtable<>())); 105 91 } 106 92 … … 112 98 Pattern p = Pattern.compile("ab?c"); 113 99 Predicate<String> stringMatchesPattern = Predicates.stringMatchesPattern(p); 114 assertFalse(stringMatchesPattern. evaluate(""));115 assertFalse(stringMatchesPattern. evaluate("a"));116 assertFalse(stringMatchesPattern. evaluate("xabcx"));117 assertTrue(stringMatchesPattern. evaluate("ac"));118 assertTrue(stringMatchesPattern. evaluate("abc"));100 assertFalse(stringMatchesPattern.test("")); 101 assertFalse(stringMatchesPattern.test("a")); 102 assertFalse(stringMatchesPattern.test("xabcx")); 103 assertTrue(stringMatchesPattern.test("ac")); 104 assertTrue(stringMatchesPattern.test("abc")); 119 105 } 120 106 … … 126 112 Pattern p = Pattern.compile("ab?c"); 127 113 Predicate<String> stringContainsPattern = Predicates.stringContainsPattern(p); 128 assertFalse(stringContainsPattern. evaluate(""));129 assertFalse(stringContainsPattern. evaluate("a"));130 assertTrue(stringContainsPattern. evaluate("xabcx"));131 assertTrue(stringContainsPattern. evaluate("ac"));132 assertTrue(stringContainsPattern. evaluate("abc"));133 assertTrue(stringContainsPattern. evaluate("xx\nabc\nx"));114 assertFalse(stringContainsPattern.test("")); 115 assertFalse(stringContainsPattern.test("a")); 116 assertTrue(stringContainsPattern.test("xabcx")); 117 assertTrue(stringContainsPattern.test("ac")); 118 assertTrue(stringContainsPattern.test("abc")); 119 assertTrue(stringContainsPattern.test("xx\nabc\nx")); 134 120 } 135 121 … … 140 126 public void testStringContains() { 141 127 Predicate<String> stringContains = Predicates.stringContains("abc"); 142 assertFalse(stringContains. evaluate(""));143 assertFalse(stringContains. evaluate("a"));144 assertTrue(stringContains. evaluate("xabcx"));145 assertFalse(stringContains. evaluate("ac"));146 assertTrue(stringContains. evaluate("abc"));128 assertFalse(stringContains.test("")); 129 assertFalse(stringContains.test("a")); 130 assertTrue(stringContains.test("xabcx")); 131 assertFalse(stringContains.test("ac")); 132 assertTrue(stringContains.test("abc")); 147 133 } 148 134 … … 154 140 Predicate<OsmPrimitive> hasTag = Predicates.hasTag("key", "value"); 155 141 Node n1 = new Node(); 156 assertFalse(hasTag. evaluate(n1));142 assertFalse(hasTag.test(n1)); 157 143 n1.put("Key", "x"); 158 assertFalse(hasTag. evaluate(n1));144 assertFalse(hasTag.test(n1)); 159 145 n1.put("key", "x"); 160 assertFalse(hasTag. evaluate(n1));146 assertFalse(hasTag.test(n1)); 161 147 n1.put("key", "value"); 162 assertTrue(hasTag. evaluate(n1));148 assertTrue(hasTag.test(n1)); 163 149 } 164 150 … … 170 156 Predicate<OsmPrimitive> hasKey = Predicates.hasKey("key"); 171 157 Node n1 = new Node(); 172 assertFalse(hasKey. evaluate(n1));158 assertFalse(hasKey.test(n1)); 173 159 n1.put("Key", "x"); 174 assertFalse(hasKey. evaluate(n1));160 assertFalse(hasKey.test(n1)); 175 161 n1.put("key", "x"); 176 assertTrue(hasKey. evaluate(n1));162 assertTrue(hasKey.test(n1)); 177 163 } 178 164 … … 184 170 List<String> list = Arrays.asList("a", "b", "c"); 185 171 Predicate<String> inCollection = Predicates.inCollection(list); 186 assertTrue(inCollection. evaluate("a"));187 assertTrue(inCollection. evaluate("c"));188 assertFalse(inCollection. evaluate("d"));189 assertFalse(inCollection. evaluate(null));172 assertTrue(inCollection.test("a")); 173 assertTrue(inCollection.test("c")); 174 assertFalse(inCollection.test("d")); 175 assertFalse(inCollection.test(null)); 190 176 191 177 List<String> list2 = Arrays.asList("a", "b", "c", null); 192 178 Predicate<String> inCollection2 = Predicates.inCollection(list2); 193 assertTrue(inCollection2. evaluate("a"));194 assertTrue(inCollection2. evaluate("c"));195 assertFalse(inCollection2. evaluate("d"));196 assertTrue(inCollection2. evaluate(null));179 assertTrue(inCollection2.test("a")); 180 assertTrue(inCollection2.test("c")); 181 assertFalse(inCollection2.test("d")); 182 assertTrue(inCollection2.test(null)); 197 183 } 198 184 … … 203 189 public void testIsNull() { 204 190 Predicate<Object> isNull = Predicates.isNull(); 205 assertTrue(isNull. evaluate(null));206 assertFalse(isNull. evaluate(Integer.valueOf(2)));191 assertTrue(isNull.test(null)); 192 assertFalse(isNull.test(Integer.valueOf(2))); 207 193 } 208 194 }
Note:
See TracChangeset
for help on using the changeset viewer.