Class AbstractHolderBuilder<T extends Holder>

java.lang.Object
com.tccc.kos.ext.dispense.AbstractHolderBuilder<T>
Direct Known Subclasses:
HolderBuilder

public abstract class AbstractHolderBuilder<T extends Holder> extends Object
Builder for constructing holders and adding them to a nozzle and assembly. This is simply a convenience class to automate the process of linking objects within an assembly which is typically boilerplate code. This builder performs the following simple operations:
  • Creates a holder calling getHolderInstance() which can be overridden to operate on custom Holder subclasses.
  • Adds the specified pump to the holder.
  • Adds the specified pump to the configured Nozzle.
  • Adds the holder to the Assembly with a group name.
This builder can be used to add single holders, but the primary convenience is when iterating over a collection of pumps. When used to construct a collection of holders, the builder supports the use of iterators to build sequences of holders using computed values.

This builder operates on a single nozzle. Use multiple builders in the case of multiple nozzles

Since:
1.0
Version:
2023-11-12
  • Constructor Details

    • AbstractHolderBuilder

      public AbstractHolderBuilder(DispenseAssembly assembly, Nozzle nozzle)
      Create a new builder for the specified assembly and nozzle.
      Parameters:
      assembly - the assembly to add holders to
      nozzle - the nozzle to link pumps to
  • Method Details

    • setNameIterator

      public void setNameIterator(String name, int startIdx, int incIdx)
      Set the holder name iterator to the specified name prefix, starting index and the index increment for each iteration. This will generate a name of the form name# where # is the next index number. For example, setNameIterator("A", 1, 1) will result in names of A1, A2, A3, ... . Similarly, setNameIterator("A", 8, -1) will result in names of A8, A7, A6, ... .
      Parameters:
      name - the prefix for the holder name
      startIdx - the starting holder index number
      incIdx - the amount to adjust startIdx on each iteration
    • setIncrementNameIterator

      public void setIncrementNameIterator(String name, int startIdx)
      Set the holder name iterator to the specified name prefix, starting index and incrementing on each iteration. This is equivalent to setNameIterator(name, startIdx, 1) . The following call setIncrementNameIterator("A", 1) will generate names of A1, A2, A3, ... .
      Parameters:
      name - the prefix for the holder name
      startIdx - the starting holder index number
    • setDecrementNameIterator

      public void setDecrementNameIterator(String name, int startIdx)
      Set the holder name iterator to the specified name prefix, starting index and decrementing on each iteration. This is equivalent to setNameIterator(name, startIdx, -1) . The following call setDecrementNameIterator("A", 8) will generate names of A8, A7, A6, ... .
      Parameters:
      name - the prefix for the holder name
      startIdx - the starting holder index number
    • setNameIterator

      public void setNameIterator(AbstractHolderBuilder.BuilderIterator<String> iterator)
      Set the holder name iterator to the specified BuilderIterator which can return a custom name for each iteration or tick of the iterator. Use ListBuilderIterator or ArrayBuilderIterator to pass collections of names to the iterator.
      Parameters:
      iterator - iterator to return a holder name
    • setNameIterator

      public void setNameIterator(String... names)
      Set the holder name iterator to the specified list of names, which will return the next name in the list for each iteration of the builder.
      Parameters:
      names - list of holder names
    • setPumpIterator

      public void setPumpIterator(List<? extends Pump<?>> pumps)
      Iterator to select the pump to assign to the next holder. Pumps will be processed sequentially starting at the beginning of the list. To process a subset of the list or to change the iteration order, use setPumpIterator(pumps, startIdx, incIdx) .
      Parameters:
      pumps - the pumps to iterate over
    • setPumpIterator

      public void setPumpIterator(List<? extends Pump<?>> pumps, int startIdx, int incIdx)
      Iterator to select the pump to assign to the next holder. The iterator will start at the specified startIdx in the list and increment the list position by the specified incIdx , which allows the list to be processed in forward or reverse order.
      Parameters:
      pumps - the pumps to iterator over
      startIdx - where in the list to start
      incIdx - index increment for next iteration
    • setPumpIterator

      public void setPumpIterator(AbstractHolderBuilder.BuilderIterator<? extends Pump<?>> iterator)
      Iterator to select the pump to assign to the next holder.
      Parameters:
      iterator - the iterator to return the next pump
    • addIterator

      public void addIterator(AbstractHolderBuilder.BuilderIterator<?> iterator)
      Add a generic iterator to the builder. This will not be used internally but the builder will tick the iterator on each iteration, allowing the iterator to perform operations on each iteration of the builder. This can be used to perform custom builder triggered operations.
      Parameters:
      iterator - the iterator to be executed by the builder
    • build

      public T build(String name, Pump<?> pump)
      Build a single holder with the specified name and pump. This will add the holder to the configured nozzle and assembly. The holder will be added to the default group in the assembly.
      Parameters:
      name - the name of the holder
      pump - the pump to add to the holder
      Returns:
      the holder
    • build

      public T build(String name, Pump<?> pump, String group)
      Build a single holder with the specified name, pump and group. This will add the holder to the configured nozzle and assembly. The holder will be added to the named group in the assembly.
      Parameters:
      name - the name of the holder
      pump - the pump to add to the holder
      group - the group the holder should be added to
      Returns:
      the holder
    • buildWater

      public T buildWater(Pump<?> pump)
      Build a single holder for water. Holder name and group will follow standard conventions.
      Parameters:
      pump - the water pump to add to the holder
      Returns:
      the holder
    • buildWater

      public T buildWater(Pump<?> pump, int pos)
      Build a holder for water with the specified position. Useful for devices that have more than one water source. Holder name and group will follow standard conventions.
      Parameters:
      pump - the water pump to add to the holder
      pos - the position of the holder
      Returns:
      the holder
    • buildCarb

      public T buildCarb(Pump<?> pump)
      Build a single holder for carb. Holder name and group will follow standard conventions.
      Parameters:
      pump - the carb pump to add to the holder
      Returns:
      the holder
    • buildCarb

      public T buildCarb(Pump<?> pump, int pos)
      Build a holder for carb with the specified position. Useful for devices that have more than one carb source. Holder name and group will follow standard conventions.
      Parameters:
      pump - the carb pump to add to the holder
      pos - the position of the holder
      Returns:
      the holder
    • buildNutritive

      public T buildNutritive(Pump<?> pump)
      Build a single holder for nutritive sweetener. Holder name and group will follow standard conventions.
      Parameters:
      pump - the nutritive sweetener pump to add to the holder
      Returns:
      the holder
    • buildNutritive

      public T buildNutritive(Pump<?> pump, int pos)
      Build a holder for nutritive sweetener with the specified position. Useful for devices that have more than one nutritive sweetener source. Holder name and group will follow standard conventions.
      Parameters:
      pump - the nutritive sweetener pump to add to the holder
      pos - the position of the holder
      Returns:
      the holder
    • buildNonNutritive

      public T buildNonNutritive(Pump<?> pump)
      Build a single holder for non-nutritive sweetener. Holder name and group will follow standard conventions.
      Parameters:
      pump - the non-nutritive sweetener pump to add to the holder
      Returns:
      the holder
    • buildNonNutritive

      public T buildNonNutritive(Pump<?> pump, int pos)
      Build a holder for non-nutritive sweetener with the specified position. Useful for devices that have more than one non-nutritive sweetener source. Holder name and group will follow standard conventions.
      Parameters:
      pump - the non-nutritive sweetener pump to add to the holder
      pos - the position of the holder
      Returns:
      the holder
    • buildMacro

      public T buildMacro(Pump<?> pump)
      Build a single holder for a macro. Holder name and group will follow standard conventions.
      Parameters:
      pump - the macro pump to add to the holder
      Returns:
      the holder
    • build

      public List<T> build(int count)
      Iterate the builder for the specified count. One holder will be constructed and added to the assembly for each iteration of the builder.
      Parameters:
      count - the number of holders to generate
      Returns:
      the list of holders created
    • build

      public List<T> build(int count, String group)
      Iterate the builder for the specified count. One holder will be constructed and added to the assembly for each iteration of the builder. Each holder will be added to the specified group. This allows holders to be grouped such that UI code can easily identify collections of pumps without needing to rely on the names of the pumps.
      Parameters:
      count - the number of holders to generate
      group - the group to add the holders to
      Returns:
      the list of holders created
    • build

      public List<T> build(int count, String group, int pos)
      Iterate the builder for the specified count. One holder will be constructed and added to the assembly for each iteration of the builder. Each holder will be added to the specified group with the specified position. Group positions are simply a way to gather pumps into multiple collections that have the same group but are ordered. When a position is specified, the effective group name is group.pos . The UI sdk has support for gathering and ordering these groups. This is typically used for Freestyle hardware where there may be multiple shelves of micro pumps. All the micro pumps can be in a group called micros but there can be three of these groups: micros.0, micros.1, micros.2 . This is simply a convention and UI can use any group name semantics that best fits the application needs.
      Parameters:
      count - the number of holders to generate
      group - the group to add the holders to
      pos - the position within the group
      Returns:
      the list of holders created
    • buildMicros

      public List<T> buildMicros(int count, int pos)
      Iterate the builder for the specified count using a group name of mciros . This is a common group name when using the Freestyle extension. For any other group name simply use build(count, group, pos .
      Parameters:
      count - the number of holders to generate
      pos - the position of the micros group
      Returns:
      the list of holders created
    • assemble

      public T assemble(String name, Pump<?> pump, String group)
      Calls getHolderInstance() and then assembles everything. This includes:
      • Adding the pump to the nozzle.
      • Adding the holder to the assembly with the specified group name.
      To perform additional assembly steps, override this method and call super.assemble() to get the holder and then perform any additional steps.

      This is called from all versions of build() . If called from an iterating build, the iterators can be used to fetch current values appropriate for the current interation.

      Parameters:
      name - the name of the holder
      pump - the pump to add to the holder
      group - the group the holder should be added to
      Returns:
    • getHolderInstance

      public abstract T getHolderInstance(com.tccc.kos.core.service.assembly.Assembly assembly, String name, Pump<?> pump)
      Return an instance of a holder with the specified name and pump. Override this to return a Holder instance. To use this builder with different types of holders, override the builder class to add additional attributes required by the new holder type and override this method to construct the holder.
      Parameters:
      assembly - assembly the holder is part of
      name - the name of the holder
      pump - the associated pump
      Returns:
      the newly created holder