java.lang.Object
com.winterhavenmc.library.messagebuilder.pipeline.extractor.FieldExtractor
All Implemented Interfaces:
Extractor

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

The FieldExtractor 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 MacroKey.

This implementation supports all built-in Adapter 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

    • FieldExtractor

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

    • extract

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

      If the adapter 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 adapter/object combination, an empty MacroStringMap is returned.

      Specified by:
      extract in interface Extractor
      Type Parameters:
      T - the type of the adapted object
      Parameters:
      baseKey - the base MacroKey representing the placeholder prefix
      adapter - the adapter 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