quoggles.stdboxes.arithmetic
Class Arithmetic_Box

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

public class Arithmetic_Box
extends Box

Input: one or several Numbers

Output: the result of the function (specified by the parameter) null if the input itself is null


Field Summary
private  java.util.Collection inputCol
          The input collection
private  java.lang.Number num1
           
private  java.lang.Number num2
           
private  java.lang.Number singleInput
          Only set if input is not a collection
 
Fields inherited from class quoggles.boxes.Box
boxExecuted, iBoxGRep, inputs, outputs, parameters
 
Constructor Summary
Arithmetic_Box()
          Constructs the box.
 
Method Summary
private  int count(java.util.Collection col)
          Counts the number of elements not equal to QConstants.EMPTY contained in the given collection.
 void execute()
          Should be overridden and called first by subclasses.
 IBoxRepresentation getGraphicalRepresentation()
          This implementation returns a new instance of DefaultBoxRepresentation.
 int[] getInputTypes()
          This implementation returns ONE element, the most general type.
 int[] getOutputTypes()
          Override this method to specify more restricted types for the output(s) of the box.
private  boolean isAggregate()
          Returns true iff the box's parameter is set so that an aggregate function is calculated.
 void setInputs(java.lang.Object[] inputs)
          Checks if the number of inputs is correct and sets the inputs.
private  java.lang.Number sum(java.util.Collection col)
          Returns the sum of all (Number) elements in the given collection.
 
Methods inherited from class quoggles.boxes.Box
areAllInputsNull, getClassName, getId, getNode, getNumberOfInputs, getNumberOfOutputs, getOutputAt, getOutputs, getParameters, hasBeenExecuted, ignoreBox, isGraphicalRepNull, isInputSet, isInputSetAt, needsQueryRunner, removeNullValues, reset, reset, setBoxNumber, setCurrentNodesTodo, setCurrentResult, setDefaultParameters, setIgnoreBox, setInputAt, setNode, setParameters, setQueryRunner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputCol

private java.util.Collection inputCol
The input collection


singleInput

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


num1

private java.lang.Number num1

num2

private java.lang.Number num2
Constructor Detail

Arithmetic_Box

public Arithmetic_Box()
Constructs the box.

Method Detail

isAggregate

private boolean isAggregate()
Returns true iff the box's parameter is set so that an aggregate function is calculated.

Returns:
true iff the box's parameter is set so that an aggreate function is calculated.

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:
quoggles.boxes.IGraphicalBox#getGraphicalRepresentation()

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()

count

private int count(java.util.Collection col)
Counts the number of elements not equal to QConstants.EMPTY contained in the given collection.

Parameters:
col - collection of which the elements should be counted
Returns:
number of elements

sum

private java.lang.Number sum(java.util.Collection col)
Returns the sum of all (Number) elements in the given collection.

Parameters:
col -
Returns:
the sum of all (Number) elements in the given collection.