Package ch.tocco.nice2.types.api
Interface Type<T>
- All Known Implementing Classes:
- TypeImpl
public interface Type<T>
- 
Nested Class SummaryNested Classes
- 
Method SummaryModifier and TypeMethodDescriptionAttempts 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.<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()Deprecated.Collection<Type<T>> booleanThis 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 usingcompare(T, T).booleanisConvertibleTo(Type<?> target) Tells if this value is convertible to the target type specified usingconvertTo(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.booleanbooleanbooleanbooleanTells if the values of this type should be unique in their context.unsafe()Casts this type toType<Object>.voidMakes sure the value is in the given type and range.
- 
Method Details- 
getNameString getName()The name of the type, for example "string", see https://wiki.tocco.ch/wiki/index.php/Nice2-types- Returns:
- The lower-case data type name.
 
- 
isNumericboolean isNumeric()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.- Returns:
- Tells if the type is numeric.
 
- 
isChronologicalboolean isChronological()- Returns:
- Tells if the type is date/time specific.
 
- 
isBooleanboolean isBoolean()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.- Returns:
- Tells if the type is boolean.
 
- 
shouldBeUniqueboolean shouldBeUnique()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. 
- 
getRepresentationClassThe class this type represents, for example java.lang.String. Virtual types return the class of the base type.- Returns:
- .
 
- 
getEmptyValueReturns what this type considers to be "empty". Examples are "" for String, 0 for Integer, false for Boolean.- Returns:
- Null if the type does not support it, for example for Date.
 
- 
cast
- 
unsafeCasts this type toType<Object>.
- 
asString- Returns:
- null-in-null-out
 
- 
asObjectAttempts 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.- 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.
 
- 
isolateReturns the value so that future changes to the value won't write through to the returned value.- Returns:
- The given object if immutable, or a defensive copy of the value, or null-in-null-out.
 
- 
isVirtualboolean isVirtual()
- 
getBaseType
- 
getVirtualTypesCollection<Type<T>> getVirtualTypes()
- 
validateMakes 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.- Throws:
- ValidationException
- See Also:
 
- 
isValid- See Also:
 
- 
convertToConverts the value of this type to the target type.- 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:
 
- 
isConvertibleToTells if this value is convertible to the target type specified usingconvertTo(ch.tocco.nice2.types.api.Type<C>, T). Basically, this is a synonym togetRelationTo(target)!=Relation.UNRELATED- Parameters:
- target- The target type to which to convert to.
- See Also:
 
- 
getRelationTo
- 
isComparableboolean isComparable()Tells if this value is comparable to another value of the same type usingcompare(T, T).- See Also:
 
- 
compareCompares two values of this type. For example the String class could use left.compareToIgnoreCase(right);- Returns:
- As usual. Two nulls are equal, otherwise null is considered "smaller". From the java docs: A negative integer, zero, or a positive integer as the right object is greater than, equal to, or less than the left object.
- Throws:
- UnsupportedTypeOperationException- if not- isComparable().
- See Also:
 
- 
isEqual
- 
isMatchableboolean isMatchable()
- 
matches
- 
contains
- 
getSizeDeprecated.Replaced withgetRelationTo(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- Returns:
- The storage size for Java.
 
- 
getAdapterReturns the type adapter as contributed in hive for this type.Example: MyTypeAdapter mta = type.getAdapter(MyTypeAdapter.class);Use this instead of findAdapter(java.lang.Class<A>)if you DO NOT want to fall back to the base type's adapter.- Returns:
- nullif no such type adapter for that type was contributed.
- See Also:
 
- 
findAdapterReturns 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 getAdapter(java.lang.Class<A>)if you want to fall back to the base type's adapter.- Returns:
- nullif no such type adapter for that type nor its base type was contributed.
- See Also:
 
- 
getGenerationTypeType.GenerationType getGenerationType()- Returns:
- If and how values of this type are automatically generated
 
 
- 
getRelationTo(Type)