Changeset 10040 in josm
- Timestamp:
- 2016-03-26T11:30:54+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r9941 r10040 48 48 import org.openstreetmap.josm.tools.FilteredCollection; 49 49 import org.openstreetmap.josm.tools.Predicate; 50 import org.openstreetmap.josm.tools.Predicates; 50 51 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 51 52 import org.openstreetmap.josm.tools.Utils; … … 264 265 private final QuadBuckets<Node> nodes = new QuadBuckets<>(); 265 266 266 private <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate< OsmPrimitive> predicate) {267 private <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<? super OsmPrimitive> predicate) { 267 268 return new SubclassFilteredCollection<>(allPrimitives, predicate); 268 269 } … … 402 403 */ 403 404 public Collection<OsmPrimitive> allPrimitives() { 404 return getPrimitives( OsmPrimitive.allPredicate);405 return getPrimitives(Predicates.alwaysTrue()); 405 406 } 406 407 -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r9979 r10040 28 28 import org.openstreetmap.josm.tools.CheckParameterUtil; 29 29 import org.openstreetmap.josm.tools.Predicate; 30 import org.openstreetmap.josm.tools.Predicates; 30 31 import org.openstreetmap.josm.tools.Utils; 31 32 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; … … 171 172 172 173 /** 173 * Some predicates, that describe conditions on primitives. 174 * A predicate that filters primitives that are usable. 175 * @see OsmPrimitive#isUsable() 174 176 */ 175 177 public static final Predicate<OsmPrimitive> isUsablePredicate = new Predicate<OsmPrimitive>() { … … 180 182 }; 181 183 184 /** 185 * A predicate filtering primitives that are selectable. 186 */ 182 187 public static final Predicate<OsmPrimitive> isSelectablePredicate = new Predicate<OsmPrimitive>() { 183 188 @Override … … 187 192 }; 188 193 194 /** 195 * A predicate filtering primitives that are not deleted. 196 */ 189 197 public static final Predicate<OsmPrimitive> nonDeletedPredicate = new Predicate<OsmPrimitive>() { 190 198 @Override public boolean evaluate(OsmPrimitive primitive) { … … 193 201 }; 194 202 203 /** 204 * A predicate filtering primitives that are not deleted and not incomplete. 205 */ 195 206 public static final Predicate<OsmPrimitive> nonDeletedCompletePredicate = new Predicate<OsmPrimitive>() { 196 207 @Override public boolean evaluate(OsmPrimitive primitive) { … … 199 210 }; 200 211 212 /** 213 * A predicate filtering primitives that are not deleted and not incomplete and that are not a relation. 214 */ 201 215 public static final Predicate<OsmPrimitive> nonDeletedPhysicalPredicate = new Predicate<OsmPrimitive>() { 202 216 @Override public boolean evaluate(OsmPrimitive primitive) { … … 205 219 }; 206 220 221 /** 222 * A predicate filtering primitives that are modified 223 */ 207 224 public static final Predicate<OsmPrimitive> modifiedPredicate = new Predicate<OsmPrimitive>() { 208 225 @Override public boolean evaluate(OsmPrimitive primitive) { … … 211 228 }; 212 229 213 public static final Predicate<OsmPrimitive> nodePredicate = new Predicate<OsmPrimitive>() {214 @Override public boolean evaluate(OsmPrimitive primitive) {215 return primitive.getClass() == Node.class;216 }217 }; 218 219 public static final Predicate<OsmPrimitive> wayPredicate = new Predicate<OsmPrimitive>() {220 @Override public boolean evaluate(OsmPrimitive primitive) {221 return primitive.getClass() == Way.class;222 } 223 };224 225 public static final Predicate<OsmPrimitive> relationPredicate = new Predicate<OsmPrimitive>() {226 @Override public boolean evaluate(OsmPrimitive primitive) {227 return primitive.getClass() == Relation.class; 228 }229 };230 230 /** 231 * A predicate filtering nodes. 232 */ 233 public static final Predicate<OsmPrimitive> nodePredicate = Predicates.<OsmPrimitive>isOfClass(Node.class); 234 235 /** 236 * A predicate filtering ways. 237 */ 238 public static final Predicate<OsmPrimitive> wayPredicate = Predicates.<OsmPrimitive>isOfClass(Way.class); 239 240 /** 241 * A predicate filtering relations. 242 */ 243 public static final Predicate<OsmPrimitive> relationPredicate = Predicates.<OsmPrimitive>isOfClass(Relation.class); 244 245 /** 246 * A predicate filtering multipolygon relations. 247 */ 231 248 public static final Predicate<OsmPrimitive> multipolygonPredicate = new Predicate<OsmPrimitive>() { 232 249 @Override public boolean evaluate(OsmPrimitive primitive) { … … 235 252 }; 236 253 237 public static final Predicate<OsmPrimitive> allPredicate = new Predicate<OsmPrimitive>() { 238 @Override public boolean evaluate(OsmPrimitive primitive) { 239 return true; 240 } 241 }; 242 254 /** 255 * This matches all ways that have a direction 256 * 257 * @see #FLAG_HAS_DIRECTIONS 258 */ 243 259 public static final Predicate<Tag> directionalKeyPredicate = new Predicate<Tag>() { 244 260 @Override … … 677 693 } 678 694 695 /** 696 * Updates the highlight flag for this primitive. 697 * @param highlighted The new highlight flag. 698 */ 679 699 public void setHighlighted(boolean highlighted) { 680 700 if (isHighlighted() != highlighted) { … … 686 706 } 687 707 708 /** 709 * Checks if the highlight flag for this primitive was set 710 * @return The highlight flag. 711 */ 688 712 public boolean isHighlighted() { 689 713 return (flags & FLAG_HIGHLIGHTED) != 0; … … 820 844 } 821 845 846 /** 847 * A tagged way that matches this pattern has a direction. 848 * @see #FLAG_HAS_DIRECTIONS 849 */ 822 850 private static volatile Match directionKeys; 851 852 /** 853 * A tagged way that matches this pattern has a direction that is reversed. 854 * <p> 855 * This pattern should be a subset of {@link #directionKeys} 856 * @see #FLAG_DIRECTION_REVERSED 857 */ 823 858 private static volatile Match reversedDirectionKeys; 824 859 825 /**826 * Contains a list of direction-dependent keys that make an object827 * direction dependent.828 * Initialized by checkDirectionTagged()829 */830 860 static { 831 861 String reversedDirectionDefault = "oneway=\"-1\""; … … 837 867 "(highway=motorway_link & -oneway=no & -oneway=reversible)"; 838 868 839 try { 840 reversedDirectionKeys = SearchCompiler.compile(Main.pref.get("tags.reversed_direction", reversedDirectionDefault)); 869 reversedDirectionKeys = compileDirectionKeys("tags.reversed_direction", reversedDirectionDefault); 870 directionKeys = compileDirectionKeys("tags.direction", directionDefault); 871 } 872 873 private static Match compileDirectionKeys(String prefName, String defaultValue) throws AssertionError { 874 try { 875 return SearchCompiler.compile(Main.pref.get(prefName, defaultValue)); 841 876 } catch (ParseError e) { 842 Main.error("Unable to compile pattern for tags.reversed_direction, trying default pattern: " + e.getMessage()); 843 844 try { 845 reversedDirectionKeys = SearchCompiler.compile(reversedDirectionDefault); 846 } catch (ParseError e2) { 847 throw new AssertionError("Unable to compile default pattern for direction keys: " + e2.getMessage(), e2); 848 } 849 } 850 try { 851 directionKeys = SearchCompiler.compile(Main.pref.get("tags.direction", directionDefault)); 852 } catch (ParseError e) { 853 Main.error("Unable to compile pattern for tags.direction, trying default pattern: " + e.getMessage()); 854 855 try { 856 directionKeys = SearchCompiler.compile(directionDefault); 857 } catch (ParseError e2) { 858 throw new AssertionError("Unable to compile default pattern for direction keys: " + e2.getMessage(), e2); 859 } 877 Main.error("Unable to compile pattern for " + prefName + ", trying default pattern: " + e.getMessage()); 878 } 879 880 try { 881 return SearchCompiler.compile(defaultValue); 882 } catch (ParseError e2) { 883 throw new AssertionError("Unable to compile default pattern for direction keys: " + e2.getMessage(), e2); 860 884 } 861 885 } -
trunk/src/org/openstreetmap/josm/tools/Predicates.java
r9246 r10040 14 14 15 15 private Predicates() { 16 } 17 18 /** 19 * Creates a predicate that returns true every time. 20 * @param <T> The type of the predicate. 21 * @return A predicate returning <code>true</code> 22 * @since 10040 23 */ 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 }; 31 } 32 33 /** 34 * Creates a predicate that returns false every time. 35 * @param <T> The type of the predicate. 36 * @return A predicate returning <code>false</code> 37 * @since 10040 38 */ 39 public static <T> Predicate<T> alwaysFalse() { 40 return new Predicate<T>() { 41 @Override 42 public boolean evaluate(T object) { 43 return false; 44 } 45 }; 16 46 } 17 47 … … 42 72 public boolean evaluate(T obj) { 43 73 return Objects.equals(obj, ref); 74 } 75 }; 76 } 77 78 /** 79 * Creates a new predicate that checks if elements are exactly of that class. 80 * @param <T> The predicate type. 81 * @param clazz The class the elements must have. 82 * @return A predicate. 83 */ 84 public static <T> Predicate<T> isOfClass(final Class<? extends T> clazz) { 85 return new Predicate<T>() { 86 @Override 87 public boolean evaluate(T obj) { 88 return obj != null && obj.getClass() == clazz; 44 89 } 45 90 };
Note:
See TracChangeset
for help on using the changeset viewer.