quoggles.boxes
Class Box

java.lang.Object
  |
  +--quoggles.boxes.Box
All Implemented Interfaces:
IBox
Direct Known Subclasses:
Algorithm_Box, Arithmetic_Box, AttributeFilter_Box, BooleanNot_Box, BooleanOp_Box, BoolPredicateEnd_Box, ChangeAttribute_Box, ChangeAttributes_Box, Check_Box, CompareTwoValues_Box, ComplexFilter_Box, Constant_Box, Contains_Box, ConvertFromParam_Box, ConvertToParam_Box, CreateParam_Box, End_Box, Equals_Box, Flatten_Box, GetAttributeValue_Box, GetGraphElements_Box, GetProperty_Box, InducedSubGraph_Box, Input_Box, InterpretAsBoolean_Box, IsInstanceof_Box, Listify_Box, ListOperations1_Box, ListOperations2_Box, MakeDistinct_Box, MakeTrue_Box, Neighborhood_Box, NormalOutput_Box, OneOneConnector_Box, RecursiveGetGraphElements_Box, Reverse_Box, SizeOf_Box, Sort_Box, SortBy_Box, SubQuery_Box, TwoSplitConnector_Box, Unpack_Box, ValueCompare_Box, ValueFilter_Box, ValueFilter_Box

public class Box
extends java.lang.Object
implements IBox

Superclass providing all methods of IBox interface. If a box subclasses this class, overriding methods should call the super versions as first action. This specially applies to methods execute(), reset(), reset(int), setinputs(Object[]).

Some basic type checking is done. It acts as an identity operator.


Field Summary
protected  boolean boxExecuted
           
private  int boxNr
           
protected  IBoxRepresentation iBoxGRep
           
private  boolean ignoreBox
           
private  boolean[] inputNumbersSet
           
protected  java.lang.Object[] inputs
           
private  boolean inputSet
           
private  org.graffiti.graph.Node node
           
protected  java.lang.Object[] outputs
           
protected  org.graffiti.plugin.parameter.Parameter[] parameters
           
 
Constructor Summary
Box()
           
Box(org.graffiti.graph.Node n)
           
 
Method Summary
protected  boolean areAllInputsNull()
          Returns true iff all inputs are null.
 void execute()
          Should be overridden and called first by subclasses.
protected  java.lang.String getClassName()
          Used by getId() to retrieve the class name of the box.
 IBoxRepresentation getGraphicalRepresentation()
          This implementation returns a new instance of DefaultBoxRepresentation.
 java.lang.String getId()
          Generates a unique id.
 int[] getInputTypes()
          This implementation returns ONE element, the most general type.
 org.graffiti.graph.Node getNode()
          Returns the node that holds this box.
 int getNumberOfInputs()
          Returns the number of inputs this box expects.
 int getNumberOfOutputs()
          Returns the number of outputs this box provides.
 java.lang.Object getOutputAt(int index)
          Returns the ith output.
 java.lang.Object[] getOutputs()
          Returns outputs.
 int[] getOutputTypes()
          Override this method to specify more restricted types for the output(s) of the box.
 org.graffiti.plugin.parameter.Parameter[] getParameters()
          Returns empty parameter array meaning the box does not need any parameters if the field parameters is still null, otherwise returns this field.
 boolean hasBeenExecuted()
          Returns true iff the box's execute() method has been called since the creation of the box or the last call to reset.
 boolean ignoreBox()
          Gets the value previously set by setIgnoreBox(boolean) or returns false if not yet set.
 boolean isGraphicalRepNull()
           
 boolean isInputSet()
          Returns true iff all inputs have been set.
 boolean isInputSetAt(int index)
          Returns true iff the input at the given index has been set.
 boolean needsQueryRunner()
          Returns false.
 java.util.Collection removeNullValues(java.util.Collection col)
          Remove all null values from the given collection.
 void reset()
          Should be called by all classes that override this method.
 void reset(int index)
          Should be called by all classes that override this method.
 void setBoxNumber(int boxNumber)
          Set the number of the box.
 void setCurrentNodesTodo(java.util.Stack nodesTodo)
          Empty implementation.
 void setCurrentResult(java.util.List res)
          Empty implementation.
 void setDefaultParameters()
          If the subclass has any parameters, it may override this method.
 void setIgnoreBox(boolean ignore)
          Specifies whether or not a box should be ignored by any query processing (possibly because it has already been executed as part of a sub query).
 void setInputAt(java.lang.Object input, int index)
          This method calls setInputs with the inputs set so far.
 void setInputs(java.lang.Object[] inputs)
          Checks if the number of inputs is correct and sets the inputs.
 void setNode(org.graffiti.graph.Node n)
          Sets the node that holds this box.
 void setParameters(org.graffiti.plugin.parameter.Parameter[] pars, boolean fromRep)
          Sets the parameters and - if needed - sets them in the graphical representation.
 void setQueryRunner(RunQuery qr)
          Empty implementation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameters

protected org.graffiti.plugin.parameter.Parameter[] parameters

inputSet

private boolean inputSet

boxExecuted

protected boolean boxExecuted

outputs

protected java.lang.Object[] outputs

inputs

protected java.lang.Object[] inputs

iBoxGRep

protected IBoxRepresentation iBoxGRep

node

private org.graffiti.graph.Node node

inputNumbersSet

private boolean[] inputNumbersSet

boxNr

private int boxNr

ignoreBox

private boolean ignoreBox
Constructor Detail

Box

public Box()

Box

public Box(org.graffiti.graph.Node n)
Method Detail

setBoxNumber

public final void setBoxNumber(int boxNumber)
Set the number of the box. Used for identification purposes.

Specified by:
setBoxNumber in interface IBox
Parameters:
boxNumber -

setParameters

public void setParameters(org.graffiti.plugin.parameter.Parameter[] pars,
                          boolean fromRep)
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
Parameters:
pars - the parameters to be set
fromRep - true if called from the box's representation
See Also:
quoggles.IBox#setParameters(org.graffiti.plugin.algorithm.Parameter)

getParameters

public final org.graffiti.plugin.parameter.Parameter[] getParameters()
Returns empty parameter array meaning the box does not need any parameters if the field parameters is still null, otherwise returns this field.

Specified by:
getParameters in interface IBox
Returns:
the parameters of the box
See Also:
IBox.getParameters()

execute

public void execute()
             throws QueryExecutionException
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
QueryExecutionException
See Also:
IBox.execute()

getClassName

protected java.lang.String getClassName()
Used by getId() to retrieve the class name of the box.

Returns:
a string that is used as class name of the box

getId

public final java.lang.String getId()
Generates a unique id.

Specified by:
getId in interface IBox
Returns:
a String identifying the box
See Also:
quoggles.boxes.IBox#getID()

hasBeenExecuted

public final boolean hasBeenExecuted()
Description copied from interface: IBox
Returns true iff the box's execute() method has been called since the creation of the box or the last call to reset.

Specified by:
hasBeenExecuted in interface IBox
Returns:
true if the box has been executed and its outputs are ready
See Also:
IBox.hasBeenExecuted()

setDefaultParameters

public void setDefaultParameters()
If the subclass has any parameters, it may override this method. It sets the values of the parameters that are displayed first time the user sees this box. The best way however is to specify correct default values when creating the parameters in the first place. Thus, this implementation will set the correct values: It uses the information it gets from a call to getParameters.

Specified by:
setDefaultParameters in interface IBox
See Also:
IBox.setDefaultParameters()

getGraphicalRepresentation

public IBoxRepresentation getGraphicalRepresentation()
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
Returns:
the graphical representation of the box. Should be the same object each time the method is called.
See Also:
IBox.getGraphicalRepresentation()

isGraphicalRepNull

public boolean isGraphicalRepNull()
See Also:
quoggles.boxes.IBox#isGraphicalRepNull()

getInputTypes

public int[] getInputTypes()
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
Returns:
an int array whose size gives the number of inputs. The entries specify the type of the inputs. This uses constants defined in quoggles.constants.ITypeConstants.
See Also:
quoggles.boxes.IBox#getOtherInputTypes()

getNumberOfInputs

public int getNumberOfInputs()
Returns the number of inputs this box expects. This implementation returns the length of the input types array.

Specified by:
getNumberOfInputs in interface IBox
Returns:
the number of inputs this box expects
See Also:
quoggles.boxes.IBox#hasSeveralInputs()

setInputAt

public final void setInputAt(java.lang.Object input,
                             int index)
                      throws InvalidInputException
This method calls setInputs with the inputs set so far.

Specified by:
setInputAt in interface IBox
Parameters:
input - the input to be set at the given index
index - the index of the input to set
InvalidInputException
See Also:
IBox.setInputAt(java.lang.Object, int)

areAllInputsNull

protected final boolean areAllInputsNull()
Returns true iff all inputs are null.

Returns:
true iff all inputs are null.

isInputSet

public final boolean isInputSet()
Returns true iff all inputs have been set.

Specified by:
isInputSet in interface IBox
Returns:

isInputSetAt

public final boolean isInputSetAt(int index)
Description copied from interface: IBox
Returns true iff the input at the given index has been set.

Specified by:
isInputSetAt in interface IBox
Parameters:
index - between zero and getNumberOfInputs()-1
Returns:
true if the input has been set at the given index
See Also:
IBox.isInputSetAt(int)

setInputs

public void setInputs(java.lang.Object[] inputs)
               throws InvalidInputException
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
Parameters:
inputs - the inputs of the box
InvalidInputException
See Also:
quoggles.boxes.IBox#setOtherInputs(java.lang.Object[])

getNumberOfOutputs

public int getNumberOfOutputs()
Returns the number of outputs this box provides. This implementation returns the length of the output types array.

Specified by:
getNumberOfOutputs in interface IBox
Returns:
the number of outputs this box provides
See Also:
quoggles.boxes.IBox#hasSeveralOutputs()

getOutputTypes

public int[] getOutputTypes()
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
Returns:
an int array whose size gives the number of outputs. The entries specify the type of the outputs. This uses constants defined in quoggles.constants.ITypeConstants.
See Also:
quoggles.boxes.IBox#getOtherOutputTypes()

getOutputAt

public java.lang.Object getOutputAt(int index)
                             throws BoxNotExecutedException
Returns the ith output.

Specified by:
getOutputAt in interface IBox
Returns:
the ith output of the box
BoxNotExecutedException
See Also:
IBox.getOutputAt(int)

getOutputs

public java.lang.Object[] getOutputs()
                              throws BoxNotExecutedException
Returns outputs. Throws exception if the box's execute method has not been called. No need to override this method. Just work on the outputs field.

Specified by:
getOutputs in interface IBox
Returns:
the outputs of the box
BoxNotExecutedException
See Also:
quoggles.boxes.IBox#getOtherOutputs()

reset

public void reset()
Should be called by all classes that override this method.

Specified by:
reset in interface IBox
See Also:
IBox.reset()

removeNullValues

public final java.util.Collection removeNullValues(java.util.Collection col)
Remove all null values from the given collection.

If the given collection supports the remove operation, it is changed directly. Otherwise, all non-null elements are inserted into a new list. In both cases, the new list is returned.

Parameters:
col - the collection to remove null values from
Returns:
a collection holding the same elements as the given collection without any null values. Needs not be the same object as the given collection.

reset

public void reset(int index)
Should be called by all classes that override this method.

Specified by:
reset in interface IBox
Parameters:
index - the index of the input that should be marked as invalid
See Also:
IBox.reset(int)

needsQueryRunner

public boolean needsQueryRunner()
Returns false.

Specified by:
needsQueryRunner in interface IBox
Returns:
true if an object implementing the RunQuery interface should be passed to this box
See Also:
quoggles.boxes.IBox#neeedsQueryRunner()

setQueryRunner

public void setQueryRunner(RunQuery qr)
Empty implementation.

Specified by:
setQueryRunner in interface IBox
Parameters:
qr - an object that has a runQuery(...) method
See Also:
IBox.setQueryRunner(quoggles.auxiliary.RunQuery)

setCurrentResult

public void setCurrentResult(java.util.List res)
Empty implementation.

Specified by:
setCurrentResult in interface IBox
Parameters:
res - the last result of a call to runQuery(...)
See Also:
IBox.setCurrentResult(java.util.List)

setCurrentNodesTodo

public void setCurrentNodesTodo(java.util.Stack nodesTodo)
Empty implementation.

Specified by:
setCurrentNodesTodo in interface IBox
Parameters:
nodesTodo - the stack of nodes that still need to be processed
See Also:
quoggles.boxes.IBox#setCurrentNodesTodo(java.util.ArrayList)

setIgnoreBox

public void setIgnoreBox(boolean ignore)
Description copied from interface: IBox
Specifies whether or not a box should be ignored by any query processing (possibly because it has already been executed as part of a sub query).

Specified by:
setIgnoreBox in interface IBox
Parameters:
ignore - true iff the box should not be executed
See Also:
IBox.setIgnoreBox(boolean)

ignoreBox

public boolean ignoreBox()
Description copied from interface: IBox
Gets the value previously set by setIgnoreBox(boolean) or returns false if not yet set.

Specified by:
ignoreBox in interface IBox
Returns:
true if the box should be ignored
See Also:
IBox.ignoreBox()

setNode

public void setNode(org.graffiti.graph.Node n)
Description copied from interface: IBox
Sets the node that holds this box.

Specified by:
setNode in interface IBox
Parameters:
n - the node that holds this box.
See Also:
IBox.setNode(org.graffiti.graph.Node)

getNode

public org.graffiti.graph.Node getNode()
Description copied from interface: IBox
Returns the node that holds this box.

Specified by:
getNode in interface IBox
Returns:
the node that holds this box
See Also:
IBox.getNode()