source: josm/trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java@ 3166

Last change on this file since 3166 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3import static org.openstreetmap.josm.tools.I18n.marktr;
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.text.MessageFormat;
7
8public enum OsmPrimitiveType {
9
10 NODE (marktr("node"), Node.class, NodeData.class),
11 WAY (marktr("way"), Way.class, WayData.class),
12 RELATION (marktr("relation"), Relation.class, RelationData.class);
13
14 private final String apiTypeName;
15 private final Class<? extends OsmPrimitive> osmClass;
16 private final Class<? extends PrimitiveData> dataClass;
17
18 OsmPrimitiveType(String apiTypeName, Class<? extends OsmPrimitive> osmClass, Class<? extends PrimitiveData> dataClass) {
19 this.apiTypeName = apiTypeName;
20 this.osmClass = osmClass;
21 this.dataClass = dataClass;
22 }
23
24 public String getAPIName() {
25 return apiTypeName;
26 }
27
28 public Class<? extends OsmPrimitive> getOsmClass() {
29 return osmClass;
30 }
31
32 public Class<? extends PrimitiveData> getDataClass() {
33 return dataClass;
34 }
35
36 public static OsmPrimitiveType fromApiTypeName(String typeName) {
37 for (OsmPrimitiveType type : OsmPrimitiveType.values()) {
38 if (type.getAPIName().equals(typeName)) return type;
39 }
40 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' is not a valid type name. Got ''{1}''.", "typeName", typeName));
41 }
42
43 public static OsmPrimitiveType from(OsmPrimitive obj) {
44 return from(obj.getClass());
45 }
46
47 public static OsmPrimitiveType from(Class<? extends OsmPrimitive> cls) {
48 if (cls.equals(Node.class)) return NODE;
49 if (cls.equals(Way.class)) return WAY;
50 if (cls.equals(Relation.class)) return RELATION;
51 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' is not an acceptable class. Got ''{1}''.", "cls", cls.toString()));
52 }
53
54 public static OsmPrimitiveType fromData(Class<? extends PrimitiveData> cls) {
55 if (cls.equals(NodeData.class)) return NODE;
56 if (cls.equals(WayData.class)) return WAY;
57 if (cls.equals(RelationData.class)) return RELATION;
58 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' is not an acceptable class. Got ''{1}''.", "cls", cls.toString()));
59 }
60
61 public static OsmPrimitiveType fromData(PrimitiveData data) {
62 return fromData(data.getClass());
63 }
64
65 public static OsmPrimitiveType from(String value) {
66 if (value == null) return null;
67 for (OsmPrimitiveType type: values()){
68 if (type.getAPIName().equalsIgnoreCase(value))
69 return type;
70 }
71 return null;
72 }
73
74 @Override
75 public String toString() {
76 return tr(getAPIName());
77 }
78}
Note: See TracBrowser for help on using the repository browser.