- java.lang.Object
-
- org.praxislive.code.userapi.Data.Sink<T>
-
- Type Parameters:
T
- type of data
- All Implemented Interfaces:
Lookup.Provider
- Enclosing class:
- Data
public abstract static class Data.Sink<T> extends Object implements Lookup.Provider
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 Constructor Description Sink()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
attach(CodeContext<?> context)
Data.Pipe<T>
input()
Get the input pipe for this sink.Data.Sink<T>
onAccumulate(BinaryOperator<T> accumulator)
Data.Sink<T>
onClear(UnaryOperator<T> clearer)
Function to clear an instance of T when required, at the head of a pipe chain, prior to accumulation, etc.Data.Sink<T>
onCreate(UnaryOperator<T> creator)
Function to get an instance of T when a new data packet is being created.Data.Sink<T>
onValidate(BiPredicate<T,T> validator)
Function to validate a source Data.Packet value against a destination Data.Packet value.T
process(T data)
Process an instance of type T through the data graph.void
reset()
Reset all functions and disconnect all sources.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.praxislive.core.Lookup.Provider
getLookup
-
-
-
-
Method Detail
-
attach
protected void attach(CodeContext<?> context)
-
reset
public void reset()
Reset all functions and disconnect all sources.
-
input
public Data.Pipe<T> 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
public T process(T data)
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
public Data.Sink<T> onCreate(UnaryOperator<T> creator)
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
public Data.Sink<T> onClear(UnaryOperator<T> clearer)
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
public Data.Sink<T> onAccumulate(BinaryOperator<T> accumulator)
-
onValidate
public Data.Sink<T> onValidate(BiPredicate<T,T> validator)
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
-
-