Changeset 10882 in josm
- Timestamp:
- 2016-08-23T23:34:58+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r10837 r10882 8 8 import java.util.List; 9 9 import java.util.NoSuchElementException; 10 import java.util.function.IntFunction; 11 import java.util.function.IntSupplier; 10 12 import java.util.regex.PatternSyntaxException; 11 13 … … 142 144 } 143 145 146 private <T extends OsmPrimitive> void doVisit(T parent, IntSupplier counter, IntFunction<OsmPrimitive> getter) { 147 // If e.parent is already set to the first matching referrer. 148 // We skip any following referrer injected into the visitor. 149 if (e.parent != null) return; 150 151 if (!left.matches(e.withPrimitive(parent))) 152 return; 153 int count = counter.getAsInt(); 154 if (link.conds == null) { 155 // index is not needed, we can avoid the sequential search below 156 e.parent = parent; 157 e.count = count; 158 return; 159 } 160 for (int i = 0; i < count; i++) { 161 if (getter.apply(i).equals(e.osm) && link.matches(e.withParentAndIndexAndLinkContext(parent, i, count))) { 162 e.parent = parent; 163 e.index = i; 164 e.count = count; 165 return; 166 } 167 } 168 } 169 144 170 @Override 145 171 public void visit(Way w) { 146 /* 147 * If e.parent is already set to the first matching referrer. We skip any following 148 * referrer injected into the visitor. 149 */ 150 if (e.parent != null) return; 151 152 if (!left.matches(e.withPrimitive(w))) 153 return; 154 for (int i = 0; i < w.getNodesCount(); i++) { 155 Node n = w.getNode(i); 156 if (n.equals(e.osm)) { 157 if (link.matches(e.withParentAndIndexAndLinkContext(w, i, w.getNodesCount()))) { 158 e.parent = w; 159 e.index = i; 160 e.count = w.getNodesCount(); 161 return; 162 } 163 } 164 } 172 doVisit(w, w::getNodesCount, w::getNode); 165 173 } 166 174 167 175 @Override 168 176 public void visit(Relation r) { 169 /* 170 * If e.parent is already set to the first matching referrer. We skip any following 171 * referrer injected into the visitor. 172 */ 173 if (e.parent != null) return; 174 175 if (!left.matches(e.withPrimitive(r))) 176 return; 177 for (int i = 0; i < r.getMembersCount(); i++) { 178 RelationMember m = r.getMember(i); 179 if (m.getMember().equals(e.osm)) { 180 if (link.matches(e.withParentAndIndexAndLinkContext(r, i, r.getMembersCount()))) { 181 e.parent = r; 182 e.index = i; 183 e.count = r.getMembersCount(); 184 return; 185 } 186 } 187 } 177 doVisit(r, r::getMembersCount, i -> r.getMember(i).getMember()); 188 178 } 189 179 }
Note:
See TracChangeset
for help on using the changeset viewer.