Class GenericConverters
java.lang.Object
com.ultikits.ultitools.config.convert.builtin.GenericConverters
- All Implemented Interfaces:
ConfigConverter<Object>
Generic factory categories, their construction policy, and per-element diagnostic boundaries.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanbindsKeyText(Type keyType) Whether a map with this declared key type binds its keys to the file's key text: every key type other thanStringandObject, whose keys are already the text the file holds.private static Objectconstruct(Class<?> raw, ConverterRegistry.Context ctx) fileKeyIndex(ConverterRegistry.Context ctx, Type keyType) Indexes the keys of the map the file holds atctx's location by the typed key each reads back to, throughkeyTypeand the same registry read path the loader uses.fromPlain(Object plain, ConversionContext context) Converts plain data to a Java value.private static StringkeyText(Object plain, Object javaKey, Type keyType, ConverterRegistry.Context keyContext) The text a converted map key is written under.private static Collection<Object> newCollection(Class<?> raw, Type element, ConverterRegistry.Context ctx) newMap(Class<?> raw, Type key, ConverterRegistry.Context ctx) private static voidreadElements(List<?> plain, Type element, ConverterRegistry.Context ctx, Collection<Object> values) private static ObjectreadEnum(Object plain, Class<?> raw, ConverterRegistry.Context ctx) static ConfigConverter<?> static ConfigConverter<?> resolveWrite(Type type) toPlain(Object value, ConversionContext context) Converts a Java value to plain data.writeMap(Map<?, ?> value, ConverterRegistry.Context ctx) Writes each entry under the file's own key text for its key when the file value at this location holds one (the first in file order), else under the key's verified text, and descends into the value under that text so nested maps bind too.
-
Field Details
-
CATALOG
-
INSTANCE
-
-
Constructor Details
-
GenericConverters
private GenericConverters()
-
-
Method Details
-
registeredTypes
- Returns:
- the implementation-owned supported builtin factory categories
-
resolve
- Parameters:
type- the declared type- Returns:
- a generic converter only when its result can be constructed
-
resolveWrite
- Parameters:
type- runtime/declaration type- Returns:
- constructor-free write converter
-
toPlain
Description copied from interface:ConfigConverterConverts a Java value to plain data.- Specified by:
toPlainin interfaceConfigConverter<Object>- Parameters:
value- the Java valuecontext- the immutable conversion location and recursive dispatcher- Returns:
- plain data
- Throws:
ConversionException- when conversion cannot preserve the value
-
writeMap
private static Map<String,Object> writeMap(Map<?, ?> value, ConverterRegistry.Context ctx) throws ConversionExceptionWrites each entry under the file's own key text for its key when the file value at this location holds one (the first in file order), else under the key's verified text, and descends into the value under that text so nested maps bind too.- Throws:
ConversionException
-
fromPlain
Description copied from interface:ConfigConverterConverts plain data to a Java value.- Specified by:
fromPlainin interfaceConfigConverter<Object>- Parameters:
plain- the value read from the documentcontext- the immutable conversion location and recursive dispatcher- Returns:
- the Java value
- Throws:
ConversionException- when the input cannot be converted
-
bindsKeyText
Whether a map with this declared key type binds its keys to the file's key text: every key type other thanStringandObject, whose keys are already the text the file holds.- Parameters:
keyType- declared map key type- Returns:
- whether the key is typed
-
fileKeyIndex
@Internal public static Map<Object,List<String>> fileKeyIndex(ConverterRegistry.Context ctx, Type keyType) Indexes the keys of the map the file holds atctx's location by the typed key each reads back to, throughkeyTypeand the same registry read path the loader uses. Each typed key maps to its file key texts in file order; a file key that does not read as the key type is skipped. Reading a key is a probe, so nothing is recorded in the conversion's failures. The one index behind both the map writer's binding (first spelling wins) and the file-key ambiguity scan (two or more spellings).- Parameters:
ctx- context whose file value is the map to indexkeyType- declared map key type- Returns:
- typed key to its file spellings in file order; empty when the key type is not typed or the file value at this location is not a map
-
keyText
private static String keyText(Object plain, Object javaKey, Type keyType, ConverterRegistry.Context keyContext) throws ConversionException The text a converted map key is written under. A key that converts to text keeps that text. A key that converts to another plain scalar (Integer,Long,Boolean, ...) is written as that scalar's text only when the text reads back, through the declared key type and the same registry path the loader uses, to a key equal to the entry's own; anything else is refused, so a key is never written under a text that loads as a different key. The read-back is a probe and records nothing in the conversion's failures.- Throws:
ConversionException
-
readElements
private static void readElements(List<?> plain, Type element, ConverterRegistry.Context ctx, Collection<Object> values) -
readEnum
private static Object readEnum(Object plain, Class<?> raw, ConverterRegistry.Context ctx) throws ConversionException - Throws:
ConversionException
-
newCollection
private static Collection<Object> newCollection(Class<?> raw, Type element, ConverterRegistry.Context ctx) throws ConversionException - Throws:
ConversionException
-
newMap
private static Map<Object,Object> newMap(Class<?> raw, Type key, ConverterRegistry.Context ctx) throws ConversionException - Throws:
ConversionException
-
construct
private static Object construct(Class<?> raw, ConverterRegistry.Context ctx) throws ConversionException - Throws:
ConversionException
-