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

Last change on this file since 2575 was 2512, checked in by stoecker, 14 years ago

i18n updated, fixed files to reduce problems when applying patches, fix #4017

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