org.openstreetmap.josm.data.osm
Class FilterMatcher

java.lang.Object
  extended by 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. Uses SearchCompiler.Match#match 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
private static class FilterMatcher.FilterInfo
           
static class FilterMatcher.FilterType
          Describes quality of the filtering.
 
Field Summary
private  java.util.List<FilterMatcher.FilterInfo> disabledFilters
           
private  java.util.List<FilterMatcher.FilterInfo> hiddenFilters
           
 
Constructor Summary
FilterMatcher()
           
 
Method Summary
private  boolean allParentMultipolygonsFiltered(OsmPrimitive primitive, boolean hidden)
           
private  boolean allParentWaysFiltered(OsmPrimitive primitive, boolean hidden)
          Check if all parent ways are filtered.
 FilterMatcher.FilterType isDisabled(OsmPrimitive primitive)
          Check if primitive is disabled.
private  boolean isFiltered(OsmPrimitive primitive, boolean hidden)
          Check if primitive is filtered.
private  boolean isFilterExplicit(OsmPrimitive primitive, boolean hidden)
          Check if primitive is hidden explicitly.
 FilterMatcher.FilterType isHidden(OsmPrimitive primitive)
          Check if primitive is hidden.
private  boolean oneParentMultipolygonNotFiltered(OsmPrimitive primitive, boolean hidden)
           
private  boolean oneParentWayNotFiltered(OsmPrimitive primitive, boolean hidden)
           
private  FilterMatcher.FilterType test(java.util.List<FilterMatcher.FilterInfo> filters, OsmPrimitive primitive, boolean hidden)
           
 void update(java.util.Collection<Filter> filters)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 SearchCompiler.ParseError
Throws:
SearchCompiler.ParseError

isFiltered

private boolean isFiltered(OsmPrimitive primitive,
                           boolean hidden)
Check if primitive is filtered.

Parameters:
primitive - the primitive to check
hidden - 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 boolean isFilterExplicit(OsmPrimitive primitive,
                                 boolean hidden)
Check if primitive is hidden explicitly. Only used for ways and relations.

Parameters:
primitive - the primitive to check
hidden - the level where the check is performed
Returns:
true, if at least one non-inverted filter applies to the primitive

allParentWaysFiltered

private boolean allParentWaysFiltered(OsmPrimitive primitive,
                                      boolean hidden)
Check if all parent ways are filtered.

Parameters:
primitive - the primitive to check
hidden - 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 boolean oneParentWayNotFiltered(OsmPrimitive primitive,
                                        boolean hidden)

allParentMultipolygonsFiltered

private boolean allParentMultipolygonsFiltered(OsmPrimitive primitive,
                                               boolean hidden)

oneParentMultipolygonNotFiltered

private boolean oneParentMultipolygonNotFiltered(OsmPrimitive primitive,
                                                 boolean hidden)

test

private FilterMatcher.FilterType test(java.util.List<FilterMatcher.FilterInfo> filters,
                                      OsmPrimitive primitive,
                                      boolean hidden)

isHidden

public FilterMatcher.FilterType isHidden(OsmPrimitive primitive)
Check if primitive is hidden. The filter flags for all parent objects must be set correctly, when calling this method.

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 FilterMatcher.FilterType isDisabled(OsmPrimitive primitive)
Check if primitive is disabled. The filter flags for all parent objects must be set correctly, when calling this method.

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


JOSM