Changeset 6652 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2014-01-06T20:42:32+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Predicates.java
r6592 r6652 3 3 import org.openstreetmap.josm.data.osm.OsmPrimitive; 4 4 5 import java.util.Collection; 5 6 import java.util.regex.Pattern; 6 7 … … 84 85 }; 85 86 } 87 88 /** 89 * Returns a {@link Predicate} executing {@link Collection#contains(Object)}. 90 */ 91 public static <T> Predicate<T> inCollection(final Collection<? extends T> target) { 92 return new Predicate<T>() { 93 @Override 94 public boolean evaluate(T object) { 95 return target.contains(object); 96 } 97 }; 98 } 86 99 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6642 r6652 37 37 import java.util.Arrays; 38 38 import java.util.Collection; 39 import java.util.Collections; 39 40 import java.util.Iterator; 40 41 import java.util.List; … … 861 862 862 863 /** 864 * Returns a human readable representation of a list of positions. 865 * <p/> 866 * For instance, {@code [1,5,2,6,7} yields "1-2,5-7 867 * @param positionList a list of positions 868 * @return a human readable representation 869 */ 870 public static String getPositionListString(List<Integer> positionList) { 871 Collections.sort(positionList); 872 final StringBuilder sb = new StringBuilder(32); 873 sb.append(positionList.get(0)); 874 int cnt = 0; 875 int last = positionList.get(0); 876 for (int i = 1; i < positionList.size(); ++i) { 877 int cur = positionList.get(i); 878 if (cur == last + 1) { 879 ++cnt; 880 } else if (cnt == 0) { 881 sb.append(",").append(cur); 882 } else { 883 sb.append("-").append(last); 884 sb.append(",").append(cur); 885 cnt = 0; 886 } 887 last = cur; 888 } 889 if (cnt >= 1) { 890 sb.append("-").append(last); 891 } 892 return sb.toString(); 893 } 894 895 896 /** 863 897 * Returns a list of capture groups if {@link Matcher#matches()}, or {@code null}. 864 898 * The first element (index 0) is the complete match.
Note:
See TracChangeset
for help on using the changeset viewer.