Class MassBuilder<I,O>

java.lang.Object
me.hsgamer.hscore.builder.MassBuilder<I,O>
Type Parameters:
I - the type of the input
O - the type of the output
Direct Known Subclasses:
Builder, FunctionalMassBuilder

public class MassBuilder<I,O> extends Object
The builder that can build multiple outputs from the input. The build element is a Function that takes the input and returns the Optional output. The Optional output can be empty if the build element cannot build from the input.
  • Constructor Details

    • MassBuilder

      public MassBuilder()
  • Method Details

    • register

      public MassBuilder<I,O> register(Function<I,Optional<O>> element, boolean addFirst)
      Register a new build element
      Parameters:
      element - the element
      addFirst - true if you want to add the element to the first of the list
      Returns:
      this builder for chaining
    • register

      public MassBuilder<I,O> register(Function<I,Optional<O>> element)
      Register a new build element
      Parameters:
      element - the element
      Returns:
      this builder for chaining
    • remove

      public MassBuilder<I,O> remove(Function<I,Optional<O>> element)
      Remove a build element
      Parameters:
      element - the element
      Returns:
      this builder for chaining
    • clear

      public MassBuilder<I,O> clear()
      Clear all the registered build elements
      Returns:
      this builder for chaining
    • buildAll

      public Collection<O> buildAll(I input)
      Build the collection of outputs from the input
      Parameters:
      input - the input
      Returns:
      the collection of outputs
    • build

      public Optional<O> build(I input)
      Build the output from the input. This will find the first build element that can build the input, and return the output. If there is no output, return an empty optional.
      Parameters:
      input - the input
      Returns:
      the output
    • getElements

      public Collection<Function<I,Optional<O>>> getElements()
      Get the registered build elements
      Returns:
      the registered build elements