diff --git a/src/org/openstreetmap/josm/data/osm/DataSet.java b/src/org/openstreetmap/josm/data/osm/DataSet.java
index c046d2b..901e7c2 100644
|
a
|
b
|
import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
| 47 | 47 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; |
| 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; |
| 52 | 53 | |
| … |
… |
public final class DataSet implements Data, Cloneable, ProjectionChangeListener
|
| 263 | 264 | */ |
| 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 | } |
| 269 | 270 | |
| … |
… |
public final class DataSet implements Data, Cloneable, ProjectionChangeListener
|
| 401 | 402 | * @return A collection containing all primitives of the dataset. Data is not ordered |
| 402 | 403 | */ |
| 403 | 404 | public Collection<OsmPrimitive> allPrimitives() { |
| 404 | | return getPrimitives(OsmPrimitive.allPredicate); |
| | 405 | return getPrimitives(Predicates.alwaysTrue()); |
| 405 | 406 | } |
| 406 | 407 | |
| 407 | 408 | /** |
diff --git a/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java b/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
index e21aeeb..dcc5e6b 100644
|
a
|
b
|
import org.openstreetmap.josm.data.osm.visitor.Visitor;
|
| 27 | 27 | import org.openstreetmap.josm.gui.mappaint.StyleCache; |
| 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; |
| 32 | 33 | |
| … |
… |
public abstract class OsmPrimitive extends AbstractPrimitive implements Comparab
|
| 170 | 171 | } |
| 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>() { |
| 176 | 178 | @Override |
| … |
… |
public abstract class OsmPrimitive extends AbstractPrimitive implements Comparab
|
| 179 | 181 | } |
| 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 |
| 184 | 189 | public boolean evaluate(OsmPrimitive primitive) { |
| … |
… |
public abstract class OsmPrimitive extends AbstractPrimitive implements Comparab
|
| 186 | 191 | } |
| 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) { |
| 191 | 199 | return !primitive.isDeleted(); |
| 192 | 200 | } |
| 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) { |
| 197 | 208 | return !primitive.isDeleted() && !primitive.isIncomplete(); |
| 198 | 209 | } |
| 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) { |
| 203 | 217 | return !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation); |
| 204 | 218 | } |
| 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) { |
| 209 | 226 | return primitive.isModified(); |
| 210 | 227 | } |
| 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 | | }; |
| | 230 | /** |
| | 231 | * A predicate filtering nodes. |
| | 232 | */ |
| | 233 | public static final Predicate<OsmPrimitive> nodePredicate = Predicates.<OsmPrimitive>isOfClass(Node.class); |
| 218 | 234 | |
| 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 | | }; |
| | 235 | /** |
| | 236 | * A predicate filtering ways. |
| | 237 | */ |
| | 238 | public static final Predicate<OsmPrimitive> wayPredicate = Predicates.<OsmPrimitive>isOfClass(Way.class); |
| 224 | 239 | |
| 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 | | }; |
| | 240 | /** |
| | 241 | * A predicate filtering relations. |
| | 242 | */ |
| | 243 | public static final Predicate<OsmPrimitive> relationPredicate = Predicates.<OsmPrimitive>isOfClass(Relation.class); |
| 230 | 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) { |
| 233 | 250 | return primitive.getClass() == Relation.class && ((Relation) primitive).isMultipolygon(); |
| 234 | 251 | } |
| 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 | | }; |
| | 254 | /** |
| | 255 | * A predicate that always returns true. |
| | 256 | * @deprecated Replaced by {@link Predicates#alwaysTrue()} |
| | 257 | */ |
| | 258 | @Deprecated |
| | 259 | public static final Predicate<OsmPrimitive> allPredicate = Predicates.alwaysTrue(); |
| 242 | 260 | |
| | 261 | /** |
| | 262 | * This matches all ways that have a direction |
| | 263 | * |
| | 264 | * @see #FLAG_HAS_DIRECTIONS |
| | 265 | */ |
| 243 | 266 | public static final Predicate<Tag> directionalKeyPredicate = new Predicate<Tag>() { |
| 244 | 267 | @Override |
| 245 | 268 | public boolean evaluate(Tag tag) { |
| … |
… |
public abstract class OsmPrimitive extends AbstractPrimitive implements Comparab
|
| 676 | 699 | return false; |
| 677 | 700 | } |
| 678 | 701 | |
| | 702 | /** |
| | 703 | * Updates the highlight flag for this primitive. |
| | 704 | * @param highlighted The new highlight flag. |
| | 705 | */ |
| 679 | 706 | public void setHighlighted(boolean highlighted) { |
| 680 | 707 | if (isHighlighted() != highlighted) { |
| 681 | 708 | updateFlags(FLAG_HIGHLIGHTED, highlighted); |
| … |
… |
public abstract class OsmPrimitive extends AbstractPrimitive implements Comparab
|
| 685 | 712 | } |
| 686 | 713 | } |
| 687 | 714 | |
| | 715 | /** |
| | 716 | * Checks if the highlight flag for this primitive was set |
| | 717 | * @return The highlight flag. |
| | 718 | */ |
| 688 | 719 | public boolean isHighlighted() { |
| 689 | 720 | return (flags & FLAG_HIGHLIGHTED) != 0; |
| 690 | 721 | } |
| … |
… |
public abstract class OsmPrimitive extends AbstractPrimitive implements Comparab
|
| 819 | 850 | return result; |
| 820 | 851 | } |
| 821 | 852 | |
| | 853 | /** |
| | 854 | * A tagged way that matches this pattern has a direction. |
| | 855 | * @see #FLAG_HAS_DIRECTIONS |
| | 856 | */ |
| 822 | 857 | private static volatile Match directionKeys; |
| 823 | | private static volatile Match reversedDirectionKeys; |
| 824 | 858 | |
| 825 | 859 | /** |
| 826 | | * Contains a list of direction-dependent keys that make an object |
| 827 | | * direction dependent. |
| 828 | | * Initialized by checkDirectionTagged() |
| | 860 | * A tagged way that matches this pattern has a direction that is reversed. |
| | 861 | * <p> |
| | 862 | * This pattern should be a subset of {@link #directionKeys} |
| | 863 | * @see #FLAG_DIRECTION_REVERSED |
| 829 | 864 | */ |
| | 865 | private static volatile Match reversedDirectionKeys; |
| | 866 | |
| 830 | 867 | static { |
| 831 | 868 | String reversedDirectionDefault = "oneway=\"-1\""; |
| 832 | 869 | |
| … |
… |
public abstract class OsmPrimitive extends AbstractPrimitive implements Comparab
|
| 836 | 873 | "junction=roundabout | (highway=motorway & -oneway=no & -oneway=reversible) | "+ |
| 837 | 874 | "(highway=motorway_link & -oneway=no & -oneway=reversible)"; |
| 838 | 875 | |
| 839 | | try { |
| 840 | | reversedDirectionKeys = SearchCompiler.compile(Main.pref.get("tags.reversed_direction", reversedDirectionDefault)); |
| 841 | | } catch (ParseError e) { |
| 842 | | Main.error("Unable to compile pattern for tags.reversed_direction, trying default pattern: " + e.getMessage()); |
| | 876 | reversedDirectionKeys = compileDirectionKeys("tags.reversed_direction", reversedDirectionDefault); |
| | 877 | directionKeys = compileDirectionKeys("tags.direction", directionDefault); |
| | 878 | } |
| 843 | 879 | |
| 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 | | } |
| | 880 | private static Match compileDirectionKeys(String prefName, String defaultValue) throws AssertionError { |
| 850 | 881 | try { |
| 851 | | directionKeys = SearchCompiler.compile(Main.pref.get("tags.direction", directionDefault)); |
| | 882 | return SearchCompiler.compile(Main.pref.get(prefName, defaultValue)); |
| 852 | 883 | } catch (ParseError e) { |
| 853 | | Main.error("Unable to compile pattern for tags.direction, trying default pattern: " + e.getMessage()); |
| | 884 | Main.error("Unable to compile pattern for " + prefName + ", trying default pattern: " + e.getMessage()); |
| | 885 | } |
| 854 | 886 | |
| 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 | | } |
| | 887 | try { |
| | 888 | return SearchCompiler.compile(defaultValue); |
| | 889 | } catch (ParseError e2) { |
| | 890 | throw new AssertionError("Unable to compile default pattern for direction keys: " + e2.getMessage(), e2); |
| 860 | 891 | } |
| 861 | 892 | } |
| 862 | 893 | |
diff --git a/src/org/openstreetmap/josm/tools/Predicates.java b/src/org/openstreetmap/josm/tools/Predicates.java
index 3dc899b..a70b4f3 100644
|
a
|
b
|
public final class Predicates {
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 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 | */ |
| | 23 | public static <T> Predicate<T> alwaysTrue() { |
| | 24 | return new Predicate<T>() { |
| | 25 | @Override |
| | 26 | public boolean evaluate(T object) { |
| | 27 | return true; |
| | 28 | } |
| | 29 | }; |
| | 30 | } |
| | 31 | |
| | 32 | /** |
| | 33 | * Creates a predicate that returns false every time. |
| | 34 | * @param <T> The type of the predicate. |
| | 35 | * @return A predicate returning <code>false</code> |
| | 36 | */ |
| | 37 | public static <T> Predicate<T> alwaysFalse() { |
| | 38 | return new Predicate<T>() { |
| | 39 | @Override |
| | 40 | public boolean evaluate(T object) { |
| | 41 | return false; |
| | 42 | } |
| | 43 | }; |
| | 44 | } |
| | 45 | |
| | 46 | /** |
| 19 | 47 | * Returns the negation of {@code predicate}. |
| 20 | 48 | * @param <T> type of items |
| 21 | 49 | * @param predicate the predicate to negate |
| … |
… |
public final class Predicates {
|
| 46 | 74 | } |
| 47 | 75 | |
| 48 | 76 | /** |
| | 77 | * Creates a new predicate that checks if elements are exactly of that class. |
| | 78 | * @param <T> The predicate type. |
| | 79 | * @param clazz The class the elements must have. |
| | 80 | * @return A predicate. |
| | 81 | */ |
| | 82 | public static <T> Predicate<T> isOfClass(final Class<? extends T> clazz) { |
| | 83 | return new Predicate<T>() { |
| | 84 | @Override |
| | 85 | public boolean evaluate(T obj) { |
| | 86 | return obj != null && obj.getClass() == clazz; |
| | 87 | } |
| | 88 | }; |
| | 89 | } |
| | 90 | |
| | 91 | /** |
| 49 | 92 | * Returns a {@link Predicate} executing {@link Pattern#matcher(CharSequence)} and {@link java.util.regex.Matcher#matches}. |
| 50 | 93 | * @param pattern the pattern |
| 51 | 94 | * @return a {@link Predicate} executing {@link Pattern#matcher(CharSequence)} and {@link java.util.regex.Matcher#matches} |