java.lang.Object
org.praxislive.code.userapi.Data.Sink<T>
- Type Parameters:
T- type of data
- All Implemented Interfaces:
Lookup.Provider
- Enclosing class:
Data
Data sink to drive pipe graph.
Use
@Inject Sink<TYPE> sink; to create a sink.
By default the pass the same instance of T through the pipe graph. To
create new type T, accumulate values, validate values, etc. provide the
related functions.
Use input() to get a Data.Pipe to link to the sink.
Use process() every time you want to process a graph of T.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidattach(CodeContext<?> context) input()Get the input pipe for this sink.onAccumulate(BinaryOperator<T> accumulator) onClear(UnaryOperator<T> clearer) Function to clear an instance of T when required, at the head of a pipe chain, prior to accumulation, etc.onCreate(UnaryOperator<T> creator) Function to get an instance of T when a new data packet is being created.onValidate(BiPredicate<T, T> validator) Function to validate a source Data.Packet value against a destination Data.Packet value.Process an instance of type T through the data graph.voidreset()Reset all functions and disconnect all sources.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.praxislive.core.Lookup.Provider
getLookup
-
Constructor Details
-
Sink
public Sink()
-
-
Method Details
-
attach
-
reset
public void reset()Reset all functions and disconnect all sources. -
input
Get the input pipe for this sink. The input pipe only supports the addition of sources - it cannot be used as a source.- Returns:
- input pipe
-
process
Process an instance of type T through the data graph. The data returned may not be the same as the data provided, depending on how you have configured the sink, whether you use Data.supply() / Data.apply(), etc.- Parameters:
data- instance of T to process- Returns:
- data of type T (may or may not be the input data)
-
onCreate
Function to get an instance of T when a new data packet is being created. This function is not required to return a new instance. The default onCreate function returns the provided value.- Parameters:
creator- function to get an instance of T- Returns:
- this sink for chaining
-
onClear
Function to clear an instance of T when required, at the head of a pipe chain, prior to accumulation, etc. This might eg. zero out an array or empty a list. The default onClear function does nothing.- Parameters:
clearer- function to clear an instance of T- Returns:
- this sink for chaining
-
onAccumulate
-
onValidate
Function to validate a source Data.Packet value against a destination Data.Packet value. The first argument is the destination, the second the existing source value. If this function returns false then the onCreate function will be called to create a new value for the source Data.Packet Packets from different sinks are always treated as invalid. The default function always returns true.- Parameters:
validator- function to validate source T against destination T- Returns:
- this sink for chaining
-