Package com.tccc.kos.ext.dispense
Class AbstractHolderBuilder<T extends Holder>
java.lang.Object
com.tccc.kos.ext.dispense.AbstractHolderBuilder<T>
- Direct Known Subclasses:
HolderBuilder
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 customHolder
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 operates on a single nozzle. Use multiple builders in the case of multiple nozzles
- Since:
- 1.0
- Version:
- 2023-11-12
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
BuilderIterator
that returns the next value in the array on each iteration.static interface
Iterate a value used during the build process.static class
BuilderIterator
that returns the next value in the list on each iteration. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractHolderBuilder
(DispenseAssembly assembly, Nozzle nozzle) Create a new builder for the specified assembly and nozzle. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIterator
(AbstractHolderBuilder.BuilderIterator<?> iterator) Add a generic iterator to the builder.CallsgetHolderInstance()
and then assembles everything.build
(int count) Iterate the builder for the specified count.Iterate the builder for the specified count.Iterate the builder for the specified count.Build a single holder with the specified name and pump.Build a single holder with the specified name, pump and group.Build a single holder for carb.Build a holder for carb with the specified position.buildMacro
(Pump<?> pump) Build a single holder for a macro.buildMicros
(int count, int pos) Iterate the builder for the specified count using a group name ofmciros
.buildNonNutritive
(Pump<?> pump) Build a single holder for non-nutritive sweetener.buildNonNutritive
(Pump<?> pump, int pos) Build a holder for non-nutritive sweetener with the specified position.buildNutritive
(Pump<?> pump) Build a single holder for nutritive sweetener.buildNutritive
(Pump<?> pump, int pos) Build a holder for nutritive sweetener with the specified position.buildWater
(Pump<?> pump) Build a single holder for water.buildWater
(Pump<?> pump, int pos) Build a holder for water with the specified position.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.void
setDecrementNameIterator
(String name, int startIdx) Set the holder name iterator to the specified name prefix, starting index and decrementing on each iteration.void
setIncrementNameIterator
(String name, int startIdx) Set the holder name iterator to the specified name prefix, starting index and incrementing on each iteration.void
Set the holder name iterator to the specifiedBuilderIterator
which can return a custom name for each iteration or tick of the iterator.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.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.void
setPumpIterator
(AbstractHolderBuilder.BuilderIterator<? extends Pump<?>> iterator) Iterator to select the pump to assign to the next holder.void
setPumpIterator
(List<? extends Pump<?>> pumps) Iterator to select the pump to assign to the next holder.void
setPumpIterator
(List<? extends Pump<?>> pumps, int startIdx, int incIdx) Iterator to select the pump to assign to the next holder.
-
Constructor Details
-
AbstractHolderBuilder
Create a new builder for the specified assembly and nozzle.- Parameters:
assembly
- the assembly to add holders tonozzle
- the nozzle to link pumps to
-
-
Method Details
-
setNameIterator
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 formname#
where#
is the next index number. For example,setNameIterator("A", 1, 1)
will result in names ofA1, A2, A3, ...
. Similarly,setNameIterator("A", 8, -1)
will result in names ofA8, A7, A6, ...
.- Parameters:
name
- the prefix for the holder namestartIdx
- the starting holder index numberincIdx
- the amount to adjuststartIdx
on each iteration
-
setIncrementNameIterator
Set the holder name iterator to the specified name prefix, starting index and incrementing on each iteration. This is equivalent tosetNameIterator(name, startIdx, 1)
. The following callsetIncrementNameIterator("A", 1)
will generate names ofA1, A2, A3, ...
.- Parameters:
name
- the prefix for the holder namestartIdx
- the starting holder index number
-
setDecrementNameIterator
Set the holder name iterator to the specified name prefix, starting index and decrementing on each iteration. This is equivalent tosetNameIterator(name, startIdx, -1)
. The following callsetDecrementNameIterator("A", 8)
will generate names ofA8, A7, A6, ...
.- Parameters:
name
- the prefix for the holder namestartIdx
- the starting holder index number
-
setNameIterator
Set the holder name iterator to the specifiedBuilderIterator
which can return a custom name for each iteration or tick of the iterator. UseListBuilderIterator
orArrayBuilderIterator
to pass collections of names to the iterator.- Parameters:
iterator
- iterator to return a holder name
-
setNameIterator
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
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, usesetPumpIterator(pumps, startIdx, incIdx)
.- Parameters:
pumps
- the pumps to iterate over
-
setPumpIterator
Iterator to select the pump to assign to the next holder. The iterator will start at the specifiedstartIdx
in the list and increment the list position by the specifiedincIdx
, which allows the list to be processed in forward or reverse order.- Parameters:
pumps
- the pumps to iterator overstartIdx
- where in the list to startincIdx
- index increment for next iteration
-
setPumpIterator
Iterator to select the pump to assign to the next holder.- Parameters:
iterator
- the iterator to return the next pump
-
addIterator
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
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 holderpump
- the pump to add to the holder- Returns:
- the holder
-
build
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 holderpump
- the pump to add to the holdergroup
- the group the holder should be added to- Returns:
- the holder
-
buildWater
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
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 holderpos
- the position of the holder- Returns:
- the holder
-
buildCarb
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
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 holderpos
- the position of the holder- Returns:
- the holder
-
buildNutritive
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
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 holderpos
- the position of the holder- Returns:
- the holder
-
buildNonNutritive
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
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 holderpos
- the position of the holder- Returns:
- the holder
-
buildMacro
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
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
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 generategroup
- the group to add the holders to- Returns:
- the list of holders created
-
build
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 isgroup.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 calledmicros
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 generategroup
- the group to add the holders topos
- the position within the group- Returns:
- the list of holders created
-
buildMicros
Iterate the builder for the specified count using a group name ofmciros
. This is a common group name when using the Freestyle extension. For any other group name simply usebuild(count, group, pos
.- Parameters:
count
- the number of holders to generatepos
- the position of the micros group- Returns:
- the list of holders created
-
assemble
CallsgetHolderInstance()
and then assembles everything. This includes:- Adding the pump to the nozzle.
- Adding the holder to the assembly with the specified group name.
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 holderpump
- the pump to add to the holdergroup
- 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 aHolder
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 ofname
- the name of the holderpump
- the associated pump- Returns:
- the newly created holder
-