Skip to content

Commit a851d02

Browse files
committed
quick geometry type lookup by name without not found error
1 parent 777fb2e commit a851d02

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/main/java/mil/nga/sf/GeometryType.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package mil.nga.sf;
22

3+
import java.util.HashMap;
34
import java.util.Locale;
5+
import java.util.Map;
46

57
/**
68
* Geometry Type enumeration
@@ -113,6 +115,16 @@ public enum GeometryType {
113115
*/
114116
TRIANGLE;
115117

118+
/**
119+
* Name to type mapping for fast find attempts
120+
*/
121+
private static final Map<String, GeometryType> types = new HashMap<>();
122+
static {
123+
for (GeometryType type : values()) {
124+
types.put(type.name(), type);
125+
}
126+
}
127+
116128
/**
117129
* Get the name, just use the enum name since they are the same
118130
*
@@ -142,14 +154,7 @@ public static GeometryType fromName(String name) {
142154
* @since 2.0.2
143155
*/
144156
public static GeometryType findName(String name) {
145-
GeometryType type = null;
146-
for (GeometryType geometryType : GeometryType.values()) {
147-
if (geometryType.name().equalsIgnoreCase(name)) {
148-
type = geometryType;
149-
break;
150-
}
151-
}
152-
return type;
157+
return types.get(name.toUpperCase(Locale.US));
153158
}
154159

155160
}

0 commit comments

Comments
 (0)