1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | public enum OsmPrimitiveType {
|
---|
6 |
|
---|
7 | NODE ("node"),
|
---|
8 | WAY ("way"),
|
---|
9 | RELATION ("relation");
|
---|
10 |
|
---|
11 | private String apiTypeName;
|
---|
12 |
|
---|
13 | OsmPrimitiveType(String apiTypeName) {
|
---|
14 | this.apiTypeName = apiTypeName;
|
---|
15 | }
|
---|
16 |
|
---|
17 | public String getAPIName() {
|
---|
18 | return apiTypeName;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public static OsmPrimitiveType fromApiTypeName(String typeName) {
|
---|
22 | for (OsmPrimitiveType type : OsmPrimitiveType.values()) {
|
---|
23 | if (type.getAPIName().equals(typeName)) return type;
|
---|
24 | }
|
---|
25 | throw new IllegalArgumentException(tr("parameter ''{0}'' is not a valid type name, got ''{1}''", "typeName", typeName));
|
---|
26 | }
|
---|
27 |
|
---|
28 | public static OsmPrimitiveType from(OsmPrimitive obj) {
|
---|
29 | return from(obj.getClass());
|
---|
30 | }
|
---|
31 |
|
---|
32 | public static OsmPrimitiveType from(Class cls) {
|
---|
33 | if (cls.equals(Node.class)) return NODE;
|
---|
34 | if (cls.equals(Way.class)) return WAY;
|
---|
35 | if (cls.equals(Relation.class)) return RELATION;
|
---|
36 | throw new IllegalArgumentException(tr("parameter ''{0}'' is not an acceptable class, got ''{1}''", "cls", cls.toString()));
|
---|
37 | }
|
---|
38 |
|
---|
39 | public static OsmPrimitiveType from(String value) {
|
---|
40 | if (value == null) return null;
|
---|
41 | for (OsmPrimitiveType type: values()){
|
---|
42 | if (type.getAPIName().equalsIgnoreCase(value))
|
---|
43 | return type;
|
---|
44 | }
|
---|
45 | return null;
|
---|
46 | }
|
---|
47 |
|
---|
48 | }
|
---|