Changeset 13803 in josm
- Timestamp:
- 2018-05-21T14:15:26+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveComparator.java
r13569 r13803 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import static java.util.Comparator.comparing;5 import static java.util.Comparator.comparingInt;6 7 4 import java.util.Comparator; 8 import java.util.HashMap;9 import java.util.Map;10 import java.util.function.Function;11 12 import org.openstreetmap.josm.tools.AlphanumComparator;13 5 14 6 /** 15 * Comparators for comparing primitives. 7 * Comparators for comparing {@link OsmPrimitive}. 8 * @since 4113 16 9 */ 17 10 public final class OsmPrimitiveComparator { … … 25 18 */ 26 19 public static Comparator<OsmPrimitive> comparingNames() { 27 final Comparator<String> digitsLast = comparing(str -> !str.isEmpty() && Character.isDigit(str.charAt(0)) ? 1 : 0); 28 return comparing(memoize(DefaultNameFormatter.getInstance()::format), 29 digitsLast.thenComparing(AlphanumComparator.getInstance())); 20 return PrimitiveComparator.doComparingNames(); 30 21 } 31 22 … … 36 27 */ 37 28 public static Comparator<OsmPrimitive> comparingUniqueId() { 38 return comparing(OsmPrimitive::getUniqueId);29 return PrimitiveComparator.doComparingUniqueId(); 39 30 } 40 31 … … 45 36 */ 46 37 public static Comparator<OsmPrimitive> orderingNodesWaysRelations() { 47 return comparingInt(osm -> osm.getType().ordinal());38 return PrimitiveComparator.doOrderingNodesWaysRelations(); 48 39 } 49 40 … … 54 45 */ 55 46 public static Comparator<OsmPrimitive> orderingWaysRelationsNodes() { 56 return comparingInt(osm -> { 57 switch (osm.getType()) { 58 case WAY: 59 return 1; 60 case RELATION: 61 return 2; 62 case NODE: 63 return 3; 64 default: 65 throw new IllegalStateException(); 66 } 67 }); 47 return PrimitiveComparator.doOrderingWaysRelationsNodes(); 68 48 } 69 49 … … 75 55 */ 76 56 public static Comparator<OsmPrimitive> orderingRelationsWaysNodes() { 77 return comparingInt(osm -> { 78 switch (osm.getType()) { 79 case RELATION: 80 return 1; 81 case WAY: 82 return 2; 83 case NODE: 84 return 3; 85 default: 86 throw new IllegalStateException(); 87 } 88 }); 89 } 90 91 private static <T, R> Function<T, R> memoize(Function<T, R> base) { 92 final Map<T, R> cache = new HashMap<>(); 93 return t -> cache.computeIfAbsent(t, base); 57 return PrimitiveComparator.doOrderingRelationsWaysNodes(); 94 58 } 95 59
Note:
See TracChangeset
for help on using the changeset viewer.