Package ch.tocco.nice2.types.impl
Class TypeImpl<T>
java.lang.Object
ch.tocco.nice2.types.impl.TypeImpl<T>
- All Implemented Interfaces:
Type<T>
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.types.api.Type
Type.GenerationType, Type.Relation
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
addAdapter
(Class<?> adapterClass, Object adapter) <U> boolean
addConversion
(Type<U> target, Converter<T, U> converter, Type.Relation relation) void
addVirtual
(TypeImpl<?> virtual) Attempts to convert ("parse") the given string input into the data type.<C> Type
<C> int
Compares two values of this type.boolean
<C> C
Converts the value of this type to the target type.boolean
Do not call equals() to compare types, rather compare their names:type1.getName().equals( type2.getName() )
<A> A
findAdapter
(Class<A> adapterClass) Returns the type adapter as contributed in hive for this type or its base type.<A> A
getAdapter
(Class<A> adapterClass) Returns the type adapter as contributed in hive for this type.@Nullable Object
Returns what this type considers to be "empty".getName()
The name of the type, for example "string", see https://wiki.tocco.ch/wiki/index.php/Nice2-typesgetRelationTo
(Type<?> target) The class this type represents, for example java.lang.String.int
getSize()
TODO in bits? bytes? sometimes a configured 'max value' is returned, for example for 'string' where no fixed length is applicable.Collection
<Type<T>> int
hashCode()
void
boolean
This only returns true for the boolean type, not for types that are boolean-able.boolean
boolean
Tells if this value is comparable to another value of the same type usingType.compare(T, T)
.boolean
isConvertibleTo
(Type<?> target) Tells if this value is convertible to the target type specified usingType.convertTo(ch.tocco.nice2.types.api.Type<C>, T)
.boolean
boolean
boolean
This only returns true for numeric types, not for types that can be used like numbers (boolean).Returns the value so that future changes to the value won't write through to the returned value.boolean
boolean
boolean
<U> boolean
removeConversion
(Type<U> target) boolean
Tells if the values of this type should be unique in their context.toString()
static TypeImpl
<?> uncheckedCreate
(org.slf4j.Logger log, TypeImpl<?> baseType, TypeHandler<?> handler, String name) static TypeImpl
<?> uncheckedCreate
(org.slf4j.Logger log, TypeHandler<?> handler, String name, Class<?> representationClass, int size, boolean comparable, boolean matchable) unsafe()
Casts this type toType<Object>
.void
Makes sure the value is in the given type and range.
-
Constructor Details
-
TypeImpl
public TypeImpl(org.slf4j.Logger log, TypeHandler<T> handler, String name, Class<T> representationClass, int size, boolean comparable, boolean matchable) -
TypeImpl
-
-
Method Details
-
toString
-
uncheckedCreate
public static TypeImpl<?> uncheckedCreate(org.slf4j.Logger log, TypeHandler<?> handler, String name, Class<?> representationClass, int size, boolean comparable, boolean matchable) -
uncheckedCreate
public static TypeImpl<?> uncheckedCreate(org.slf4j.Logger log, TypeImpl<?> baseType, TypeHandler<?> handler, String name) -
getName
Description copied from interface:Type
The name of the type, for example "string", see https://wiki.tocco.ch/wiki/index.php/Nice2-types -
isNumeric
public boolean isNumeric()Description copied from interface:Type
This only returns true for numeric types, not for types that can be used like numbers (boolean). STATUS EXPERIMENTAL: raffi does not see the necessity. -
isChronological
public boolean isChronological()- Specified by:
isChronological
in interfaceType<T>
- Returns:
- Tells if the type is date/time specific.
-
isBoolean
public boolean isBoolean()Description copied from interface:Type
This only returns true for the boolean type, not for types that are boolean-able. This is here to avoid the use of "boolean".equals(getName()). STATUS EXPERIMENTAL: raffi does not see the necessity. -
shouldBeUnique
public boolean shouldBeUnique()Description copied from interface:Type
Tells if the values of this type should be unique in their context.Examples: identifier, counter.
Context can mean: in their entity (db table), together with the business unit.
- Specified by:
shouldBeUnique
in interfaceType<T>
-
getRepresentationClass
Description copied from interface:Type
The class this type represents, for example java.lang.String. Virtual types return the class of the base type.- Specified by:
getRepresentationClass
in interfaceType<T>
- Returns:
- .
-
getEmptyValue
Description copied from interface:Type
Returns what this type considers to be "empty". Examples are "" for String, 0 for Integer, false for Boolean.- Specified by:
getEmptyValue
in interfaceType<T>
- Returns:
- Null if the type does not support it, for example for Date.
-
cast
- Specified by:
cast
in interfaceType<T>
- Throws:
UnsupportedTypeOperationException
-
unsafe
Description copied from interface:Type
Casts this type toType<Object>
. -
asString
-
asObject
Description copied from interface:Type
Attempts to convert ("parse") the given string input into the data type.Example: if your type is 'integer' then an
Integer.valueOf(str)
is executed, and the result is returned on success, or a StringConversionException on failure.- Specified by:
asObject
in interfaceType<T>
- Parameters:
str
- The string to parse into the data type. null-in-null-out.- Returns:
- The value as this type's data type. null-in-null-out.
- Throws:
StringConversionException
- If it does not fit.
-
isolate
Description copied from interface:Type
Returns the value so that future changes to the value won't write through to the returned value. -
isVirtual
public boolean isVirtual() -
getBaseType
- Specified by:
getBaseType
in interfaceType<T>
-
getVirtualTypes
- Specified by:
getVirtualTypes
in interfaceType<T>
-
validate
Description copied from interface:Type
Makes sure the value is in the given type and range.null
is usually accepted. For example the type 'serial' doesn't just check for a number, but also for a non-negative number.- Specified by:
validate
in interfaceType<T>
- Throws:
ValidationException
- See Also:
-
isValid
-
convertTo
Description copied from interface:Type
Converts the value of this type to the target type.- Specified by:
convertTo
in interfaceType<T>
- Parameters:
target
- The target type to which to convert to.value
- The value to convert.- Returns:
- The value in the target type, null-in-null-out.
- Throws:
TypeConversionException
- See Also:
-
isConvertibleTo
Description copied from interface:Type
Tells if this value is convertible to the target type specified usingType.convertTo(ch.tocco.nice2.types.api.Type<C>, T)
. Basically, this is a synonym togetRelationTo(target)!=Relation.UNRELATED
- Specified by:
isConvertibleTo
in interfaceType<T>
- Parameters:
target
- The target type to which to convert to.- See Also:
-
getRelationTo
- Specified by:
getRelationTo
in interfaceType<T>
-
isComparable
public boolean isComparable()Description copied from interface:Type
Tells if this value is comparable to another value of the same type usingType.compare(T, T)
.- Specified by:
isComparable
in interfaceType<T>
- See Also:
-
compare
Description copied from interface:Type
Compares two values of this type. For example the String class could use left.compareToIgnoreCase(right); -
isEqual
-
isMatchable
public boolean isMatchable()- Specified by:
isMatchable
in interfaceType<T>
-
matches
-
contains
-
getSize
public int getSize()Description copied from interface:Type
TODO in bits? bytes? sometimes a configured 'max value' is returned, for example for 'string' where no fixed length is applicable. also see https://wiki.tocco.ch/wiki/index.php/Nice2-types -
getAdapter
Description copied from interface:Type
Returns the type adapter as contributed in hive for this type.Example:
MyTypeAdapter mta = type.getAdapter(MyTypeAdapter.class);
Use this instead of
Type.findAdapter(java.lang.Class<A>)
if you DO NOT want to fall back to the base type's adapter.- Specified by:
getAdapter
in interfaceType<T>
- Returns:
null
if no such type adapter for that type was contributed.- See Also:
-
findAdapter
Description copied from interface:Type
Returns the type adapter as contributed in hive for this type or its base type.Example:
MyTypeAdapter mta = type.findAdapter(MyTypeAdapter.class);
Use this instead of
Type.getAdapter(java.lang.Class<A>)
if you want to fall back to the base type's adapter.- Specified by:
findAdapter
in interfaceType<T>
- Returns:
null
if no such type adapter for that type nor its base type was contributed.- See Also:
-
initHandler
public void initHandler() -
addVirtual
-
addConversion
-
removeConversion
-
addAdapter
- Returns:
- False if there is already an adapter object for that class set.
-
getGenerationType
- Specified by:
getGenerationType
in interfaceType<T>
- Returns:
- If and how values of this type are automatically generated
-
equals
Do not call equals() to compare types, rather compare their names:type1.getName().equals( type2.getName() )
-
hashCode
public int hashCode()
-