public class FilterMatcher extends java.lang.Object
SearchCompiler.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.Modifier and Type | Class and Description |
---|---|
private static class |
FilterMatcher.FilterInfo |
static class |
FilterMatcher.FilterType
Describes quality of the filtering.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<FilterMatcher.FilterInfo> |
disabledFilters |
private java.util.List<FilterMatcher.FilterInfo> |
hiddenFilters |
Constructor and Description |
---|
FilterMatcher() |
Modifier and Type | Method and Description |
---|---|
void |
add(Filter filter)
Adds a filter to the currently used filters
|
private static boolean |
allParentMultipolygonsFiltered(OsmPrimitive primitive,
boolean hidden) |
private static boolean |
allParentWaysFiltered(OsmPrimitive primitive,
boolean hidden)
Check if all parent ways are filtered.
|
boolean |
hasFilters()
Determines if at least one filter is enabled.
|
FilterMatcher.FilterType |
isDisabled(OsmPrimitive primitive)
Check if primitive is disabled.
|
private static boolean |
isFiltered(OsmPrimitive primitive,
boolean hidden)
Check if primitive is filtered.
|
private static boolean |
isFilterExplicit(OsmPrimitive primitive,
boolean hidden)
Check if primitive is hidden explicitly.
|
FilterMatcher.FilterType |
isHidden(OsmPrimitive primitive)
Check if primitive is hidden.
|
static FilterMatcher |
of(Filter... filters)
Returns a new
FilterMatcher containing the given filters. |
private static boolean |
oneParentMultipolygonNotFiltered(OsmPrimitive primitive,
boolean hidden) |
private static boolean |
oneParentWayNotFiltered(OsmPrimitive primitive,
boolean hidden) |
void |
reset()
Clears the filters in use.
|
private static FilterMatcher.FilterType |
test(java.util.List<FilterMatcher.FilterInfo> filters,
OsmPrimitive primitive,
boolean hidden) |
void |
update(java.util.Collection<Filter> filters)
Clears the current filters, and adds the given filters
|
private final java.util.List<FilterMatcher.FilterInfo> hiddenFilters
private final java.util.List<FilterMatcher.FilterInfo> disabledFilters
public FilterMatcher()
public void update(java.util.Collection<Filter> filters) throws SearchParseError
filters
- the filters to addSearchParseError
- if the search expression in one of the filters cannot be parsedpublic void reset()
public boolean hasFilters()
true
if at least one filter is enabledpublic void add(Filter filter) throws SearchParseError
filter
- the filter to addSearchParseError
- if the search expression in the filter cannot be parsedprivate static boolean isFiltered(OsmPrimitive primitive, boolean hidden)
primitive
- the primitive to checkhidden
- the minimum level required for the primitive to count as filteredprivate static boolean isFilterExplicit(OsmPrimitive primitive, boolean hidden)
primitive
- the primitive to checkhidden
- the level where the check is performedprivate static boolean allParentWaysFiltered(OsmPrimitive primitive, boolean hidden)
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 filteredhidden
and
(c) at least one of the parent ways is explicitly filteredprivate static boolean oneParentWayNotFiltered(OsmPrimitive primitive, boolean hidden)
private static boolean allParentMultipolygonsFiltered(OsmPrimitive primitive, boolean hidden)
private static boolean oneParentMultipolygonNotFiltered(OsmPrimitive primitive, boolean hidden)
private static FilterMatcher.FilterType test(java.util.List<FilterMatcher.FilterInfo> filters, OsmPrimitive primitive, boolean hidden)
public FilterMatcher.FilterType isHidden(OsmPrimitive primitive)
primitive
- the primitivepublic FilterMatcher.FilterType isDisabled(OsmPrimitive primitive)
primitive
- the primitivepublic static FilterMatcher of(Filter... filters) throws SearchParseError
FilterMatcher
containing the given filters.filters
- filters to add to the resulting filter matcherFilterMatcher
containing the given filtersSearchParseError
- if the search expression in a filter cannot be parsed