Ignore:
Timestamp:
15.01.2012 21:28:46 (4 months ago)
Author:
simon04
Message:

fix #6425 - remotecontrol: make download objects available (e.g., /load_object?objects=n1,w2,r3[&new_layer=false&relation_members=true])

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java

    r3115 r4796  
    33 
    44import java.io.Serializable; 
     5import java.util.regex.Matcher; 
     6import java.util.regex.Pattern; 
    57 
    68public class SimplePrimitiveId implements PrimitiveId, Serializable { 
     
    5759        return type + " " + id; 
    5860    } 
     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    } 
    5981} 
Note: See TracChangeset for help on using the changeset viewer.