Class AutoFilterRule
- java.lang.Object
-
- org.openstreetmap.josm.gui.autofilter.AutoFilterRule
-
public class AutoFilterRule extends java.lang.Object
An auto filter rule determines how auto filter can be built from visible map data. Several rules can be registered, but only one rule is active at the same time. Rules are identified by the OSM key on which they apply. The dynamic values discovering operates only below a certain zoom level, for performance reasons.- Since:
- 12400
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>allKeysThe union ofkeyand the keys provided bysetExtraKeys(List).private java.util.function.Function<OsmPrimitive,java.util.stream.IntStream>defaultValueSupplierprivate java.lang.Stringkeyprivate intminZoomLevelprivate booleannoValueFilterprivate static BooleanPropertyPROP_AUTO_FILTER_DEFAULTSProperty to determine if the auto filter should assume sensible defaults for values (such as layer=1 for bridge=yes).private java.util.function.ToIntFunction<java.lang.String>valueExtractorprivate java.util.function.IntFunction<java.lang.String>valueFormatter
-
Constructor Summary
Constructors Constructor Description AutoFilterRule(java.lang.String key, int minZoomLevel)Constructs a newAutoFilterRule.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.stream.IntStreamdefaultLayer(OsmPrimitive osm)static AutoFilterRule[]defaultRules()Returns the default list of auto filter rules.AutoFilterRuleenableNoValueFilter()Adds a filter button for OSM primitives which have no value for the key.booleanequals(java.lang.Object o)java.lang.StringformatValue(java.lang.Integer value)Formats the numeric value(package private) static java.util.Optional<AutoFilterRule>getDefaultRule(java.lang.String key)Returns the default auto filter rule for the given keyjava.lang.StringgetKey()Returns the OSM key on which the rule applies.intgetMinZoomLevel()Returns the minimum zoom level at which the rule applies.booleangetNoValueFilter()Returns true if there should be a filter button for OSM primitives which have no value for the key.java.util.stream.IntStreamgetTagValuesForPrimitive(OsmPrimitive osm, boolean directValuesOnly)Returns the numeric values for the given OSM primitiveprivate java.util.stream.IntStreamgetTagValuesForPrimitive(OsmPrimitive osm, java.lang.String key, boolean directValuesOnly)inthashCode()AutoFilterRulesetDefaultValueSupplier(java.util.function.Function<OsmPrimitive,java.util.stream.IntStream> defaultValueSupplier)Sets the function which yields default values for the given OSM primitive.AutoFilterRulesetExtraKeys(java.util.List<java.lang.String> extraKeys)Sets extra OSM keys on which the rule applies in addition to the primary key (getKey()).AutoFilterRulesetValueExtractor(java.util.function.ToIntFunction<java.lang.String> valueExtractor)Sets the function which extracts a numeric value from an OSM valueAutoFilterRulesetValueFormatter(java.util.function.IntFunction<java.lang.String> valueFormatter)Sets a OSM value formatter that defines the associated button label.java.lang.StringtoString()
-
-
-
Field Detail
-
PROP_AUTO_FILTER_DEFAULTS
private static final BooleanProperty PROP_AUTO_FILTER_DEFAULTS
Property to determine if the auto filter should assume sensible defaults for values (such as layer=1 for bridge=yes).
-
key
private final java.lang.String key
-
minZoomLevel
private final int minZoomLevel
-
defaultValueSupplier
private java.util.function.Function<OsmPrimitive,java.util.stream.IntStream> defaultValueSupplier
-
valueExtractor
private java.util.function.ToIntFunction<java.lang.String> valueExtractor
-
valueFormatter
private java.util.function.IntFunction<java.lang.String> valueFormatter
-
noValueFilter
private boolean noValueFilter
-
allKeys
private java.util.List<java.lang.String> allKeys
The union ofkeyand the keys provided bysetExtraKeys(List).
-
-
Constructor Detail
-
AutoFilterRule
public AutoFilterRule(java.lang.String key, int minZoomLevel)
Constructs a newAutoFilterRule.- Parameters:
key- the OSM key on which the rule appliesminZoomLevel- the minimum zoom level at which the rule applies
-
-
Method Detail
-
getKey
public java.lang.String getKey()
Returns the OSM key on which the rule applies.- Returns:
- the OSM key on which the rule applies
-
getMinZoomLevel
public int getMinZoomLevel()
Returns the minimum zoom level at which the rule applies.- Returns:
- the minimum zoom level at which the rule applies
-
getNoValueFilter
public boolean getNoValueFilter()
Returns true if there should be a filter button for OSM primitives which have no value for the key.- Since:
- 19592
-
formatValue
public java.lang.String formatValue(java.lang.Integer value)
Formats the numeric value- Parameters:
value- the numeric value to format- Returns:
- the formatted value
- Since:
- 19592
-
setValueFormatter
public AutoFilterRule setValueFormatter(java.util.function.IntFunction<java.lang.String> valueFormatter)
Sets a OSM value formatter that defines the associated button label.- Parameters:
valueFormatter- OSM value formatter. Cannot be null- Returns:
this- Throws:
java.lang.NullPointerException- ifvalueFormatteris null
-
setDefaultValueSupplier
public AutoFilterRule setDefaultValueSupplier(java.util.function.Function<OsmPrimitive,java.util.stream.IntStream> defaultValueSupplier)
Sets the function which yields default values for the given OSM primitive. This function is invoked if the primitive does not have this key.- Parameters:
defaultValueSupplier- the function which yields default values for the given OSM primitive- Returns:
this- Throws:
java.lang.NullPointerException- ifdefaultValueSupplieris null
-
setValueExtractor
public AutoFilterRule setValueExtractor(java.util.function.ToIntFunction<java.lang.String> valueExtractor)
Sets the function which extracts a numeric value from an OSM value- Parameters:
valueExtractor- the function which extracts a numeric value from an OSM value- Returns:
this- Throws:
java.lang.NullPointerException- ifvalueExtractoris null
-
enableNoValueFilter
public AutoFilterRule enableNoValueFilter()
Adds a filter button for OSM primitives which have no value for the key.
-
setExtraKeys
public AutoFilterRule setExtraKeys(java.util.List<java.lang.String> extraKeys)
Sets extra OSM keys on which the rule applies in addition to the primary key (getKey()). This allows a filter to look at the values of more than one key at the same time.- Parameters:
extraKeys- the list of extra keys, may be empty- Returns:
this- Throws:
java.lang.NullPointerException- ifextraKeysis null- Since:
- 19592
-
getTagValuesForPrimitive
public java.util.stream.IntStream getTagValuesForPrimitive(OsmPrimitive osm, boolean directValuesOnly)
Returns the numeric values for the given OSM primitive- Parameters:
osm- the primitivedirectValuesOnly- whether "inner" values from ranges (such as 6 and 7 for 5-8) should be omitted- Returns:
- a stream of numeric values
- Since:
- 19592
-
getTagValuesForPrimitive
private java.util.stream.IntStream getTagValuesForPrimitive(OsmPrimitive osm, java.lang.String key, boolean directValuesOnly)
-
defaultRules
public static AutoFilterRule[] defaultRules()
Returns the default list of auto filter rules. Plugins can extend the list by registering additional rules.- Returns:
- the default list of auto filter rules
-
getDefaultRule
static java.util.Optional<AutoFilterRule> getDefaultRule(java.lang.String key)
Returns the default auto filter rule for the given key- Parameters:
key- the OSM key- Returns:
- default auto filter rule for the given key
-
defaultLayer
private static java.util.stream.IntStream defaultLayer(OsmPrimitive osm)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-