package com.onaro.sanscreen.client.view.tabular.value;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import com.onaro.sanscreen.client.view.init.SummaryInitInfo;
import com.onaro.sanscreen.client.view.tabular.NumberColumn;
import com.onaro.util.jfc.grouping.Node;
import com.onaro.util.jfc.grouping.Summarizer;
/**
* Sum the number values in a {@link NumberColumn} for the rows that match the specified condition.
* Multiple values that are equal in terms of {@link NumberValue#equals(Object)} and {@link NumberValue#hashCode()}
* are summed only once.
*
If all children of a group are equal (not in value, but when testing the equals and hashcode methods),
* then one of the values becomes the summary.
*
If any of the children isn't a {@link NumberValue}, the summary will be empty.
*
Usage example: Summing the capacity of volumes in a group where the capacicty value is
* identified by the volume name.
*/
public class ConditionalSumUniqueNumberColumnSummarizer implements Summarizer {
/**
* Condition to check if the child node should be included in the summary
*/
protected NodeCondition condition;
/**
* The column to put the sum in.
*/
protected int column;
/**
* Defined the format-name used by {@link NumberValue} to format the number.
*/
protected String format;
/**
* Initialize a summarizer for the given column.
* @param condition the condition to check on the child row
* @param column the column to put the sum in
*/
public ConditionalSumUniqueNumberColumnSummarizer(NodeCondition condition, int column) {
this(condition, column, NumberValue.FORMAT_DEFAULT);
}
/**
* Initialize a summarizer for the given column.
* @param condition the condition to check on the child row
* @param column the column to put the sum in
* @param format the format to display the number value
*/
public ConditionalSumUniqueNumberColumnSummarizer(NodeCondition condition, int column, String format) {
this.condition = condition;
this.column = column;
this.format = format;
}
/**
* Sum the number values in a {@link NumberColumn} for the rows in a group meeting the condition. Multiple values that
* are equal in terms of {@link NumberValue#equals(Object)} and {@link NumberValue#hashCode()}
* are summed only once.
*
If all children of a group are equal (not in value, but when testing the equals and hashcode methods),
* then one of the values becomes the summary.
*
If any of the children isn't a {@link NumberValue}, the summary will be empty.
* @param node the node
*/
public void updateSummary(Node node) {
Set