Package org.openstreetmap.josm.data.osm
Class FilterMatcher
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.FilterMatcher
-
public class FilterMatcher extends java.lang.Object
Class that encapsulates the filter logic, i.e. applies a list of filters to a primitive. UsesSearchCompiler.Match.match(org.openstreetmap.josm.data.osm.OsmPrimitive)
to see if the filter expression matches, cares for "inverted-flag" of the filters and combines the results of all active filters. There are two major use cases: (1) Hide features that you don't like to edit but get in the way, e.g.landuse
or power lines. It is expected, that the inverted flag if false for these kind of filters. (2) Highlight certain features, that are currently interesting and hide everything else. This can be thought of as an improved search (Ctrl-F), where you can continue editing and don't loose the current selection. It is expected that the inverted flag of the filter is true in this case. In addition to the formal application of filter rules, some magic is applied to (hopefully) match the expectations of the user: (1) non-inverted: When hiding a way, all its untagged nodes are hidden as well. This avoids a "cloud of nodes", that normally isn't useful without the corresponding way. (2) inverted: When displaying a way, we show all its nodes, although the individual nodes do not match the filter expression. The reason is, that a way without its nodes cannot be edited properly. Multipolygons and (untagged) member ways are handled in a similar way.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
FilterMatcher.FilterInfo
static class
FilterMatcher.FilterType
Describes quality of the filtering.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<FilterMatcher.FilterInfo>
disabledFilters
private java.util.List<FilterMatcher.FilterInfo>
hiddenFilters
-
Constructor Summary
Constructors Constructor Description FilterMatcher()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Filter filter)
Adds a filter to the currently used filtersprivate static boolean
allParentMultipolygonsFiltered(IPrimitive primitive, boolean hidden)
private static <T extends IPrimitive & IFilterablePrimitive>
booleanallParentWaysFiltered(T primitive, boolean hidden)
Check if all parent ways are filtered.boolean
hasFilters()
Determines if at least one filter is enabled.<T extends IPrimitive & IFilterablePrimitive>
FilterMatcher.FilterTypeisDisabled(T primitive)
Check if primitive is disabled.private static boolean
isFiltered(IPrimitive primitive, boolean hidden)
Check if primitive is filtered.private static <T extends IFilterablePrimitive>
booleanisFilterExplicit(T primitive, boolean hidden)
Check if primitive is hidden explicitly.<T extends IPrimitive & IFilterablePrimitive>
FilterMatcher.FilterTypeisHidden(T primitive)
Check if primitive is hidden.static FilterMatcher
of(Filter... filters)
Returns a newFilterMatcher
containing the given filters.private static boolean
oneParentMultipolygonNotFiltered(IPrimitive primitive, boolean hidden)
private static boolean
oneParentWayNotFiltered(IPrimitive primitive, boolean hidden)
void
reset()
Clears the filters in use.private static <T extends IPrimitive & IFilterablePrimitive>
FilterMatcher.FilterTypetest(java.util.List<FilterMatcher.FilterInfo> filters, T primitive, boolean hidden)
void
update(java.util.Collection<Filter> filters)
Clears the current filters, and adds the given filters
-
-
-
Field Detail
-
hiddenFilters
private final java.util.List<FilterMatcher.FilterInfo> hiddenFilters
-
disabledFilters
private final java.util.List<FilterMatcher.FilterInfo> disabledFilters
-
-
Constructor Detail
-
FilterMatcher
public FilterMatcher()
-
-
Method Detail
-
update
public void update(java.util.Collection<Filter> filters) throws SearchParseError
Clears the current filters, and adds the given filters- Parameters:
filters
- the filters to add- Throws:
SearchParseError
- if the search expression in one of the filters cannot be parsed
-
reset
public void reset()
Clears the filters in use.
-
hasFilters
public boolean hasFilters()
Determines if at least one filter is enabled.- Returns:
true
if at least one filter is enabled- Since:
- 14206
-
add
public void add(Filter filter) throws SearchParseError
Adds a filter to the currently used filters- Parameters:
filter
- the filter to add- Throws:
SearchParseError
- if the search expression in the filter cannot be parsed
-
isFiltered
private static boolean isFiltered(IPrimitive primitive, boolean hidden)
Check if primitive is filtered.- Parameters:
primitive
- the primitive to checkhidden
- the minimum level required for the primitive to count as filtered- Returns:
- when hidden is true, returns whether the primitive is hidden when hidden is false, returns whether the primitive is disabled or hidden
-
isFilterExplicit
private static <T extends IFilterablePrimitive> boolean isFilterExplicit(T primitive, boolean hidden)
Check if primitive is hidden explicitly. Only used for ways and relations.- Type Parameters:
T
- The primitive type- Parameters:
primitive
- the primitive to checkhidden
- the level where the check is performed- Returns:
- true, if at least one non-inverted filter applies to the primitive
-
allParentWaysFiltered
private static <T extends IPrimitive & IFilterablePrimitive> boolean allParentWaysFiltered(T primitive, boolean hidden)
Check if all parent ways are filtered.- Type Parameters:
T
- The primitive type- Parameters:
primitive
- the primitive to checkhidden
- parameter that indicates the minimum level of filtering: true when objects need to be hidden to count as filtered and false when it suffices to be disabled to count as filtered- Returns:
- true if (a) there is at least one parent way
(b) all parent ways are filtered at least at the level indicated by the
parameter
hidden
and (c) at least one of the parent ways is explicitly filtered
-
oneParentWayNotFiltered
private static boolean oneParentWayNotFiltered(IPrimitive primitive, boolean hidden)
-
allParentMultipolygonsFiltered
private static boolean allParentMultipolygonsFiltered(IPrimitive primitive, boolean hidden)
-
oneParentMultipolygonNotFiltered
private static boolean oneParentMultipolygonNotFiltered(IPrimitive primitive, boolean hidden)
-
test
private static <T extends IPrimitive & IFilterablePrimitive> FilterMatcher.FilterType test(java.util.List<FilterMatcher.FilterInfo> filters, T primitive, boolean hidden)
-
isHidden
public <T extends IPrimitive & IFilterablePrimitive> FilterMatcher.FilterType isHidden(T primitive)
Check if primitive is hidden. The filter flags for all parent objects must be set correctly, when calling this method.- Type Parameters:
T
- The primitive type- Parameters:
primitive
- the primitive- Returns:
- FilterType.NOT_FILTERED when primitive is not hidden; FilterType.EXPLICIT when primitive is hidden and there is a non-inverted filter that applies; FilterType.PASSIV when primitive is hidden and all filters that apply are inverted
-
isDisabled
public <T extends IPrimitive & IFilterablePrimitive> FilterMatcher.FilterType isDisabled(T primitive)
Check if primitive is disabled. The filter flags for all parent objects must be set correctly, when calling this method.- Type Parameters:
T
- The primitive type- Parameters:
primitive
- the primitive- Returns:
- FilterType.NOT_FILTERED when primitive is not disabled; FilterType.EXPLICIT when primitive is disabled and there is a non-inverted filter that applies; FilterType.PASSIV when primitive is disabled and all filters that apply are inverted
-
of
public static FilterMatcher of(Filter... filters) throws SearchParseError
Returns a newFilterMatcher
containing the given filters.- Parameters:
filters
- filters to add to the resulting filter matcher- Returns:
- a new
FilterMatcher
containing the given filters - Throws:
SearchParseError
- if the search expression in a filter cannot be parsed- Since:
- 12383
-
-