Adding BasePropertyType to remove OrientDBType
This commit is contained in:
parent
bae57c6ea8
commit
37074ff322
|
@ -0,0 +1,136 @@
|
|||
package org.gcube.informationsystem.types;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||
import org.gcube.informationsystem.utils.TypeVersion;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public enum BasePropertyType {
|
||||
|
||||
BOOLEAN("Boolean"),
|
||||
|
||||
INTEGER("Integer"),
|
||||
|
||||
SHORT("Short"),
|
||||
|
||||
LONG("Long"),
|
||||
|
||||
FLOAT("Float"),
|
||||
|
||||
DOUBLE("Double"),
|
||||
|
||||
DATETIME("Datetime"),
|
||||
|
||||
STRING("String"),
|
||||
|
||||
BINARY("Binary"),
|
||||
|
||||
PROPERTY("Property"),
|
||||
|
||||
PROPERTYLIST("PropertyList"),
|
||||
|
||||
PROPERTYSET("PropertySet"),
|
||||
|
||||
PROPERTYMAP("PropertyMap"),
|
||||
|
||||
BYTE("Byte");
|
||||
|
||||
private String stringValue;
|
||||
|
||||
BasePropertyType(String stringValue) {
|
||||
this.stringValue = stringValue;
|
||||
}
|
||||
|
||||
public String getStringValue() {
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
|
||||
protected static final Map<Class<?>,BasePropertyType> BASE_PROPERTY_TYPES_BY_CLASS;
|
||||
|
||||
static {
|
||||
BASE_PROPERTY_TYPES_BY_CLASS = new HashMap<>();
|
||||
|
||||
// This is made by hand because not all types should be add.
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Boolean.TYPE, BasePropertyType.BOOLEAN);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Boolean.class, BasePropertyType.BOOLEAN);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Integer.TYPE, BasePropertyType.INTEGER);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Integer.class, BasePropertyType.INTEGER);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(BigInteger.class, BasePropertyType.INTEGER);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Short.TYPE, BasePropertyType.SHORT);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Short.class, BasePropertyType.SHORT);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Long.TYPE, BasePropertyType.LONG);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Long.class, BasePropertyType.LONG);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Float.TYPE, BasePropertyType.FLOAT);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Float.class, BasePropertyType.FLOAT);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Double.TYPE, BasePropertyType.DOUBLE);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Double.class, BasePropertyType.DOUBLE);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Date.class, BasePropertyType.DATETIME);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Calendar.class, BasePropertyType.DATETIME);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(String.class, BasePropertyType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Character.TYPE, BasePropertyType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Character.class, BasePropertyType.STRING);
|
||||
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Property.class, BasePropertyType.PROPERTY);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(List.class, BasePropertyType.PROPERTYLIST);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Set.class, BasePropertyType.PROPERTYSET);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Map.class, BasePropertyType.PROPERTYMAP);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte.TYPE, BasePropertyType.BYTE);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte.class, BasePropertyType.BYTE);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(byte[].class, BasePropertyType.BINARY);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Byte[].class, BasePropertyType.BINARY);
|
||||
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(Enum.class, BasePropertyType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(URI.class, BasePropertyType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(URL.class, BasePropertyType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(UUID.class, BasePropertyType.STRING);
|
||||
BASE_PROPERTY_TYPES_BY_CLASS.put(TypeVersion.class, BasePropertyType.STRING);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the correspondent type by checking the "assignability" of the
|
||||
* class received as parameter.
|
||||
*
|
||||
* @param clazz Class to check
|
||||
* @return BasePropertyType instance if found, otherwise null
|
||||
*/
|
||||
public static BasePropertyType getBasePropertyTypeByClass(final Class<?> clazz) {
|
||||
if(clazz == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BasePropertyType type = BASE_PROPERTY_TYPES_BY_CLASS.get(clazz);
|
||||
|
||||
if(type == null && Enum.class.isAssignableFrom(clazz)) {
|
||||
type = BASE_PROPERTY_TYPES_BY_CLASS.get(Enum.class);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue