- Timestamp:
- 2024-04-28T09:37:20+02:00 (10 months ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/IWaySegment.java
r17986 r19065 18 18 */ 19 19 public class IWaySegment<N extends INode, W extends IWay<N>> implements Comparable<IWaySegment<N, W>> { 20 protected static final String NOT_A_SEGMENT = "Node pair is not a single segment of the way!"; 20 21 21 22 private final W way; … … 97 98 * @param second second node 98 99 * @return way segment 99 * @throws IllegalArgumentException if the node pair is not part ofway100 * @throws IllegalArgumentException if the node pair is not a single segment of the way 100 101 */ 101 102 public static <N extends INode, W extends IWay<N>> IWaySegment<N, W> forNodePair(W way, N first, N second) { … … 103 104 while (endIndex > 0) { 104 105 final int indexOfFirst = way.getNodes().subList(0, endIndex).lastIndexOf(first); 106 if (indexOfFirst < 0) 107 break; 105 108 if (second.equals(way.getNode(indexOfFirst + 1))) { 106 109 return new IWaySegment<>(way, indexOfFirst); … … 108 111 endIndex--; 109 112 } 110 throw new IllegalArgumentException( "Node pair is not part of way!");113 throw new IllegalArgumentException(NOT_A_SEGMENT); 111 114 } 112 115 … … 162 165 @Override 163 166 public int compareTo(IWaySegment o) { 167 if (o == null) 168 return -1; 164 169 final W thisWay; 165 170 final IWay<?> otherWay; 166 171 try { 167 172 thisWay = toWay(); 168 otherWay = o == null ? null : o.toWay();173 otherWay = o.toWay(); 169 174 } catch (ReflectiveOperationException e) { 170 175 Logging.error(e); 171 176 return -1; 172 177 } 173 return o == null ? -1 : (equals(o) ? 0 : thisWay.compareTo(otherWay));178 return equals(o) ? 0 : thisWay.compareTo(otherWay); 174 179 } 175 180 -
trunk/src/org/openstreetmap/josm/data/osm/WaySegment.java
r19062 r19065 26 26 * @param second second node 27 27 * @return way segment 28 * @throws IllegalArgumentException if the node pair is not part ofway28 * @throws IllegalArgumentException if the node pair is not single a segment of the way 29 29 */ 30 30 public static WaySegment forNodePair(Way way, Node first, Node second) { … … 32 32 while (endIndex > 0) { 33 33 final int indexOfFirst = way.getNodes().subList(0, endIndex).lastIndexOf(first); 34 if (indexOfFirst < 0) 35 break; 34 36 if (second.equals(way.getNode(indexOfFirst + 1))) { 35 37 return new WaySegment(way, indexOfFirst); … … 37 39 endIndex--; 38 40 } 39 throw new IllegalArgumentException( "The node pair is not consecutive part of the way!");41 throw new IllegalArgumentException(IWaySegment.NOT_A_SEGMENT); 40 42 } 41 43
Note:
See TracChangeset
for help on using the changeset viewer.