Class 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 Detail

      • Sink

        public Sink()
    • 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
      • 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