Class MapCSSRuleIndex
- java.lang.Object
-
- org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRuleIndex
-
public class MapCSSRuleIndex extends java.lang.Object
A collection ofMapCSSRules, 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 classMapCSSRuleIndex.MapCSSKeyRulesThis is a map of all rules that are only applied if the primitive has a given key (and possibly value)private classMapCSSRuleIndex.RuleCandidatesIteratorThis 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>indexAll rules that only apply when the given key is present.private java.util.BitSetremainingRules that do not require any key to be present.private java.util.List<MapCSSRule>rulesAll rules this index is for.private static java.util.EnumSet<ConditionFactory.KeyMatchType>VALID_INDEX_KEY_TYPESValid 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 voidadd(MapCSSRule rule)Add a rule to this index.voidclear()Clear the index.private static java.lang.StringfindAnyRequiredKey(java.util.List<Condition> conds)Search for any key that condition might depend on.private MapCSSRuleIndex.MapCSSKeyRulesgetEntryInIndex(java.lang.String key)java.util.Iterator<MapCSSRule>getRuleCandidates(IPrimitive osm)Get a subset of all rules that might match the primitive.voidinitIndex()Initialize the index.booleanisEmpty()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
nullif 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
-
-