use of uk.me.parabola.mkgmap.reader.osm.WatchableTypeResult in project mkgmap by openstreetmap.
the class RuleSet method resolveType.
/**
* Resolve the type for this element by running the rules in order.
*
* This is a very performance critical part of the style system as parts
* of the code are run for every tag in the input file.
*
* @param el The element as read from an OSM xml file in 'tag' format.
* @param result A GType describing the Garmin type of the first rule that
* matches is returned here. If continue types are used then more than
* one type may be saved here. If there are no matches then nothing will
* be saved.
*/
public int resolveType(int cacheId, Element el, TypeResult result) {
WatchableTypeResult a = new WatchableTypeResult(result);
if (!compiled || cacheId == Integer.MAX_VALUE)
compile();
// new element, invalidate all caches
cacheId++;
// Get all the rules that could match from the index.
BitSet candidates = new BitSet();
for (Entry<Short, String> tagEntry : el.getFastTagEntryIterator()) {
BitSet rules = index.getRulesForTag(tagEntry.getKey(), tagEntry.getValue());
if (rules != null && !rules.isEmpty())
candidates.or(rules);
}
Rule lastRule = null;
for (int i = candidates.nextSetBit(0); i >= 0; i = candidates.nextSetBit(i + 1)) {
a.reset();
lastRule = rules[i];
cacheId = lastRule.resolveType(cacheId, el, a);
if (a.isResolved())
return cacheId;
}
if (lastRule != null && lastRule.getFinalizeRule() != null) {
if ("true".equals(el.getTag(executeFinalizeRulesTagKey))) {
cacheId = lastRule.getFinalizeRule().resolveType(cacheId, el, a);
}
}
return cacheId;
}
Aggregations