Package space.arim.dazzleconf.serialiser
Interface FlexibleType
public interface FlexibleType
A type which may be adapted to some other. Inbuilt type conversion is extended by the
All methods throw
ValueSerialisers. All methods throw
BadValueException if type conversion failed at some point.- Author:
- A248
-
Method Summary
Modifier and TypeMethodDescriptiondefault BadValueException.BuilderHelper method to begin creating aBadValueExceptionwhich describes this value.Gets the key associated with this flexible type.booleanGets the value as a booleanbytegetByte()Gets the value as a bytecharGets the value as a characterGets the value as a collection of further flexible types.<E> Collection<E>getCollection(FlexibleTypeFunction<? extends E> elementProcessor) Gets the value as a collection of further flexible types (getCollection()) and processes it by converting each flexible type element to a result element.doubleGets the value as a double<T extends Enum<T>>
TGets the value as an enum typefloatgetFloat()Gets the value as a floatintGets the value as an integergetList()Gets the value as a list of further flexible types.<E> List<E>getList(FlexibleTypeFunction<? extends E> elementProcessor) Gets the value as a list of further flexible types (getList()) and processes it by converting each flexible type element to a result element.longgetLong()Gets the value as a longgetMap()Gets the value as a map of further flexible types.<K,V> Map<K, V> getMap(FlexibleTypeMapEntryFunction<? extends K, ? extends V> entryProcessor) Gets the value as a map of further flexible types (getMap()) and processes it by converting each pair of flexible types to a map entry.<T> TGets this type as some arbitrary object.getSet()Gets the value as a set of further flexible types.<E> Set<E>getSet(FlexibleTypeFunction<? extends E> elementProcessor) Gets the value as a set of further flexible types (getSet()) and processes it by converting each flexible type element to a result element.shortgetShort()Gets the value as a shortGets the value as a string
-
Method Details
-
getAssociatedKey
String getAssociatedKey()Gets the key associated with this flexible type. This is not necessarily the key this object is actually located at. Rather, the associated key is intended to inform the user where the error took place. The returned string may be an absolute key path; its exact details are not specified.
UsebadValueExceptionBuilder()to include the key inBadValueExceptions- Returns:
- the informative key for this flexible type
-
badValueExceptionBuilder
Helper method to begin creating aBadValueExceptionwhich describes this value. UsesgetAssociatedKey()- Returns:
- an exception builder for
BadValueExceptionwith the key already set
-
getString
Gets the value as a string- Returns:
- the string
- Throws:
BadValueException- if type conversion failed
-
getBoolean
Gets the value as a boolean- Returns:
- the boolean
- Throws:
BadValueException- if type conversion failed
-
getByte
Gets the value as a byte- Returns:
- the byte
- Throws:
BadValueException- if type conversion failed
-
getShort
Gets the value as a short- Returns:
- the short
- Throws:
BadValueException- if type conversion failed
-
getInteger
Gets the value as an integer- Returns:
- the integer
- Throws:
BadValueException- if type conversion failed
-
getLong
Gets the value as a long- Returns:
- the long
- Throws:
BadValueException- if type conversion failed
-
getFloat
Gets the value as a float- Returns:
- the float
- Throws:
BadValueException- if type conversion failed
-
getDouble
Gets the value as a double- Returns:
- the double
- Throws:
BadValueException- if type conversion failed
-
getCharacter
Gets the value as a character- Returns:
- the character
- Throws:
BadValueException- if type conversion failed
-
getEnum
Gets the value as an enum type- Type Parameters:
T- the enum type- Parameters:
enumClass- the enum class- Returns:
- the enum value
- Throws:
BadValueException- if conversion to the enum failedNullPointerException- ifenumClassis null
-
getList
Gets the value as a list of further flexible types. This operation may fail if the underlying config value is not a collection andConfigurationOptions.createSingleElementCollections()isfalse.- Returns:
- the list of flexible types
- Throws:
BadValueException- if this value cannot be made into a list
-
getList
Gets the value as a list of further flexible types (getList()) and processes it by converting each flexible type element to a result element.- Type Parameters:
E- the element type- Parameters:
elementProcessor- the processor to convert elements- Returns:
- the list result
- Throws:
BadValueException- if the list cannot be made or any flexible type cannot be made into a resultNullPointerException- ifelementProcessoris null
-
getSet
Gets the value as a set of further flexible types. This operation may fail if the underlying config value is not a collection andConfigurationOptions.createSingleElementCollections()isfalse.- Returns:
- the set of flexible types
- Throws:
BadValueException- if this value cannot be made into a set
-
getSet
Gets the value as a set of further flexible types (getSet()) and processes it by converting each flexible type element to a result element.- Type Parameters:
E- the element type- Parameters:
elementProcessor- the processor to convert elements- Returns:
- the set result
- Throws:
BadValueException- if the set cannot be made or any flexible type cannot be made into a resultNullPointerException- ifelementProcessoris null
-
getCollection
Gets the value as a collection of further flexible types. This operation may fail if the underlying config value is not a collection andConfigurationOptions.createSingleElementCollections()isfalse.- Returns:
- the collection of flexible types
- Throws:
BadValueException- if this value cannot be made into a collection
-
getCollection
<E> Collection<E> getCollection(FlexibleTypeFunction<? extends E> elementProcessor) throws BadValueException Gets the value as a collection of further flexible types (getCollection()) and processes it by converting each flexible type element to a result element.- Type Parameters:
E- the element type- Parameters:
elementProcessor- the processor to convert elements- Returns:
- the collection result
- Throws:
BadValueException- if the collection cannot be made or any flexible type cannot be made into a resultNullPointerException- ifelementProcessoris null
-
getMap
Gets the value as a map of further flexible types. This operation may fail if the underlying config value is not a map.- Returns:
- the map of flexible types
- Throws:
BadValueException- if this value cannot be made into a map
-
getMap
<K,V> Map<K,V> getMap(FlexibleTypeMapEntryFunction<? extends K, ? extends V> entryProcessor) throws BadValueExceptionGets the value as a map of further flexible types (getMap()) and processes it by converting each pair of flexible types to a map entry.- Type Parameters:
K- the value typeV- the value type- Parameters:
entryProcessor- the processor to convert map entries- Returns:
- the map result
- Throws:
BadValueException- if the map cannot be made or any flexible type cannot be made into a resultNullPointerException- ifentryProcessoris null
-
getObject
Gets this type as some arbitrary object. This may call other configuredValueSerialisers which have been configured for the defined type.
Ifclazzis String, a primitive, or an enum, this is the same as callinggetString(), the corresponding primitive getter, orgetEnum(Class). Otherwise, the appropriate serializer is used; if none is found,IllDefinedConfigExceptionis thrown.- Type Parameters:
T- the target type of the object- Parameters:
clazz- the target type's class- Returns:
- the object
- Throws:
BadValueException- if type conversion failedIllDefinedConfigException- if no value serializer could be found for the typeNullPointerException- ifclazzis null
-