uk.me.parabola.mkgmap.osmstyle
Class RuleIndex

java.lang.Object
  extended by uk.me.parabola.mkgmap.osmstyle.RuleIndex

public class RuleIndex
extends java.lang.Object

An index to reduce the number of rules that have to be executed.

Only the first term (after rearrangement) of the rule is used in the index. This will (currently) always be an EQUALS or EXISTS (A=B or A=*).

We look at the tags of the element and pick out all rules that have the first term that matches the tag=value and tag=*, this is done by a single lookup for each tag in the element (on average a low number such as 3).

So if the element had the one tag highway=primary and the rules were as follows:

 1  surface=good { ... }
 2  highway=secondary { set fence=no; }
 3  highway=primary { set surface=good; }
 4  highway=* & abc=yes { }
 5  surface=good { }
 6  oneway=yes & highway=primary { }
 
We would select rules 3 and 4. No other rule can match initially. But there is a further issue; if rule 3 matched it could set the surface tag. So we also need to select rule 5. Rule 1 can not be matched because it occurs before the rule that sets the tag, so it is not included. All this is precomputed when the index is created, so we can still do a single lookup.

So the full set of rules that we need to match is 3, 4 and 5. If rule 5 itself sets a tag, then we might have to add more rules and so on.

Author:
Steve Ratcliffe

Constructor Summary
RuleIndex()
           
 
Method Summary
 void addRuleToIndex(uk.me.parabola.mkgmap.osmstyle.RuleDetails rd)
          Save the rule and maintains several lists related to it from the other information that is supplied.
 java.util.List<uk.me.parabola.mkgmap.osmstyle.RuleDetails> getRuleDetails()
           
 Rule[] getRules()
          Get all the rules that have been added.
 java.util.List<java.lang.Integer> getRulesForTag(java.lang.String tagval)
          Get a list of rules that might be matched by this tag.
 void prepare()
          Prepare the index for use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuleIndex

public RuleIndex()
Method Detail

addRuleToIndex

public void addRuleToIndex(uk.me.parabola.mkgmap.osmstyle.RuleDetails rd)
Save the rule and maintains several lists related to it from the other information that is supplied.

Parameters:
rd - Contains 1) the keystring which is the key into the index. 2) the rule itself. 3) a list of the tags that might be changed by this rule, should it be matched.

getRules

public Rule[] getRules()
Get all the rules that have been added. This is used in the RuleSet for looking up by number.

Returns:
The rules as an array for quick lookup.

getRulesForTag

public java.util.List<java.lang.Integer> getRulesForTag(java.lang.String tagval)
Get a list of rules that might be matched by this tag.

Parameters:
tagval - The tag and its value eg highway=primary.
Returns:
A list of rules, it may contain duplicates. It appears to be faster just to skip duplicates, rather than using sets to ensure that there are none for example. If there are no rules then null will be returned.

prepare

public void prepare()
Prepare the index for use. This involves merging in all the possible rules that could be run as a result of actions changing tags.


getRuleDetails

public java.util.List<uk.me.parabola.mkgmap.osmstyle.RuleDetails> getRuleDetails()