Changeset 4796 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 15.01.2012 21:28:46 (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java
r3115 r4796 3 3 4 4 import java.io.Serializable; 5 import java.util.regex.Matcher; 6 import java.util.regex.Pattern; 5 7 6 8 public class SimplePrimitiveId implements PrimitiveId, Serializable { … … 57 59 return type + " " + id; 58 60 } 61 62 /** 63 * Parses a {@code OsmPrimitiveType} from the string {@code s}. 64 * @param s the string to be parsed, e.g., {@code n1}, {@code node1}, 65 * {@code w1}, {@code way1}, {@code r1}, {@code rel1}, {@code relation1}. 66 * @return the parsed {@code OsmPrimitiveType} 67 * @throws IllegalArgumentException if the string does not match the pattern 68 */ 69 public static SimplePrimitiveId fromString(String s) { 70 final Pattern p = Pattern.compile("((n(ode)?|w(ay)?|r(el(ation)?)?)/?)(\\d+)"); 71 final Matcher m = p.matcher(s); 72 if (m.matches()) { 73 return new SimplePrimitiveId(Long.parseLong(m.group(m.groupCount())), 74 s.charAt(0) == 'n' ? OsmPrimitiveType.NODE 75 : s.charAt(0) == 'w' ? OsmPrimitiveType.WAY 76 : OsmPrimitiveType.RELATION); 77 } else { 78 throw new IllegalArgumentException("The string " + s + " does not match the pattern " + p); 79 } 80 } 59 81 }
Note: See TracChangeset
for help on using the changeset viewer.
