Package ch.tocco.nice2.types.api
Interface TypeManager
- All Known Implementing Classes:
TypeManagerImpl
public interface TypeManager
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
<T> T
Attempts to convert any object to the desired target type.void
ensureType
(@Nullable String name) Makes sure the required type exists in the nice system.@Nullable Type
<?> findBaseType
(Class<?> representationClass) Finds theType
for the given java class for one of its ancestors, if any.<T> @Nullable Type
<T> getBaseType
(Class<T> representationClass) Returns theType
for the given java class, if any.Collection
<Type<?>> Returns all available base types (the real ones, without virtual ones).@Nullable Type
<?> Returns the Type (base or virtual) for the name specified.Collection
<Type<?>> getTypes()
Returns all available types (including virtual ones).boolean
Tells if such a type or virtual type exists.Type
<?> matchTypes
(Type<?> one, Type<?> two) TypedValue
<?> parse
(String str, TypeManager.ParseFlags... flags) TypedValue
<?> parse
(String type, String value, TypeManager.ParseFlags... flags) <T> Type
<T> requireBaseType
(Class<T> representationClass) Same asgetBaseType(java.lang.Class<T>)
but throws if missing.Type
<?> requireType
(String name) Same asgetType(java.lang.String)
but throws if missing.@Nullable String
suggestType
(String name) Suggests the correct type name when the one looked for does not exist.
-
Method Details
-
getTypes
Collection<Type<?>> getTypes()Returns all available types (including virtual ones). -
hasType
Tells if such a type or virtual type exists.- Parameters:
name
- The type's name, eg 'string'.
-
getType
Returns the Type (base or virtual) for the name specified. See https://wiki.tocco.ch/wiki/index.php/Nice2-types- Parameters:
name
- The type's name, eg 'string'.- Returns:
- Null if no such type.
- See Also:
-
getBaseTypes
Collection<Type<?>> getBaseTypes()Returns all available base types (the real ones, without virtual ones). -
getBaseType
Returns theType
for the given java class, if any. For the java to type mappings see https://wiki.tocco.ch/wiki/index.php/Nice2-types- Parameters:
representationClass
- The class.- Returns:
- The type. Null if none. Never a virtual type.
- See Also:
-
findBaseType
Finds theType
for the given java class for one of its ancestors, if any. For the java to type mappings see https://wiki.tocco.ch/wiki/index.php/Nice2-types- Parameters:
representationClass
- The class.- Returns:
- The type. Null if none. Never a virtual type.
-
requireType
Same asgetType(java.lang.String)
but throws if missing.- Throws:
NoSuchTypeException
- See Also:
-
requireBaseType
Same asgetBaseType(java.lang.Class<T>)
but throws if missing.- Throws:
NoSuchTypeException
- See Also:
-
parse
- Throws:
StringConversionException
-
parse
TypedValue<?> parse(String type, String value, TypeManager.ParseFlags... flags) throws StringConversionException - Throws:
StringConversionException
-
convert
@Nullable <T> T convert(@Nullable @Nullable Object o, Type<T> targetType) throws TypeConversionException Attempts to convert any object to the desired target type.- Parameters:
o
- The object to convert.- Returns:
- Object as the converted type, null if input was null (null-in-null-out).
- Throws:
TypeConversionException
- If there is no such type converter, or the conversion fails.
-
convert
<T> T convert(@Nullable @Nullable Object o, Type<?> sourceType, Type<T> targetType) throws TypeConversionException - Throws:
TypeConversionException
-
matchTypes
-
getStringType
-
getIntegerType
-
getLongType
-
getDoubleType
-
getBooleanType
-
getGlobType
-
getNullType
-
suggestType
Suggests the correct type name when the one looked for does not exist.Examples are "String" → "string" and "int" → "integer".
If the requested type really exists then the same string is returned, though that's not what this method is meant for.
If the requested type does not look familiar in any way then null is returned.
This method is meant for checking (configuration) input, and telling the implementor quickly what the correct type name is.
- Returns:
- The correct type name, or null.
- See Also:
-
ensureType
Makes sure the required type exists in the nice system.If missing then the desired exception is thrown, along with meaningful text info.
This is useful for config readers etc.
- Parameters:
name
- The type's name, eg 'string'.- Throws:
IllegalArgumentException
-