Class MapCSSRuleIndex
- java.lang.Object
-
- org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRuleIndex
-
public class MapCSSRuleIndex extends java.lang.Object
A collection ofMapCSSRule
s, that are indexed by tag key and value. Speeds up the process of finding all rules that match a certain primitive. Rules with aConditionFactory.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 toadd(MapCSSRule)
all rules to it. You then need to callinitIndex()
. Afterwards, you can usegetRuleCandidates(IPrimitive)
to get an iterator over all rules that might be applied to that primitive.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
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
MapCSSRuleIndex.RuleCandidatesIterator
This is an iterator over all rules that are marked as possible in the bitset.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,MapCSSRuleIndex.MapCSSKeyRules>
index
All rules that only apply when the given key is present.private java.util.BitSet
remaining
Rules that do not require any key to be present.private java.util.List<MapCSSRule>
rules
All rules this index is for.private static java.util.EnumSet<ConditionFactory.KeyMatchType>
VALID_INDEX_KEY_TYPES
Valid key types for indexing (seeConditionFactory.KeyMatchType
)
-
Constructor Summary
Constructors Constructor Description MapCSSRuleIndex()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(MapCSSRule rule)
Add a rule to this index.void
clear()
Clear the index.private static java.lang.String
findAnyRequiredKey(java.util.List<Condition> conds)
Search for any key that condition might depend on.private MapCSSRuleIndex.MapCSSKeyRules
getEntryInIndex(java.lang.String key)
java.util.Iterator<MapCSSRule>
getRuleCandidates(IPrimitive osm)
Get a subset of all rules that might match the primitive.void
initIndex()
Initialize the index.boolean
isEmpty()
Check if this index is empty.
-
-
-
Field Detail
-
VALID_INDEX_KEY_TYPES
private static final java.util.EnumSet<ConditionFactory.KeyMatchType> VALID_INDEX_KEY_TYPES
Valid key types for indexing (seeConditionFactory.KeyMatchType
)
-
rules
private final java.util.List<MapCSSRule> rules
All rules this index is for. Once this index is built, this list is sorted.
-
index
private final java.util.Map<java.lang.String,MapCSSRuleIndex.MapCSSKeyRules> index
All rules that only apply when the given key is present.
-
-
Constructor Detail
-
MapCSSRuleIndex
public MapCSSRuleIndex()
-
-
Method Detail
-
add
public void add(MapCSSRule rule)
Add a rule to this index. This needs to be called beforeinitIndex()
is called.- Parameters:
rule
- The rule to add.
-
initIndex
public void initIndex()
Initialize the index.You must own the write lock of STYLE_SOURCE_LOCK when calling this method.
-
findAnyRequiredKey
private static java.lang.String findAnyRequiredKey(java.util.List<Condition> conds)
Search for any key that condition might depend on.- Parameters:
conds
- The conditions to search through.- Returns:
- An arbitrary key this rule depends on or
null
if there is no such key.
-
getEntryInIndex
private MapCSSRuleIndex.MapCSSKeyRules getEntryInIndex(java.lang.String key)
-
getRuleCandidates
public java.util.Iterator<MapCSSRule> getRuleCandidates(IPrimitive osm)
Get a subset of all rules that might match the primitive. Rules not included in the result are guaranteed to not match this primitive.You must have a read lock of STYLE_SOURCE_LOCK when calling this method.
- Parameters:
osm
- the primitive to match- Returns:
- An iterator over possible rules in the right order.
- Since:
- 13810 (signature)
-
clear
public void clear()
Clear the index.You must own the write lock STYLE_SOURCE_LOCK when calling this method.
-
isEmpty
public boolean isEmpty()
Check if this index is empty.- Returns:
- true if this index is empty.
- Since:
- 16784
-
-