jimm.datavision.field
Class AggregateField

java.lang.Object
  extended by java.util.Observable
      extended by jimm.datavision.Element
          extended by jimm.datavision.field.Field
              extended by jimm.datavision.field.AggregateField
All Implemented Interfaces:
java.lang.Cloneable, java.util.Observer, Draggable, Identity, Writeable

public class AggregateField
extends Field

An aggregate field represents a field's aggregated values, either ColumnField or FormulaField. It also may be associated with a group (assigned in ReportReader.field or when editing a report), meaning that the aggregate value is reset whenever the group's value changes. The value of an aggregate field holds the id of some other field whose value we are aggregating.

Author:
Jim Menard, jimm@io.com

Field Summary
protected  Field fieldToAggregate
           
protected  AggregateFunction function
           
protected  java.lang.String functionName
           
protected static java.lang.Object[] functionNames
          A sorted array of the function names.
protected static java.util.HashMap functions
          Maps function names to AggregateFunction objects.
protected  Group group
           
protected static int START_VALUES_LENGTH
           
protected  double[] values
           
protected  int valuesIndex
           
 
Fields inherited from class jimm.datavision.field.Field
border, bounds, cache, DEFAULT_HEIGHT, DEFAULT_WIDTH, format, id, maxIdSeen, value
 
Fields inherited from class jimm.datavision.Element
report, section, visible
 
Constructor Summary
AggregateField(java.lang.Long id, Report report, Section section, java.lang.Object value, boolean visible, java.lang.String functionName)
          Constructs a field with the specified id in the specified report section that aggregates the field with id value.
 
Method Summary
 boolean canBeAggregated()
          Returns true if this field can be aggregated.
 java.lang.String designLabel()
          Returns a string representing the field in the GUI during report design.
 java.lang.String dragString()
          Returns the string used to identify a field type when dragging.
protected  void finalize()
           
 java.lang.String formulaString()
          Returns a string representing the field as it appears in a formula.
static java.lang.Object[] functionNameArray()
          Returns the list of function names as an array of objects.
 double getAggregateValue()
          Returns the current aggregate value.
 Field getField()
          Returns the field over which we are aggregating.
 java.lang.Long getFieldId()
          Returns the id of the field over which we are aggregating.
 java.lang.String getFunction()
           
 Group getGroup()
          Returns the group over which this field is aggregating.
 java.lang.Object getValue()
          Returns the value of this field: the aggregate as a Double.
 void initialize()
          Resets this aggregate.
static boolean isAggregateFunctionName(java.lang.String functionName)
          Returns true if functionName is a legal aggregate function name.
 boolean refersTo(Field f)
          Returns true if this field contains a reference to the specified field.
 boolean refersTo(Formula f)
          Returns true if this field contains a reference to the specified formula.
 boolean refersTo(Parameter p)
          Returns true if this field contains a reference to the specified parameter.
 boolean refersTo(UserColumn uc)
          Returns true if this field contains a reference to the specified user column.
 void setFunction(java.lang.String newFunctionName)
           
 void setGroup(Group newGroup)
          Sets the group this field is aggregate.
 java.lang.String typeString()
          Returns the string that specifies this field's type in the report XML.
 void updateAggregate()
          Updates the aggregate value.
 
Methods inherited from class jimm.datavision.field.Field
clone, create, createFromDragString, getBorder, getBorderOrDefault, getBounds, getFormat, getId, getOutputHeight, makeWidget, setBorder, setBounds, setFormat, setValue, toString, update, writeFieldGuts, writeXML
 
Methods inherited from class jimm.datavision.Element
getReport, getSection, isVisible, setSection, setVisible
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

START_VALUES_LENGTH

protected static final int START_VALUES_LENGTH
See Also:
Constant Field Values

functions

protected static java.util.HashMap functions
Maps function names to AggregateFunction objects.


functionNames

protected static java.lang.Object[] functionNames
A sorted array of the function names.


group

protected Group group

functionName

protected java.lang.String functionName

function

protected AggregateFunction function

values

protected double[] values

valuesIndex

protected int valuesIndex

fieldToAggregate

protected Field fieldToAggregate
Constructor Detail

AggregateField

public AggregateField(java.lang.Long id,
                      Report report,
                      Section section,
                      java.lang.Object value,
                      boolean visible,
                      java.lang.String functionName)
Constructs a field with the specified id in the specified report section that aggregates the field with id value.

Parameters:
id - the new field's id
report - the report containing this element
section - the report section in which the field resides
value - the magic string
visible - show/hide flag
functionName - "xxx", where xxx is the aggregate function
Method Detail

isAggregateFunctionName

public static boolean isAggregateFunctionName(java.lang.String functionName)
Returns true if functionName is a legal aggregate function name.

Parameters:
functionName - an aggregate function name (hopefully)
Returns:
true if it's a function name

functionNameArray

public static java.lang.Object[] functionNameArray()
Returns the list of function names as an array of objects.

Returns:
all possible function names

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class Field
Throws:
java.lang.Throwable

getFunction

public java.lang.String getFunction()

setFunction

public void setFunction(java.lang.String newFunctionName)

initialize

public void initialize()
Resets this aggregate. Called by the report once at the beginning of each run.


dragString

public java.lang.String dragString()
Description copied from class: Field
Returns the string used to identify a field type when dragging. Usually returns Field.typeString() plus a value or an id.

Specified by:
dragString in interface Draggable
Specified by:
dragString in class Field
Returns:
the string used to identify the field when dragging

getGroup

public Group getGroup()
Returns the group over which this field is aggregating. May return null since not all aggregate fields are associated with a group.

Returns:
a group; null if this aggregate field is not associated with any group

setGroup

public void setGroup(Group newGroup)
Sets the group this field is aggregate. The group may be null.

Parameters:
newGroup - a group

getField

public Field getField()
Returns the field over which we are aggregating. We lazily instantiate it because when we are constructed that field may not yet exist. We also start observing the field so we can notify our observers in turn.

Returns:
the field we are aggregating

getFieldId

public java.lang.Long getFieldId()
Returns the id of the field over which we are aggregating. The field itself may not yet exist.

Returns:
the id of the field we are aggregating

getAggregateValue

public double getAggregateValue()
Returns the current aggregate value.

Returns:
a doubleing point total

typeString

public java.lang.String typeString()
Description copied from class: Field
Returns the string that specifies this field's type in the report XML.

Specified by:
typeString in class Field
Returns:
a string representing this field's type; used in XML files

designLabel

public java.lang.String designLabel()
Description copied from class: Field
Returns a string representing the field in the GUI during report design.

Overrides:
designLabel in class Field
Returns:
a string useful for display in the design GUI

formulaString

public java.lang.String formulaString()
Description copied from class: Field
Returns a string representing the field as it appears in a formula.

Specified by:
formulaString in class Field
Returns:
a string useful in a formula

refersTo

public boolean refersTo(Field f)
Description copied from class: Field
Returns true if this field contains a reference to the specified field. Most fields return false; only a AggregateField or FormulaField would return true.

Overrides:
refersTo in class Field
Parameters:
f - a field
Returns:
true if this field contains a reference to the specified field

refersTo

public boolean refersTo(Formula f)
Description copied from class: Field
Returns true if this field contains a reference to the specified formula. Most fields return false; only a AggregateField or FormulaField would return true.

Overrides:
refersTo in class Field
Parameters:
f - a formula
Returns:
true if this field contains a reference to the specified field

refersTo

public boolean refersTo(UserColumn uc)
Description copied from class: Field
Returns true if this field contains a reference to the specified user column. Most fields return false; only a AggregateField, UserColumnField, or FormulaField would return true.

Overrides:
refersTo in class Field
Parameters:
uc - a user column
Returns:
true if this field contains a reference to the specified user column

refersTo

public boolean refersTo(Parameter p)
Description copied from class: Field
Returns true if this field contains a reference to the specified parameter. Most fields return false; only a AggregateField or FormulaField would return true.

Overrides:
refersTo in class Field
Parameters:
p - a parameter
Returns:
true if this field contains a reference to the specified field

canBeAggregated

public boolean canBeAggregated()
Description copied from class: Field
Returns true if this field can be aggregated. This method returns false by default but is overridded by classes whose values may be aggregated.

Overrides:
canBeAggregated in class Field
Returns:
true if this field can be aggregated

updateAggregate

public void updateAggregate()
Updates the aggregate value. Called by the report when a new line of data is retrieved.


getValue

public java.lang.Object getValue()
Returns the value of this field: the aggregate as a Double.

Overrides:
getValue in class Field
Returns:
a Double