Merge pull request #51 from DirkMahler/master

[OLINGO-1357] use map to cache EdmPrimitiveTypeKind values for lookup
This commit is contained in:
mibo 2019-05-14 21:09:21 +02:00 committed by GitHub
commit 2a509a3bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions

View File

@ -18,6 +18,10 @@
*/
package org.apache.olingo.commons.api.edm;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Enumeration of all primitive type kinds.
*/
@ -57,6 +61,26 @@ public enum EdmPrimitiveTypeKind {
GeometryMultiPolygon,
GeometryCollection;
private static Map<String, EdmPrimitiveTypeKind> VALUES_BY_NAME;
static {
Map<String, EdmPrimitiveTypeKind> valuesByName = new HashMap<java.lang.String, EdmPrimitiveTypeKind>();
for (EdmPrimitiveTypeKind value : values()) {
valuesByName.put(value.name(), value);
}
VALUES_BY_NAME = Collections.unmodifiableMap(valuesByName);
}
/**
* Get a type kind by name.
*
* @param name The name.
* @return The type kind or <tt>null</tt> if it does not exist.
*/
public static EdmPrimitiveTypeKind getByName(String name) {
return VALUES_BY_NAME.get(name);
}
/**
* Checks if is a geospatial type.
*

View File

@ -109,11 +109,8 @@ public class EdmTypeInfo {
fullQualifiedName = new FullQualifiedName(namespace, typeName);
try {
primitiveType = EdmPrimitiveTypeKind.valueOf(typeName);
} catch (final IllegalArgumentException e) {
primitiveType = null;
}
primitiveType = EdmPrimitiveTypeKind.getByName(typeName);
if (primitiveType == null && edm != null) {
typeDefinition = edm.getTypeDefinition(fullQualifiedName);
if (typeDefinition == null) {