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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddAdapter(Class<?> adapterClass, Object adapter) <U> booleanaddConversion(Type<U> target, Converter<T, U> converter, Type.Relation relation) voidaddVirtual(TypeImpl<?> virtual) Attempts to convert ("parse") the given string input into the data type.<C> Type<C> intCompares two values of this type.boolean<C> CConverts the value of this type to the target type.booleanDo not call equals() to compare types, rather compare their names:type1.getName().equals( type2.getName() )<A> AfindAdapter(Class<A> adapterClass) Returns the type adapter as contributed in hive for this type or its base type.<A> AgetAdapter(Class<A> adapterClass) Returns the type adapter as contributed in hive for this type.@Nullable ObjectReturns 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.intgetSize()TODO in bits? bytes? sometimes a configured 'max value' is returned, for example for 'string' where no fixed length is applicable.Collection<Type<T>> inthashCode()voidbooleanThis only returns true for the boolean type, not for types that are boolean-able.booleanbooleanTells if this value is comparable to another value of the same type usingType.compare(T, T).booleanisConvertibleTo(Type<?> target) Tells if this value is convertible to the target type specified usingType.convertTo(ch.tocco.nice2.types.api.Type<C>, T).booleanbooleanbooleanThis 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.booleanbooleanboolean<U> booleanremoveConversion(Type<U> target) booleanTells 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>.voidMakes 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:TypeThe 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:TypeThis 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:
isChronologicalin interfaceType<T>- Returns:
- Tells if the type is date/time specific.
-
isBoolean
public boolean isBoolean()Description copied from interface:TypeThis 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:TypeTells 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:
shouldBeUniquein interfaceType<T>
-
getRepresentationClass
Description copied from interface:TypeThe class this type represents, for example java.lang.String. Virtual types return the class of the base type.- Specified by:
getRepresentationClassin interfaceType<T>- Returns:
- .
-
getEmptyValue
Description copied from interface:TypeReturns what this type considers to be "empty". Examples are "" for String, 0 for Integer, false for Boolean.- Specified by:
getEmptyValuein interfaceType<T>- Returns:
- Null if the type does not support it, for example for Date.
-
cast
- Specified by:
castin interfaceType<T>- Throws:
UnsupportedTypeOperationException
-
unsafe
Description copied from interface:TypeCasts this type toType<Object>. -
asString
-
asObject
Description copied from interface:TypeAttempts 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:
asObjectin 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:TypeReturns the value so that future changes to the value won't write through to the returned value. -
isVirtual
public boolean isVirtual() -
getBaseType
- Specified by:
getBaseTypein interfaceType<T>
-
getVirtualTypes
- Specified by:
getVirtualTypesin interfaceType<T>
-
validate
Description copied from interface:TypeMakes sure the value is in the given type and range.nullis usually accepted. For example the type 'serial' doesn't just check for a number, but also for a non-negative number.- Specified by:
validatein interfaceType<T>- Throws:
ValidationException- See Also:
-
isValid
-
convertTo
Description copied from interface:TypeConverts the value of this type to the target type.- Specified by:
convertToin 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:TypeTells 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:
isConvertibleToin interfaceType<T>- Parameters:
target- The target type to which to convert to.- See Also:
-
getRelationTo
- Specified by:
getRelationToin interfaceType<T>
-
isComparable
public boolean isComparable()Description copied from interface:TypeTells if this value is comparable to another value of the same type usingType.compare(T, T).- Specified by:
isComparablein interfaceType<T>- See Also:
-
compare
Description copied from interface:TypeCompares two values of this type. For example the String class could use left.compareToIgnoreCase(right); -
isEqual
-
isMatchable
public boolean isMatchable()- Specified by:
isMatchablein interfaceType<T>
-
matches
-
contains
-
getSize
public int getSize()Description copied from interface:TypeTODO 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:TypeReturns 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:
getAdapterin interfaceType<T>- Returns:
nullif no such type adapter for that type was contributed.- See Also:
-
findAdapter
Description copied from interface:TypeReturns 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:
findAdapterin interfaceType<T>- Returns:
nullif 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:
getGenerationTypein 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()
-