Class ConverterRegistry.Context

java.lang.Object
com.ultikits.ultitools.config.convert.ConverterRegistry.Context
All Implemented Interfaces:
ConversionContext
Enclosing class:
ConverterRegistry

@Internal public static final class ConverterRegistry.Context extends Object implements ConversionContext
  • Field Details

    • registry

      private final ConverterRegistry registry
    • file

      private final String file
    • path

      private final List<String> path
    • type

      private final Type type
    • failures

      private final List<ConversionFailure> failures
    • fileValue

      private final Object fileValue
      The plain value the file holds at path, or null when unknown. Writes carry it so a typed map key can be written under the file's own key text; reads never use it.
    • fileEntriesByText

      private Map<String,Object> fileEntriesByText
      The entries of the file map at this location by their key text, first in map order; built once, on the first lookup that misses an exact key, so binding every key of a map visits its file entries once, not once per key (PR #687 local Codex run 2).
  • Constructor Details

  • Method Details

    • readSerializable

      public Object readSerializable(Object plain, Class<? extends org.bukkit.configuration.serialization.ConfigurationSerializable> factory) throws ConversionException
      Applies the ordinary registered hierarchy before delegate-aware Bukkit fallback.
      Parameters:
      plain - nested tagged map
      factory - registered alias factory
      Returns:
      hydrated value
      Throws:
      ConversionException - on alias conversion failure
    • file

      public String file()
      Specified by:
      file in interface ConversionContext
      Returns:
      the configuration file's module-relative name
    • path

      public List<String> path()
      Specified by:
      path in interface ConversionContext
      Returns:
      an immutable list of whole path segments
    • declaredType

      public Type declaredType()
      Specified by:
      declaredType in interface ConversionContext
      Returns:
      the declared Java type, including generic arguments
    • toPlain

      public Object toPlain(Object nested) throws ConversionException
      Description copied from interface: ConversionContext
      Converts a nested Java value using its runtime type and the same registry.
      Specified by:
      toPlain in interface ConversionContext
      Parameters:
      nested - the nested Java value
      Returns:
      plain data
      Throws:
      ConversionException - when conversion fails
    • fromPlain

      public <V> V fromPlain(Object nested, Type declared) throws ConversionException
      Description copied from interface: ConversionContext
      Converts a nested document value through the same registry.
      Specified by:
      fromPlain in interface ConversionContext
      Type Parameters:
      V - the result type
      Parameters:
      nested - the nested document value
      declared - the declared nested Java type
      Returns:
      the converted nested value
      Throws:
      ConversionException - when conversion fails
    • writeTyped

      public Object writeTyped(Object value, Type declared) throws ConversionException
      Parameters:
      value - nested Java value
      declared - nested type
      Returns:
      plain data
      Throws:
      ConversionException - on failure
    • readTyped

      public <V> V readTyped(Object value, Type declared) throws ConversionException
      Type Parameters:
      V - result type
      Parameters:
      value - nested plain value
      declared - nested type
      Returns:
      converted value
      Throws:
      ConversionException - on failure
    • child

      public ConverterRegistry.Context child(String segment, Type declared)
      The nested context carries the file's value at the nested location: the entry under segment when the file value is a map, the element at that index when it is a list and segment is an index, else none.
      Parameters:
      segment - whole key or index
      declared - nested type
      Returns:
      nested context
    • fileValue

      @Internal public Object fileValue()
      Returns:
      the plain value the file holds at this context's location, or null when unknown; a probe and every read carry none
    • probe

      @Internal public ConverterRegistry.Probe probe(Object plain, Type declared)
      Reads plain as declared through the same registry path the loader uses, at this context's location, without recording anything in this conversion's failure list: a refusal, or any nested omission, goes to a throw-away list and makes the probe fail. Used to check that a map key's text reads back to the key it was written from, and to index the keys a file holds.
      Parameters:
      plain - document value to read
      declared - type to read it as
      Returns:
      the read value, or a failed probe; never throws a conversion failure
    • record

      public void record(Object raw, ConversionException cause)
      Parameters:
      raw - refused input
      cause - failure at its original nested location
    • failure

      public ConversionException failure(String reason, Throwable cause)
      Parameters:
      reason - failure description
      cause - underlying failure
      Returns:
      checked located failure
    • fileEntry

      private Object fileEntry(String segment)
      The file's value under segment: the entry whose key is exactly that text, else the first entry in map order whose key reads as that text, through the index built once per map.
    • entriesByText

      private static Map<String,Object> entriesByText(Map<?,?> entries)
      entries by key text (String.valueOf), keeping the first entry in map order for each text.