Class MapCSSRuleIndex
java.lang.Object
org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRuleIndex
A collection of
MapCSSRules, that are indexed by tag key and value.
Speeds up the process of finding all rules that match a certain primitive.
Rules with a ConditionFactory.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(IPrimitive) to get an iterator over
all rules that might be applied to that primitive.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classThis is a map of all rules that are only applied if the primitive has a given key (and possibly value)private final classThis is an iterator over all rules that are marked as possible in the bitset. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<String,MapCSSRuleIndex.MapCSSKeyRules> All rules that only apply when the given key is present.private final BitSetRules that do not require any key to be present.private final List<MapCSSRule>All rules this index is for.private static final EnumSet<ConditionFactory.KeyMatchType>Valid key types for indexing (seeConditionFactory.KeyMatchType) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(MapCSSRule rule) Add a rule to this index.voidclear()Clear the index.private static StringfindAnyRequiredKey(List<Condition> conds) Search for any key that condition might depend on.private MapCSSRuleIndex.MapCSSKeyRulesgetEntryInIndex(String key) Get a subset of all rules that might match the primitive.voidInitialize the index.booleanisEmpty()Check if this index is empty.
-
Field Details
-
VALID_INDEX_KEY_TYPES
Valid key types for indexing (seeConditionFactory.KeyMatchType) -
rules
All rules this index is for. Once this index is built, this list is sorted. -
index
All rules that only apply when the given key is present. -
remaining
Rules that do not require any key to be present. Only the index in therulesarray is stored.
-
-
Constructor Details
-
MapCSSRuleIndex
public MapCSSRuleIndex()
-
-
Method Details
-
add
Add a rule to this index. This needs to be called beforeinitIndex()is called.- Parameters:
rule- The rule to add.
-
initIndex
Initialize the index.You must own the write lock of STYLE_SOURCE_LOCK when calling this method.
-
findAnyRequiredKey
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
-
getRuleCandidates
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
Clear the index.You must own the write lock STYLE_SOURCE_LOCK when calling this method.
-
isEmpty
Check if this index is empty.- Returns:
- true if this index is empty.
- Since:
- 16784
-