Class PropertyTypeName
- java.lang.Object
-
- org.gcube.informationsystem.types.PropertyTypeName
-
public class PropertyTypeName extends Object
Represents the type name of a property, including its base type and any generic parameters.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPropertyTypeName.BaseTypeThe fundamental data types for properties.static classPropertyTypeName.BaseTypeGroupGroups of base types.static classPropertyTypeName.SemanticTypeString-overlay semantic types: JSON string values (PropertyTypeName.BaseType.STRINGat the wire level) that carry extra, class-specific validation semantics -- a fixed validation regex and a documented meaning.
-
Field Summary
Fields Modifier and Type Field Description protected static Map<Class<?>,PropertyTypeName.BaseType>BASE_PROPERTY_TYPES_BY_CLASSA map of base types, keyed by class.protected PropertyTypeName.BaseTypebaseTypeThe base type.protected Class<?>clzThe class of the property.static StringGENERIC_NOT_ALLOWED_MESSAGEConstraint on non-collection base types: onlyPropertyTypeName.BaseType.LIST/PropertyTypeName.BaseType.SET/PropertyTypeName.BaseType.MAPmay declare a generic type.protected PropertyTypeName.BaseTypegenericBaseTypeThe generic base type.static StringMAP_KEY_MUST_BE_STRING_MESSAGEConstraint onPropertyTypeName.BaseType.MAP: its key must always bePropertyTypeName.BaseType.STRING.static StringMISSING_GENERIC_TYPE_MESSAGEConstraint onPropertyTypeName.BaseType.LIST/PropertyTypeName.BaseType.SET: the generic type must be declared explicitly (e.g.protected StringnamedTypeNameThe name of the referenced Property-family class, if any --nullfor flat scalars and for collections of a flat scalar.static StringNESTED_COLLECTION_NOT_ALLOWED_MESSAGE_FORMATConstraint onPropertyTypeName.BaseType.LIST/PropertyTypeName.BaseType.SET/PropertyTypeName.BaseType.MAP: their generic/value type must be a non-collection base type -- collections cannot be nested.protected static Map<Class<?>,PropertyTypeName.SemanticType>SEMANTIC_TYPES_BY_CLASSA map of semantic types, keyed by class.protected static Map<String,PropertyTypeName.SemanticType>SEMANTIC_TYPES_BY_CLASS_NAMEA map of semantic types, keyed by class simple name.protected booleanstructuredTypeWhether this type is structured -- a Property-family class reference or a List/Set/Map, as opposed to a flat scalar (String, Integer, Boolean, Date, ...).
-
Constructor Summary
Constructors Constructor Description PropertyTypeName(Class<?> clz)Constructs aPropertyTypeNamefrom aClass.PropertyTypeName(Method method)Constructs aPropertyTypeNamefrom aMethod's return type.PropertyTypeName(String type)Constructs aPropertyTypeNamefrom a string representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)PropertyTypeName.BaseTypegetBaseType()Returns the base type of this property.static PropertyTypeName.BaseTypegetBaseTypeByClass(Class<?> clazz)Determines the correspondingPropertyTypeName.BaseTypefor a given class.PropertyTypeName.BaseTypegetGenericBaseType()Returns the generic base type of this property, if applicable.StringgetNamedTypeName()Returns the simple name of the referenced Property-family class, if any -- direct or as a collection's element type.static StringgetRegexByClass(Class<?> clz)Returns a regular expression for validating the string representation of a given class.static StringgetRegexByClassname(String className)Returns a regular expression for validating the string representation of a given class name.StringgetType()Returns the string representation of this type name.inthashCode()booleanisStructuredType()Checks whether this property type is structured: a direct Property-family class reference (e.g.voidsetType(String type)Sets the type from a string representation.StringtoString()
-
-
-
Field Detail
-
BASE_PROPERTY_TYPES_BY_CLASS
protected static final Map<Class<?>,PropertyTypeName.BaseType> BASE_PROPERTY_TYPES_BY_CLASS
A map of base types, keyed by class.
-
SEMANTIC_TYPES_BY_CLASS
protected static final Map<Class<?>,PropertyTypeName.SemanticType> SEMANTIC_TYPES_BY_CLASS
A map of semantic types, keyed by class.
-
SEMANTIC_TYPES_BY_CLASS_NAME
protected static final Map<String,PropertyTypeName.SemanticType> SEMANTIC_TYPES_BY_CLASS_NAME
A map of semantic types, keyed by class simple name.
-
baseType
protected PropertyTypeName.BaseType baseType
The base type.
-
structuredType
protected boolean structuredType
Whether this type is structured -- a Property-family class reference or a List/Set/Map, as opposed to a flat scalar (String, Integer, Boolean, Date, ...). Does not by itself guaranteenamedTypeNameis set: a scalar-typed collection (e.g.List<Integer>) is structured too, but has no named class to report.
-
genericBaseType
protected PropertyTypeName.BaseType genericBaseType
The generic base type.
-
namedTypeName
protected String namedTypeName
The name of the referenced Property-family class, if any --nullfor flat scalars and for collections of a flat scalar.
-
clz
protected Class<?> clz
The class of the property.
-
MISSING_GENERIC_TYPE_MESSAGE
public static final String MISSING_GENERIC_TYPE_MESSAGE
Constraint onPropertyTypeName.BaseType.LIST/PropertyTypeName.BaseType.SET: the generic type must be declared explicitly (e.g.Set<Property>, not a bareSet).- See Also:
- Constant Field Values
-
GENERIC_NOT_ALLOWED_MESSAGE
public static final String GENERIC_NOT_ALLOWED_MESSAGE
Constraint on non-collection base types: onlyPropertyTypeName.BaseType.LIST/PropertyTypeName.BaseType.SET/PropertyTypeName.BaseType.MAPmay declare a generic type.- See Also:
- Constant Field Values
-
MAP_KEY_MUST_BE_STRING_MESSAGE
public static final String MAP_KEY_MUST_BE_STRING_MESSAGE
Constraint onPropertyTypeName.BaseType.MAP: its key must always bePropertyTypeName.BaseType.STRING.- See Also:
- Constant Field Values
-
NESTED_COLLECTION_NOT_ALLOWED_MESSAGE_FORMAT
public static final String NESTED_COLLECTION_NOT_ALLOWED_MESSAGE_FORMAT
Constraint onPropertyTypeName.BaseType.LIST/PropertyTypeName.BaseType.SET/PropertyTypeName.BaseType.MAP: their generic/value type must be a non-collection base type -- collections cannot be nested. AString.formattemplate, taking the offending base type's name.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PropertyTypeName
public PropertyTypeName(String type)
Constructs aPropertyTypeNamefrom a string representation.- Parameters:
type- The string representation of the type (e.g., "String", "List<Integer>").
-
PropertyTypeName
public PropertyTypeName(Class<?> clz)
Constructs aPropertyTypeNamefrom aClass.- Parameters:
clz- The class of the property.
-
-
Method Detail
-
getRegexByClass
public static String getRegexByClass(Class<?> clz)
Returns a regular expression for validating the string representation of a given class.- Parameters:
clz- The class.- Returns:
- The validation regex, or
nullif none is defined.
-
getRegexByClassname
public static String getRegexByClassname(String className)
Returns a regular expression for validating the string representation of a given class name.- Parameters:
className- The simple name of the class.- Returns:
- The validation regex, or
nullif none is defined.
-
getBaseTypeByClass
public static PropertyTypeName.BaseType getBaseTypeByClass(Class<?> clazz)
Determines the correspondingPropertyTypeName.BaseTypefor a given class.- Parameters:
clazz- The class to check.- Returns:
- The corresponding
BaseType, ornull.
-
setType
public void setType(String type)
Sets the type from a string representation.- Parameters:
type- The string representation of the type.
-
getType
public String getType()
Returns the string representation of this type name.- Returns:
- The type name as a string.
-
getBaseType
public PropertyTypeName.BaseType getBaseType()
Returns the base type of this property.- Returns:
- The base type.
-
isStructuredType
public boolean isStructuredType()
Checks whether this property type is structured: a direct Property-family class reference (e.g.EnumStringProperty), or aList/Set/Map-- as opposed to a flat scalar likeStringorInteger. A structured collection of scalars (e.g.List<Integer>) is stilltruehere even though it has no named class to report -- checkgetNamedTypeName()for that.- Returns:
trueif this type is a Property-family reference or a collection.
-
getGenericBaseType
public PropertyTypeName.BaseType getGenericBaseType()
Returns the generic base type of this property, if applicable.- Returns:
- The generic base type, or
null.
-
getNamedTypeName
public String getNamedTypeName()
Returns the simple name of the referenced Property-family class, if any -- direct or as a collection's element type.nullfor flat scalars and for collections of a flat scalar, even whenisStructuredType()istrue.- Returns:
- The referenced class name, or
null.
-
-