quoggles.stdboxes.listoperations1
Class ListOperations1_Box

java.lang.Object
  |
  +--quoggles.boxes.Box
        |
        +--quoggles.stdboxes.listoperations1.ListOperations1_Box
All Implemented Interfaces:
IBox

public class ListOperations1_Box
extends Box

FLATTEN:

Input: an object

Output: null if the input has been null. If the input is a collection, a flat structure of that collection is returned (this flattenig is applied recursively)

From its hierarchical input (a Collection holding Collections), a flat structure is retrieved.

Example: If the input is a list of the form

[ [A1, A2], B, [C1, A1, C2] ]

then the result list will look like this:

[ A1, A2, B, C1, A1, C2 ]

null values are removed.

The order will be preserved (if the given Collectionss guarantee an order).

Duplicates are not removed.

null as input is passed on.

A non-collection input is put into a one element list.

LISTIFY:

Input: one or several collections

Output: a list where the i'th element is a list made up from the i'th elements in the input lists (in the order of the inputs).

MAKEDISINCT:

Input: a collection of objects of arbitrary types

Output: a collection containing the input elements, without any duplicates (tested using equals).

REVERSE:

Input: an Object or a Collection

Output: a Collection with the same elemenst as the input Collection with the order of the elements reversed. If the input is not a Collection, the input object is returned untouched.

DELISTIFY:

Reverses LISTIFY.

Input: a collection (of collections of size == number of outputs of the box

Output: Input is a collection of tuples. All tuples must have same size s. Box must have s outputs. Output number i produces a list of the i^th elements of the tuples.

UNPACK:

Similar to DELISTIFY; for one input tuple.

Input: a collection #nrOutputs objects

Output: Input is one tuple of size s. Box must have s outputs. Output number i produces the i^th element of the tuple.


Field Summary
private  org.graffiti.plugin.parameter.Parameter chooseOp
           
private  java.util.Collection inputCol
          Used if one input
private  java.util.Collection[] inputCols
          Used if several inputs
private  int longestInput
          Used by listify operation
private  int nrInputs
          Number of inputs
private  int nrOutputs
          Number of outputs
private  java.lang.Object singleInput
          Only set if input is not a collection
 
Fields inherited from class quoggles.boxes.Box
boxExecuted, iBoxGRep, inputs, outputs, parameters
 
Constructor Summary
ListOperations1_Box()
           
 
Method Summary
 void execute()
          Should be overridden and called first by subclasses.
private  java.lang.Object flatten(java.lang.Object in)
          Flattens a hierarchical structure.
 IBoxRepresentation getGraphicalRepresentation()
          This implementation returns a new instance of DefaultBoxRepresentation.
 int[] getInputTypes()
          This implementation returns ONE element, the most general type.
 int getNumberOfInputs()
          Returns the number of inputs this box expects.
 int getNumberOfOutputs()
          Returns the number of outputs this box provides.
 int[] getOutputTypes()
          Override this method to specify more restricted types for the output(s) of the box.
 void setInputs(java.lang.Object[] inputs)
          Checks if the number of inputs is correct and sets the inputs.
 void setParameters(org.graffiti.plugin.parameter.Parameter[] pars, boolean fromRep)
          Sets the parameters and - if needed - sets them in the graphical representation.
 
Methods inherited from class quoggles.boxes.Box
areAllInputsNull, getClassName, getId, getNode, getOutputAt, getOutputs, getParameters, hasBeenExecuted, ignoreBox, isGraphicalRepNull, isInputSet, isInputSetAt, needsQueryRunner, removeNullValues, reset, reset, setBoxNumber, setCurrentNodesTodo, setCurrentResult, setDefaultParameters, setIgnoreBox, setInputAt, setNode, setQueryRunner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleInput

private java.lang.Object singleInput
Only set if input is not a collection


inputCols

private java.util.Collection[] inputCols
Used if several inputs


inputCol

private java.util.Collection inputCol
Used if one input


nrInputs

private int nrInputs
Number of inputs


nrOutputs

private int nrOutputs
Number of outputs


longestInput

private int longestInput
Used by listify operation


chooseOp

private org.graffiti.plugin.parameter.Parameter chooseOp
Constructor Detail

ListOperations1_Box

public ListOperations1_Box()
Method Detail

execute

public void execute()
             throws QueryExecutionException
Description copied from class: Box
Should be overridden and called first by subclasses. Throws InputNotSetException if the inputSet flag indicates the no input has been set for this box. May throw other QueryExecutionExceptions. The implementation of this abstract sets the output to be equal to the input.

Specified by:
execute in interface IBox
Overrides:
execute in class Box
QueryExecutionException
See Also:
IBox.execute()

flatten

private java.lang.Object flatten(java.lang.Object in)
Flattens a hierarchical structure.

Parameters:
in - the object to flatten
Returns:
Collection that does not hold any Collection as element; the input object itself if it had not been a collection

getNumberOfInputs

public int getNumberOfInputs()
Description copied from class: Box
Returns the number of inputs this box expects. This implementation returns the length of the input types array.

Specified by:
getNumberOfInputs in interface IBox
Overrides:
getNumberOfInputs in class Box
See Also:
IBox.getNumberOfInputs()

getNumberOfOutputs

public int getNumberOfOutputs()
Description copied from class: Box
Returns the number of outputs this box provides. This implementation returns the length of the output types array.

Specified by:
getNumberOfOutputs in interface IBox
Overrides:
getNumberOfOutputs in class Box
See Also:
IBox.getNumberOfOutputs()

setParameters

public void setParameters(org.graffiti.plugin.parameter.Parameter[] pars,
                          boolean fromRep)
Description copied from class: Box
Sets the parameters and - if needed - sets them in the graphical representation. Subclasses need not override this method. Just assign your parameters to the protected field parameters.

Specified by:
setParameters in interface IBox
Overrides:
setParameters in class Box
See Also:
IBox.setParameters(org.graffiti.plugin.parameter.Parameter[], boolean)

getInputTypes

public int[] getInputTypes()
Description copied from class: Box
This implementation returns ONE element, the most general type. Override this method to specify more restricted types for the input(s) of the box. The size of the returned array must be consistent with the return value of getNumberOfInputs.

Specified by:
getInputTypes in interface IBox
Overrides:
getInputTypes in class Box
See Also:
IBox.getInputTypes()

getOutputTypes

public int[] getOutputTypes()
Description copied from class: Box
Override this method to specify more restricted types for the output(s) of the box. The size of the returned array must be consistent with the return value of getNumberOfOutputs. This implementation returns the same as a call to getInputTypes yields.

Specified by:
getOutputTypes in interface IBox
Overrides:
getOutputTypes in class Box
See Also:
IBox.getOutputTypes()

setInputs

public void setInputs(java.lang.Object[] inputs)
               throws InvalidInputException
Description copied from class: Box
Checks if the number of inputs is correct and sets the inputs. Subclasses probably will want to override this method to avoid many casts necessary when working with the input array. They should however first call this method (via super.setInputs(inputs)) so that consistency checks are done and some flags are correctly set.

Specified by:
setInputs in interface IBox
Overrides:
setInputs in class Box
InvalidInputException
See Also:
IBox.setInputs(java.lang.Object[])

getGraphicalRepresentation

public IBoxRepresentation getGraphicalRepresentation()
Description copied from class: Box
This implementation returns a new instance of DefaultBoxRepresentation. If your subclass has any parameters, you will probably have to design your own representation and override this method for example as follows: if (iBoxGRep == null || !(iBoxGRep instanceof MYOWNBOX_Rep)) { iBoxGRep = new MYOWNBOX_Rep(this); } return iBoxGRep;

Specified by:
getGraphicalRepresentation in interface IBox
Overrides:
getGraphicalRepresentation in class Box
See Also:
IBox.getGraphicalRepresentation()