java.lang.Object
com.winterhavenmc.library.messagebuilder.adapters.pipeline.accessors.MacroFieldAccessor
All Implemented Interfaces:
FieldAccessor

public class MacroFieldAccessor extends Object implements FieldAccessor
Default implementation of the FieldAccessor interface that delegates field extraction to the appropriate functional interface based on the adapter type.

The MacroFieldAccessor is responsible for mapping adapted objects (e.g., Nameable, Locatable, Quantifiable, etc.) to their extracted macro string values. These values are inserted into a MacroStringMap, keyed by the supplied ValidMacroKey.

This implementation supports all built-in Accessor types and ensures that the correct extraction method is called based on both the adapter class and the runtime type of the adapted object.

  • Constructor Details

    • MacroFieldAccessor

      public MacroFieldAccessor(AccessorCtx ctx)
      Constructs a new MacroFieldAccessor with the provided context container.
      Parameters:
      ctx - the context container holding formatter and configuration dependencies
  • Method Details

    • extract

      public <T> MacroStringMap extract(ValidMacroKey baseKey, Accessor accessor, T adapted)
      Extracts macro string values from the adapted object using the accessor's corresponding interface, such as Nameable or Locatable.

      If the accessor is recognized and the adapted object is an instance of the expected functional interface, the appropriate extractor method is invoked.

      If no valid match is found for the accessor/object combination, an empty MacroStringMap is returned.

      Specified by:
      extract in interface FieldAccessor
      Type Parameters:
      T - the type of the adapted object
      Parameters:
      baseKey - the base ValidMacroKey representing the placeholder prefix
      accessor - the accessor that was used to adapt the original object
      adapted - the adapted object implementing one of the field interfaces
      Returns:
      a MacroStringMap containing extracted macro values