Class CompositeMetadata

java.lang.Object
dev.jcputney.elearning.parser.output.metadata.CompositeMetadata
All Implemented Interfaces:
MetadataComponent, Serializable

public class CompositeMetadata extends Object implements MetadataComponent
A composite implementation of the MetadataComponent interface that can contain other metadata components.

This class represents a composite node in the composite pattern, containing other metadata components. When queried for metadata, it searches through its child components in order until it finds a match.

See Also:
  • Constructor Details

    • CompositeMetadata

      public CompositeMetadata()
  • Method Details

    • addComponent

      public CompositeMetadata addComponent(@NonNull @NonNull MetadataComponent component)
      Adds a metadata component to this composite.
      Parameters:
      component - The component to add.
      Returns:
      This CompositeMetadata instance for method chaining.
    • addComponents

      public CompositeMetadata addComponents(@NonNull @NonNull List<MetadataComponent> components)
      Adds multiple metadata components to this composite.
      Parameters:
      components - The components to add.
      Returns:
      This CompositeMetadata instance for method chaining.
    • getMetadata

      public Optional<Object> getMetadata(String key)
      Description copied from interface: MetadataComponent
      Gets a metadata value by key.
      Specified by:
      getMetadata in interface MetadataComponent
      Parameters:
      key - The key to look up.
      Returns:
      An Optional containing the value if found, or empty if not found.
    • getMetadata

      public <T> Optional<T> getMetadata(String key, Class<T> type)
      Description copied from interface: MetadataComponent
      Gets a metadata value by key, with type conversion.
      Specified by:
      getMetadata in interface MetadataComponent
      Type Parameters:
      T - The type to convert the value to.
      Parameters:
      key - The key to look up.
      type - The class to convert the value to.
      Returns:
      An Optional containing the converted value if found, or empty if not found.
    • hasMetadata

      public boolean hasMetadata(String key)
      Description copied from interface: MetadataComponent
      Checks if this component contains metadata for the given key.
      Specified by:
      hasMetadata in interface MetadataComponent
      Parameters:
      key - The key to check.
      Returns:
      true if this component contains metadata for the key, false otherwise.
    • getComponents

      public List<MetadataComponent> getComponents()
      Gets all components in this composite.
      Returns:
      A list of all components.