Computes the horizontal average over all columns specified in the field-list. The average will be computed over all
fields of the current data-row, it will not be computed for all rows in the group. For that use the
instead.
Non numeric and null-columns will be treated as zero for the task of summing up all members. Whether these fields are
used counted as valid fields can be controlled with the 'onlyValidFields' flag.
| Method from org.jfree.report.function.ColumnAverageExpression Detail: |
public int getRoundingMode() {
return roundingMode;
}
Returns the defined rounding mode. This influences the precision of the divide-operation. |
public int getScale() {
return scale;
}
Returns the scale for the divide-operation. The scale influences the precision of the division. |
public Object getValue() {
final Object[] values = getFieldValues();
BigDecimal computedResult = new BigDecimal(0);
int count = 0;
for (int i = 0; i < values.length; i++)
{
final Object value = values[i];
if (value instanceof Number == false)
{
continue;
}
final Number n = (Number) value;
final BigDecimal nval = new BigDecimal(n.toString());
computedResult = computedResult.add(nval);
count += 1;
}
if (onlyValidFields)
{
if (count == 0)
{
if (returnInfinity == false)
{
return null;
}
if (computedResult.signum() == -1)
{
return new Double(Double.NEGATIVE_INFINITY);
}
else
{
return new Double(Double.POSITIVE_INFINITY);
}
}
return computedResult.divide(new BigDecimal(count), scale, roundingMode);
}
if (values.length == 0)
{
if (returnInfinity == false)
{
return null;
}
if (computedResult.signum() == -1)
{
return new Double(Double.NEGATIVE_INFINITY);
}
else
{
return new Double(Double.POSITIVE_INFINITY);
}
}
return computedResult.divide(new BigDecimal(values.length), scale, roundingMode);
}
Computes the horizontal average of all field in the field-list. The average will be computed over all fields of the
current data-row, it will not be computed for all rows in the group. For that use the org.jfree.report.function.ItemAvgFunction instead. |
public boolean isOnlyValidFields() {
return onlyValidFields;
}
Returns, whether non-numeric and null-values are ignored for the average-computation. |
public boolean isReturnInfinity() {
return returnInfinity;
}
Returns, whether the expression returns infinity if there are no valid fields. If set to false, this expression
returns null instead. |
public void setOnlyValidFields(boolean onlyValidFields) {
this.onlyValidFields = onlyValidFields;
}
Defines, whether non-numeric and null-values are ignored for the average-computation. |
public void setReturnInfinity(boolean returnInfinity) {
this.returnInfinity = returnInfinity;
}
Defines, whether the expression returns infinity if there are no valid fields. If set to false, this expression
returns null instead. |
public void setRoundingMode(int roundingMode) {
this.roundingMode = roundingMode;
}
Defines the rounding mode. This influences the precision of the divide-operation. |
public void setScale(int scale) {
this.scale = scale;
}
Defines the scale for the divide-operation. The scale influences the precision of the division. |