- Timestamp:
- 2015-09-09T13:03:32+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r8735 r8740 27 27 public abstract class AbstractPrimitive implements IPrimitive { 28 28 29 /** 30 * This is a visitor that can be used to loop over the keys/values of this primitive. 31 * 32 * @author Michael Zangl 33 * @since 8740 34 */ 35 public interface KeyValueVisitor { 36 37 /** 38 * This method gets called for every tag received. 39 * 40 * @param key The key 41 * @param value The value 42 */ 43 void visitKeyValue(String key, String value); 44 } 45 29 46 private static final AtomicLong idCounter = new AtomicLong(0); 30 47 … … 477 494 * @return tags of this primitive. Changes made in returned map are not mapped 478 495 * back to the primitive, use setKeys() to modify the keys 496 * @see #visitKeys(KeyValueVisitor) 479 497 */ 480 498 @Override … … 489 507 } 490 508 return result; 509 } 510 511 /** 512 * Calls the visitor for every key/value pair of this primitive. 513 * 514 * @param visitor The visitor to call. 515 * @see #getKeys() 516 * @since 8740 517 */ 518 public void visitKeys(KeyValueVisitor visitor) { 519 final String[] keys = this.keys; 520 if (keys != null) { 521 for (int i = 0; i < keys.length; i += 2) { 522 visitor.visitKeyValue(keys[i], keys[i + 1]); 523 } 524 } 491 525 } 492 526 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r8509 r8740 30 30 import org.openstreetmap.josm.Main; 31 31 import org.openstreetmap.josm.data.Version; 32 import org.openstreetmap.josm.data.osm.AbstractPrimitive.KeyValueVisitor; 32 33 import org.openstreetmap.josm.data.osm.Node; 33 34 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 145 146 * @author Michael Zangl 146 147 */ 147 private final class RuleCandidatesIterator implements Iterator<MapCSSRule> {148 private final class RuleCandidatesIterator implements Iterator<MapCSSRule>, KeyValueVisitor { 148 149 private final BitSet ruleCandidates; 149 150 private int next; … … 151 152 private RuleCandidatesIterator(BitSet ruleCandidates) { 152 153 this.ruleCandidates = ruleCandidates; 153 next = ruleCandidates.nextSetBit(0);154 154 } 155 155 … … 169 169 public void remove() { 170 170 throw new UnsupportedOperationException(); 171 } 172 173 @Override 174 public void visitKeyValue(String key, String value) { 175 MapCSSKeyRules v = index.get(key); 176 if (v != null) { 177 BitSet rs = v.get(value); 178 ruleCandidates.or(rs); 179 } 180 } 181 182 /** 183 * Call this before using the iterator. 184 */ 185 public void prepare() { 186 next = ruleCandidates.nextSetBit(0); 171 187 } 172 188 } … … 318 334 ruleCandidates.or(remaining); 319 335 320 for (Map.Entry<String, String> e : osm.getKeys().entrySet()) { 321 MapCSSKeyRules v = index.get(e.getKey()); 322 if (v != null) { 323 BitSet rs = v.get(e.getValue()); 324 ruleCandidates.or(rs); 325 } 326 } 327 return new RuleCandidatesIterator(ruleCandidates); 336 final RuleCandidatesIterator candidatesIterator = new RuleCandidatesIterator(ruleCandidates); 337 osm.visitKeys(candidatesIterator); 338 candidatesIterator.prepare(); 339 return candidatesIterator; 328 340 } 329 341
Note:
See TracChangeset
for help on using the changeset viewer.