- Timestamp:
- 2012-11-13T14:19:52+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r5441 r5578 433 433 , GBC.eol()); 434 434 right.add(new SearchKeywordRow(hcbSearchString) 435 .addTitle(tr("relat ions"))435 .addTitle(tr("related objects")) 436 436 .addKeyword("child <i>expr</i>", "child ", tr("all children of objects matching the expression"), "child building") 437 437 .addKeyword("parent <i>expr</i>", "parent ", tr("all parents of objects matching the expression"), "parent bus_stop") 438 .addKeyword("nth:<i>7</i>", "nth: ", tr("n-th member of relation and/or n-th node of way"), "nth:5 (child type:relation)") 439 .addKeyword("nth%:<i>7</i>", "nth: ", tr("every n-th member of relation and/or every n-th node of way"), "nth%:100 (child waterway)") 438 440 , GBC.eol()); 439 441 right.add(new SearchKeywordRow(hcbSearchString) -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r5184 r5578 101 101 "changeset", "nodes", "tags", "areasize", "modified", "selected", 102 102 "incomplete", "untagged", "closed", "new", "indownloadarea", 103 "allindownloadarea", "inview", "allinview", "timestamp" );103 "allindownloadarea", "inview", "allinview", "timestamp", "nth", "nth%"); 104 104 105 105 @Override … … 138 138 else if ("areasize".equals(keyword)) 139 139 return new AreaSize(tokenizer); 140 else if ("nth".equals(keyword)) 141 return new Nth(tokenizer, false); 142 else if ("nth%".equals(keyword)) 143 return new Nth(tokenizer, true); 140 144 else if ("timestamp".equals(keyword)) { 141 145 String rangeS = " " + tokenizer.readTextOrNumber() + " "; // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""}) … … 785 789 @Override public String toString() { 786 790 return "role=" + role; 791 } 792 } 793 794 /** 795 * Matches the n-th object of a relation and/or the n-th node of a way. 796 */ 797 private static class Nth extends Match { 798 799 private final int nth; 800 private final boolean modulo; 801 802 public Nth(PushbackTokenizer tokenizer, boolean modulo) throws ParseError { 803 this((int) tokenizer.readNumber(tr("Primitive id expected")), modulo); 804 } 805 806 private Nth(int nth, boolean modulo) { 807 this.nth = nth; 808 this.modulo = modulo; 809 } 810 811 @Override 812 public boolean match(OsmPrimitive osm) { 813 for (OsmPrimitive p : osm.getReferrers()) { 814 Integer idx = null; 815 if (p instanceof Way) { 816 Way w = (Way) p; 817 idx = w.getNodes().indexOf(osm); 818 } else if (p instanceof Relation) { 819 Relation r = (Relation) p; 820 idx = r.getMemberPrimitivesList().indexOf(osm); 821 } 822 if (idx != null) { 823 if (idx.intValue() == nth || (modulo && idx.intValue() % nth == 0)) { 824 return true; 825 } 826 } 827 } 828 return false; 787 829 } 788 830 } -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r5266 r5578 13 13 import org.openstreetmap.josm.data.osm.visitor.Visitor; 14 14 import org.openstreetmap.josm.tools.CopyList; 15 import org.openstreetmap.josm.tools.Utils; 15 16 16 17 /** … … 395 396 } 396 397 398 public List<OsmPrimitive> getMemberPrimitivesList() { 399 return Utils.transform(getMembers(), new Utils.Function<RelationMember, OsmPrimitive>() { 400 @Override 401 public OsmPrimitive apply(RelationMember x) { 402 return x.getMember(); 403 } 404 }); 405 } 406 397 407 @Override 398 408 public OsmPrimitiveType getType() { -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r5577 r5578 19 19 import java.security.NoSuchAlgorithmException; 20 20 import java.text.MessageFormat; 21 import java.util.AbstractCollection; 22 import java.util.AbstractList; 21 23 import java.util.ArrayList; 22 24 import java.util.Collection; … … 455 457 */ 456 458 public static <A, B> Collection<B> transform(final Collection<? extends A> c, final Function<A, B> f) { 457 return new Collection<B>() {459 return new AbstractCollection<B>() { 458 460 459 461 @Override 460 462 public int size() { 461 463 return c.size(); 462 }463 464 @Override465 public boolean isEmpty() {466 return c.isEmpty();467 }468 469 @Override470 public boolean contains(Object o) {471 return c.contains(o);472 }473 474 @Override475 public Object[] toArray() {476 return c.toArray();477 }478 479 @Override480 public <T> T[] toArray(T[] a) {481 return c.toArray(a);482 }483 484 @Override485 public String toString() {486 return c.toString();487 464 } 488 465 … … 509 486 }; 510 487 } 488 }; 489 } 490 491 /** 492 * Transforms the list {@code l} into an unmodifiable list and 493 * applies the {@link Function} {@code f} on each element upon access. 494 * @param <A> class of input collection 495 * @param <B> class of transformed collection 496 * @param l a collection 497 * @param f a function that transforms objects of {@code A} to objects of {@code B} 498 * @return the transformed unmodifiable list 499 */ 500 public static <A, B> List<B> transform(final List<? extends A> l, final Function<A, B> f) { 501 return new AbstractList<B>() { 502 511 503 512 504 @Override 513 public boolean add(B e) {514 throw new UnsupportedOperationException();505 public int size() { 506 return l.size(); 515 507 } 516 508 517 509 @Override 518 public boolean remove(Object o) { 519 throw new UnsupportedOperationException(); 520 } 521 522 @Override 523 public boolean containsAll(Collection<?> c) { 524 throw new UnsupportedOperationException(); 525 } 526 527 @Override 528 public boolean addAll(Collection<? extends B> c) { 529 throw new UnsupportedOperationException(); 530 } 531 532 @Override 533 public boolean removeAll(Collection<?> c) { 534 throw new UnsupportedOperationException(); 535 } 536 537 @Override 538 public boolean retainAll(Collection<?> c) { 539 throw new UnsupportedOperationException(); 540 } 541 542 @Override 543 public void clear() { 544 throw new UnsupportedOperationException(); 545 } 510 public B get(int index) { 511 return f.apply(l.get(index)); 512 } 513 514 546 515 }; 547 516 }
Note:
See TracChangeset
for help on using the changeset viewer.