com.univocity.api.io
Class InputQueue<T>

java.lang.Object
  extended by com.univocity.api.io.ReaderProvider
      extended by com.univocity.api.io.InputQueue<T>
All Implemented Interfaces:
ResourceProvider<Reader>
Direct Known Subclasses:
InputFileQueue, InputReaderQueue

public abstract class InputQueue<T>
extends ReaderProvider

A queue of a sequence of inputs to be processed. Inputs can come in all sort of formats, but must be abstracted by a Reader. Variables can be used to assign values to each input and provide more control and information about what the input represents (e.g. date the input was produced, some user ID associated with the input, etc)

Author:
uniVocity Software Pty Ltd - dev@univocity.com
See Also:
InputFileQueue, InputReaderQueue

Constructor Summary
InputQueue()
          Creates an empty queue.
 
Method Summary
 void assignVariablesToLastEntry(Map<String,Object> variables)
          Assigns a set of variables and their values to the last entry added to this input queue
 void assignVariableToLastEntry(String variable, Object value)
          Assigns a variable and its value to the last entry added to this input queue
 Map<String,Object> getCurrentVariables()
          Returns a map of all variables assigned to the input being read
 Reader getResource()
          Grabs the next input of the queue, opens it as an instanceof Reader with the help of method open(Object), loads the variables associated with the input, and returns the Reader.
 boolean isEmpty()
          Queries whether the input is empty (i.e.
protected  void offer(T input)
          Adds an input to be processed to the end of the queue
protected abstract  Reader open(T input)
          Opens an input and returns an instanceof Reader which will be used to consume it.
 T peek()
          Returns the current input at the head of the queue.
 Object readVariable(String variable)
          Returns the value assigned to a given variable associated with the current input being read.
<O> O
readVariable(String variable, Class<O> type)
          Returns the value assigned to a given variable associated with the current input being read.
<O> O
readVariable(String variable, O defaultValue)
          Returns the value assigned to a given variable associated with the current input being read.
 int size()
          Returns the number of inputs to be processed that are waiting in the queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputQueue

public InputQueue()
Creates an empty queue.

Method Detail

isEmpty

public final boolean isEmpty()
Queries whether the input is empty (i.e. all inputs have been processed)

Returns:
true if there are no more inputs to be processed, otherwise false

size

public final int size()
Returns the number of inputs to be processed that are waiting in the queue

Returns:
the queue size

peek

public final T peek()
Returns the current input at the head of the queue.

Returns:
the current input at the head of the queue.

offer

protected final void offer(T input)
Adds an input to be processed to the end of the queue

Parameters:
input - the input to be processed

assignVariableToLastEntry

public void assignVariableToLastEntry(String variable,
                                      Object value)
Assigns a variable and its value to the last entry added to this input queue

Parameters:
variable - the variable name associated to the last input to be processed in this input queue
value - the value to associated to the given variable

assignVariablesToLastEntry

public void assignVariablesToLastEntry(Map<String,Object> variables)
Assigns a set of variables and their values to the last entry added to this input queue

Parameters:
variables - the variable and values associated to the last input to be processed in this input queue

getResource

public final Reader getResource()
Grabs the next input of the queue, opens it as an instanceof Reader with the help of method open(Object), loads the variables associated with the input, and returns the Reader.

Returns:
an instance of Reader to consume the next element of the input queue.

readVariable

public Object readVariable(String variable)
Returns the value assigned to a given variable associated with the current input being read.

Parameters:
variable - the variable name
Returns:
the value of the variable, or null if it doesn't exist

readVariable

public <O> O readVariable(String variable,
                          O defaultValue)
Returns the value assigned to a given variable associated with the current input being read.

Type Parameters:
O - the type of value returned by this method.
Parameters:
variable - the variable name
defaultValue - a default value to return in case the variable doesn't exist or its value is null
Returns:
the value of the variable, or the default value if the variable value evaluates to null

readVariable

public <O> O readVariable(String variable,
                          Class<O> type)
Returns the value assigned to a given variable associated with the current input being read.

Type Parameters:
O - the type of value returned by this method.
Parameters:
variable - the variable name
type - the type of value expected to be returned. The value assigned to this variable will be cast to the given type.
Returns:
the value of the variable, or the default value if the variable value evaluates to null

getCurrentVariables

public Map<String,Object> getCurrentVariables()
Returns a map of all variables assigned to the input being read

Returns:
all variables associated with the current input.

open

protected abstract Reader open(T input)
Opens an input and returns an instanceof Reader which will be used to consume it. Used when getResource() is called.

Parameters:
input - the input to be read
Returns:
Reader that can be used to consume the given input.


Copyright © 2018 uniVocity Software Pty Ltd. All rights reserved.