Changeset 10715 in josm
- Timestamp:
- 2016-08-03T15:01:43+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java
r10657 r10715 12 12 import java.util.Set; 13 13 import java.util.concurrent.CopyOnWriteArrayList; 14 import java.util.function.Predicate;15 14 16 15 import org.openstreetmap.josm.data.osm.Node; … … 43 42 private final CopyOnWriteArrayList<IConflictListener> listeners; 44 43 45 private static class FilterPredicate implements Predicate<Conflict<? extends OsmPrimitive>> {46 47 private final Class<? extends OsmPrimitive> c;48 49 FilterPredicate(Class<? extends OsmPrimitive> c) {50 this.c = c;51 }52 53 @Override54 public boolean test(Conflict<? extends OsmPrimitive> conflict) {55 return conflict != null && c.isInstance(conflict.getMy());56 }57 }58 59 private static final FilterPredicate NODE_FILTER_PREDICATE = new FilterPredicate(Node.class);60 private static final FilterPredicate WAY_FILTER_PREDICATE = new FilterPredicate(Way.class);61 private static final FilterPredicate RELATION_FILTER_PREDICATE = new FilterPredicate(Relation.class);62 63 44 /** 64 45 * Constructs a new {@code ConflictCollection}. … … 364 345 */ 365 346 public final Collection<Conflict<? extends OsmPrimitive>> getNodeConflicts() { 366 return SubclassFilteredCollection.filter(conflicts, NODE_FILTER_PREDICATE);347 return SubclassFilteredCollection.filter(conflicts, c -> c != null && c.getMy() instanceof Node); 367 348 } 368 349 … … 373 354 */ 374 355 public final Collection<Conflict<? extends OsmPrimitive>> getWayConflicts() { 375 return SubclassFilteredCollection.filter(conflicts, WAY_FILTER_PREDICATE);356 return SubclassFilteredCollection.filter(conflicts, c -> c != null && c.getMy() instanceof Way); 376 357 } 377 358 … … 382 363 */ 383 364 public final Collection<Conflict<? extends OsmPrimitive>> getRelationConflicts() { 384 return SubclassFilteredCollection.filter(conflicts, RELATION_FILTER_PREDICATE);365 return SubclassFilteredCollection.filter(conflicts, c -> c != null && c.getMy() instanceof Relation); 385 366 } 386 367 -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r10691 r10715 48 48 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 49 49 import org.openstreetmap.josm.tools.FilteredCollection; 50 import org.openstreetmap.josm.tools.Predicates;51 50 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 52 51 import org.openstreetmap.josm.tools.Utils; … … 458 457 */ 459 458 public Collection<OsmPrimitive> allPrimitives() { 460 return getPrimitives( Predicates.alwaysTrue());459 return getPrimitives(o -> true); 461 460 } 462 461 -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r10660 r10715 28 28 import org.openstreetmap.josm.gui.mappaint.StyleCache; 29 29 import org.openstreetmap.josm.tools.CheckParameterUtil; 30 import org.openstreetmap.josm.tools.Predicates;31 30 import org.openstreetmap.josm.tools.Utils; 32 31 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; … … 234 233 * A predicate filtering nodes. 235 234 */ 236 public static final Predicate<OsmPrimitive> nodePredicate = Predicates.<OsmPrimitive>isOfClass(Node.class);235 public static final Predicate<OsmPrimitive> nodePredicate = Node.class::isInstance; 237 236 238 237 /** 239 238 * A predicate filtering ways. 240 239 */ 241 public static final Predicate<OsmPrimitive> wayPredicate = Predicates.<OsmPrimitive>isOfClass(Way.class);240 public static final Predicate<OsmPrimitive> wayPredicate = Way.class::isInstance; 242 241 243 242 /** 244 243 * A predicate filtering relations. 245 244 */ 246 public static final Predicate<OsmPrimitive> relationPredicate = Predicates.<OsmPrimitive>isOfClass(Relation.class);245 public static final Predicate<OsmPrimitive> relationPredicate = Relation.class::isInstance; 247 246 248 247 /** -
trunk/src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java
r10680 r10715 19 19 import org.openstreetmap.josm.data.validation.TestError; 20 20 import org.openstreetmap.josm.tools.LanguageInfo; 21 import org.openstreetmap.josm.tools.Predicates;22 21 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 23 22 … … 166 165 final List<TestError> errors = new ArrayList<>(); 167 166 for (final String key : SubclassFilteredCollection.filter(p.keySet(), 168 P redicates.stringMatchesPattern(Pattern.compile(".*:conditional(:.*)?$")))) {167 Pattern.compile(":conditional(:.*)?$").asPredicate())) { 169 168 if (!isKeyValid(key)) { 170 169 errors.add(new TestError(this, Severity.WARNING, tr("Wrong syntax in {0} key", key), 3201, p)); -
trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java
r10657 r10715 28 28 import org.openstreetmap.josm.tools.MultiMap; 29 29 import org.openstreetmap.josm.tools.Pair; 30 import org.openstreetmap.josm.tools.Predicates;31 30 32 31 /** … … 156 155 boolean ignore = false; 157 156 for (String ignoredKey : IGNORED_KEYS.get()) { 158 if (error.getPrimitives().stream().anyMatch( Predicates.hasKey(ignoredKey))) {157 if (error.getPrimitives().stream().anyMatch(p -> p.hasKey(ignoredKey))) { 159 158 ignore = true; 160 159 break; -
trunk/src/org/openstreetmap/josm/data/validation/tests/WayConnectedToArea.java
r10657 r10715 15 15 import org.openstreetmap.josm.data.validation.TestError; 16 16 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 17 import org.openstreetmap.josm.tools.Predicates;18 17 19 18 /** … … 67 66 if (wayNode.isOutsideDownloadArea()) { 68 67 return; 69 } else if (wayNode.getReferrers().stream().anyMatch( Predicates.hasTag("route", "ferry"))) {68 } else if (wayNode.getReferrers().stream().anyMatch(p1 -> p1.hasTag("route", "ferry"))) { 70 69 return; 71 70 } else if (isArea(p)) { -
trunk/src/org/openstreetmap/josm/gui/SplashScreen.java
r10611 r10715 38 38 import org.openstreetmap.josm.tools.GBC; 39 39 import org.openstreetmap.josm.tools.ImageProvider; 40 import org.openstreetmap.josm.tools.Predicates;41 40 import org.openstreetmap.josm.tools.Utils; 42 41 import org.openstreetmap.josm.tools.WindowGeometry; … … 276 275 */ 277 276 public void finishTask(String title) { 278 final Task task = Utils.find(tasks, Predicates.<Task>equalTo(new MeasurableTask(title)));277 final Task task = Utils.find(tasks, new MeasurableTask(title)::equals); 279 278 if (task instanceof MeasurableTask) { 280 279 ((MeasurableTask) task).finish(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r10691 r10715 105 105 import org.openstreetmap.josm.tools.LanguageInfo; 106 106 import org.openstreetmap.josm.tools.OpenBrowser; 107 import org.openstreetmap.josm.tools.Predicates;108 107 import org.openstreetmap.josm.tools.Shortcut; 109 108 import org.openstreetmap.josm.tools.Utils; … … 896 895 positionString = Utils.getPositionListString(position); 897 896 // if not all objects from the selection are member of this relation 898 if (selection.stream().anyMatch( Predicates.inCollection(members).negate())) {897 if (selection.stream().anyMatch(p -> !members.contains(p))) { 899 898 positionString += ",\u2717"; 900 899 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
r10657 r10715 37 37 import org.openstreetmap.josm.tools.Destroyable; 38 38 import org.openstreetmap.josm.tools.MultiMap; 39 import org.openstreetmap.josm.tools.Predicates;40 39 41 40 /** … … 347 346 public void selectRelatedErrors(final Collection<OsmPrimitive> primitives) { 348 347 final Collection<TreePath> paths = new ArrayList<>(); 349 walkAndSelectRelatedErrors(new TreePath(getRoot()), Predicates.inCollection(new HashSet<>(primitives)), paths);348 walkAndSelectRelatedErrors(new TreePath(getRoot()), new HashSet<>(primitives)::contains, paths); 350 349 getSelectionModel().clearSelection(); 351 350 for (TreePath path : paths) { -
trunk/src/org/openstreetmap/josm/gui/layer/LayerPositionStrategy.java
r10592 r10715 3 3 4 4 import java.util.List; 5 import java.util.Objects; 5 6 import java.util.function.Predicate; 6 7 import org.openstreetmap.josm.tools.Predicates;8 7 9 8 /** … … 46 45 */ 47 46 static LayerPositionStrategy inFrontOf(Layer other) { 48 return inFrontOfFirst( Predicates.equalTo(other));47 return inFrontOfFirst(obj -> Objects.equals(obj, other)); 49 48 } 50 49 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r10674 r10715 28 28 import org.openstreetmap.josm.gui.mappaint.Environment; 29 29 import org.openstreetmap.josm.tools.CheckParameterUtil; 30 import org.openstreetmap.josm.tools.Predicates;31 30 import org.openstreetmap.josm.tools.Utils; 32 31 … … 513 512 this.matchType = matchType == null ? KeyMatchType.EQ : matchType; 514 513 this.containsPattern = KeyMatchType.REGEX.equals(matchType) 515 ? P redicates.stringContainsPattern(Pattern.compile(label))514 ? Pattern.compile(label).asPredicate() 516 515 : null; 517 516 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r10691 r10715 16 16 import java.util.Collections; 17 17 import java.util.List; 18 import java.util.Objects; 18 19 import java.util.TreeSet; 19 20 import java.util.function.Function; … … 37 38 import org.openstreetmap.josm.tools.ColorHelper; 38 39 import org.openstreetmap.josm.tools.Geometry; 39 import org.openstreetmap.josm.tools.Predicates;40 40 import org.openstreetmap.josm.tools.RightAndLefthandTraffic; 41 41 import org.openstreetmap.josm.tools.SubclassFilteredCollection; … … 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.<Float>isNull().negate());1137 final Collection<Float> nonNullList = SubclassFilteredCollection.filter(floats, Objects::nonNull); 1138 1138 return nonNullList.isEmpty() ? (Float) Float.NaN : computeMax ? Collections.max(nonNullList) : Collections.min(nonNullList); 1139 1139 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r10674 r10715 24 24 import org.openstreetmap.josm.tools.Geometry; 25 25 import org.openstreetmap.josm.tools.Pair; 26 import org.openstreetmap.josm.tools.Predicates;27 26 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 28 27 import org.openstreetmap.josm.tools.Utils; … … 322 321 } 323 322 final Collection<Relation> multipolygons = Utils.filteredCollection(SubclassFilteredCollection.filter( 324 e.osm.getReferrers(), Predicates.hasTag("type", "multipolygon")), Relation.class);323 e.osm.getReferrers(), p -> p.hasTag("type", "multipolygon")), Relation.class); 325 324 final Relation multipolygon = multipolygons.iterator().next(); 326 325 if (multipolygon == null) throw new NoSuchElementException(); -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReader.java
r10590 r10715 43 43 import org.openstreetmap.josm.io.CachedFile; 44 44 import org.openstreetmap.josm.io.UTFInputStreamReader; 45 import org.openstreetmap.josm.tools.Predicates;46 45 import org.openstreetmap.josm.tools.XmlObjectParser; 47 46 import org.xml.sax.SAXException; … … 226 225 if (all.contains(tp)) { 227 226 lastmenuOriginal = tp; 228 tp = (TaggingPresetMenu) all.stream().filter( Predicates.equalTo(tp)).findFirst().get();227 tp = (TaggingPresetMenu) all.stream().filter(tp::equals).findFirst().get(); 229 228 lastmenuOriginal.group = null; 230 229 } else { -
trunk/src/org/openstreetmap/josm/tools/Predicates.java
r10691 r10715 11 11 /** 12 12 * Utility class for creating {@link Predicate}s. 13 * @deprecated Use corresponding lambda expressions instead 13 14 */ 15 @Deprecated 14 16 public final class Predicates { 15 17 … … 87 89 */ 88 90 public static Predicate<String> stringContainsPattern(final Pattern pattern) { 89 return string ->pattern.matcher(string).find();91 return pattern.asPredicate(); 90 92 } 91 93 … … 134 136 */ 135 137 public static <T> Predicate<T> isNull() { 136 return object -> object == null;138 return Objects::isNull; 137 139 } 138 140 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r10692 r10715 142 142 */ 143 143 public static <T> boolean exists(Iterable<T> collection, Class<? extends T> clazz) { 144 return exists(collection, Predicates.<T>isInstanceOf(clazz)); 144 CheckParameterUtil.ensureParameterNotNull(clazz, "clazz"); 145 return exists(collection, clazz::isInstance); 145 146 } 146 147 … … 170 171 @SuppressWarnings("unchecked") 171 172 public static <T> T find(Iterable<? extends Object> collection, Class<? extends T> clazz) { 172 return (T) find(collection, Predicates.<Object>isInstanceOf(clazz)); 173 CheckParameterUtil.ensureParameterNotNull(clazz, "clazz"); 174 return (T) find(collection, clazz::isInstance); 173 175 } 174 176 … … 199 201 */ 200 202 public static <S, T extends S> SubclassFilteredCollection<S, T> filteredCollection(Collection<S> collection, final Class<T> clazz) { 201 return new SubclassFilteredCollection<>(collection, Predicates.<S>isInstanceOf(clazz)); 203 CheckParameterUtil.ensureParameterNotNull(clazz, "clazz"); 204 return new SubclassFilteredCollection<>(collection, clazz::isInstance); 202 205 } 203 206
Note:
See TracChangeset
for help on using the changeset viewer.