public static class MapCSSStyleSource.MapCSSRuleIndex extends Object
MapCSSRule
s, that are indexed by tag key and value.
Speeds up the process of finding all rules that match a certain primitive.
Rules with a Condition.SimpleKeyValueCondition
[key=value] or rules that require a specific key to be set are
indexed. Now you only need to loop the tags of a primitive to retrieve the possibly matching rules.
To use this index, you need to add(MapCSSRule)
all rules to it. You then need to call
initIndex()
. Afterwards, you can use getRuleCandidates(OsmPrimitive)
to get an iterator over
all rules that might be applied to that primitive.Modifier and Type | Class and Description |
---|---|
private static class |
MapCSSStyleSource.MapCSSRuleIndex.MapCSSKeyRules
This is a map of all rules that are only applied if the primitive has a given key (and possibly value)
|
private class |
MapCSSStyleSource.MapCSSRuleIndex.RuleCandidatesIterator
This is an iterator over all rules that are marked as possible in the bitset.
|
Modifier and Type | Field and Description |
---|---|
private Map<String,MapCSSStyleSource.MapCSSRuleIndex.MapCSSKeyRules> |
index
All rules that only apply when the given key is present.
|
private BitSet |
remaining
Rules that do not require any key to be present.
|
private List<MapCSSRule> |
rules
All rules this index is for.
|
Constructor and Description |
---|
MapCSSRuleIndex() |
Modifier and Type | Method and Description |
---|---|
void |
add(MapCSSRule rule)
Add a rule to this index.
|
void |
clear()
Clear the index.
|
private static boolean |
conditionRequiresKeyPresence(Condition.KeyMatchType matchType) |
private String |
findAnyRequiredKey(List<Condition> conds)
Search for any key that condition might depend on.
|
private MapCSSStyleSource.MapCSSRuleIndex.MapCSSKeyRules |
getEntryInIndex(String key) |
Iterator<MapCSSRule> |
getRuleCandidates(OsmPrimitive osm)
Get a subset of all rules that might match the primitive.
|
void |
initIndex()
Initialize the index.
|
private final List<MapCSSRule> rules
private final Map<String,MapCSSStyleSource.MapCSSRuleIndex.MapCSSKeyRules> index
public MapCSSRuleIndex()
public void add(MapCSSRule rule)
initIndex()
is called.rule
- The rule to add.public void initIndex()
You must own the write lock of STYLE_SOURCE_LOCK when calling this method.
private String findAnyRequiredKey(List<Condition> conds)
conds
- The conditions to search through.null
if there is no such key.private static boolean conditionRequiresKeyPresence(Condition.KeyMatchType matchType)
private MapCSSStyleSource.MapCSSRuleIndex.MapCSSKeyRules getEntryInIndex(String key)
public Iterator<MapCSSRule> getRuleCandidates(OsmPrimitive osm)
You must have a read lock of STYLE_SOURCE_LOCK when calling this method.
osm
- the primitive to matchpublic void clear()
You must own the write lock STYLE_SOURCE_LOCK when calling this method.