|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jidesoft.pivot.DefaultSummaryCalculator
public class DefaultSummaryCalculator
Default implementation of SummaryCalculator. In this implementation, it calculates seven statistics - Sum, Min, Max, Mean, Var, StdDev, Count - for numbers (all classes extending Number and primitives) and BigDecimals; Max, Min, Count for String and only Count for all other data types.
You can always add your own summary. For example, you want to add a new summary called "Last Value". Here is the sample code.
pivotDataModel.setSummaryCalculator(new DefaultSummaryCalculator(){
final int SUMMARY_LAST_VALUE = PivotConstants.SUMMARY_RESERVED_MAX + 1;
private double _lastValue;
public void addValue(Object v) {
super.addValue(v);
if (object instanceof Number) {
_lastValue = ((Number) object).doubleValue();
}
}
public void clear() {
super.clear();
_lastValue = 0;
}
public int getNumberOfSummaries() {
return super.getNumberOfSummaries() + 1;
}
public String getSummaryName(int type) {
if(type == SUMMARY_LAST_VALUE) {
return "Last Value";
}
return super.getSummaryName(type);
}
public Object getSummaryResult(int type) {
if(type == SUMMARY_LAST_VALUE) {
return new Double(_lastValue);
}
return super.getSummaryResult(type);
}
});
In the example, we use the DefaultSummaryCalculator
because we just need to add one more summary. If you want
to provide your own way to calculate the summaries, you can implement SummaryCalculator
interface directly.
DefaultSummaryCalculator
has built-in support for Numbers, BigDecimals, Dates/Calendars and Booleans. If
you need to calculate other data types, you can create your own SummaryCalculator
extending
DefaultSummaryCalculator
.
Field Summary |
---|
Fields inherited from interface com.jidesoft.pivot.SummaryCalculator |
---|
ALLOWED_SUMMARIES_ALL, ALLOWED_SUMMARIES_COUNT, ALLOWED_SUMMARIES_MAX_MIN_COUNT |
Constructor Summary | |
---|---|
DefaultSummaryCalculator()
|
Method Summary | |
---|---|
void |
addValue(IPivotDataModel dataModel,
PivotField field,
int rowIndex,
int columnIndex,
Object value)
Deprecated. replaced by addValue(PivotValueProvider, PivotField, Values, Values, Object) |
void |
addValue(Object object)
Adds a value for calculation. |
void |
addValue(PivotValueProvider valueProvider,
PivotField field,
Object value)
Deprecated. replaced by addValue(PivotValueProvider, PivotField, Values, Values, Object) |
void |
addValue(PivotValueProvider dataModel,
PivotField field,
Values rowValues,
Values columnValues,
Object object)
Adds a value for calculation. |
void |
clear()
Clears all previous added values. |
Object |
clone()
|
int[] |
getAllowedSummaries(Class<?> type)
Gets the allowed summary types for a data type. |
int[] |
getAllowedSummaries(Class<?> type,
ConverterContext context)
Gets the allowed summary types. |
long |
getCount()
Gets the number of values that have been added so far. |
MathContext |
getMathContext()
Gets the MathContext. |
int |
getNumberOfSummaries()
Gets the number of summary types. |
String |
getSummaryName(Locale locale,
int summaryType)
Gets the summary name for the specified type. |
Object |
getSummaryResult(int type)
Gets the summary result for the specified type. |
boolean |
isBiasCorrected()
Checks if the biasCorrect is set. |
void |
setBiasCorrected(boolean biasCorrected)
Sets the biasCorrected flag. |
void |
setMathContext(MathContext mathContext)
To calculate statistics for BigDecimals, a MathContext to control the precision. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DefaultSummaryCalculator()
Method Detail |
---|
public Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public void addValue(Object object)
SummaryCalculator
addValue
in interface SummaryCalculator
object
- the value@Deprecated public void addValue(IPivotDataModel dataModel, PivotField field, int rowIndex, int columnIndex, Object value)
addValue(PivotValueProvider, PivotField, Values, Values, Object)
addValue(Object)
which only takes the value as parameter,
this method provides PivotDataModel, PivotField and row/column index of the cell as in the DataTableModel.
addValue
in interface SummaryCalculator
dataModel
- the PivotDataModelfield
- the PivotFieldrowIndex
- the row index as in the PivotDataModel#getDataTableModel. It could be -1 if the row index is
not available.columnIndex
- the column index as in the PivotDataModel#getDataTableModel. It could be -1 if the column
index is not available.value
- the value@Deprecated public void addValue(PivotValueProvider valueProvider, PivotField field, Object value)
addValue(PivotValueProvider, PivotField, Values, Values, Object)
addValue
in interface SummaryCalculator
valueProvider
- the PivotValueProviderfield
- the PivotFieldvalue
- the valuepublic void addValue(PivotValueProvider dataModel, PivotField field, Values rowValues, Values columnValues, Object object)
SummaryCalculator
SummaryCalculator.addValue(Object)
which only takes the value as parameter,
this method provides PivotValueProvider, PivotField and row/column values of the cell as in the DataTableModel.
To get the row indices in the original table model, please try to use the following code.
((IPivotDataModel) dataModel).getDataAt(((DefaultValues) rowValues).toCompoundKey(), ((DefaultValues) columnValues).toCompoundKey());
addValue
in interface SummaryCalculator
dataModel
- the PivotDataModelfield
- the PivotFieldrowValues
- the row values corresponding to the cell to calculate.columnValues
- the column values corresponding to the cell to calculate.object
- the valuepublic void clear()
SummaryCalculator
clear
in interface SummaryCalculator
public long getCount()
SummaryCalculator
getCount
in interface SummaryCalculator
public int getNumberOfSummaries()
SummaryCalculator
getNumberOfSummaries
in interface SummaryCalculator
public String getSummaryName(Locale locale, int summaryType)
SummaryCalculator
getSummaryName
in interface SummaryCalculator
locale
- the current locale
public Object getSummaryResult(int type)
SummaryCalculator
getSummaryResult
in interface SummaryCalculator
public boolean isBiasCorrected()
public void setBiasCorrected(boolean biasCorrected)
biasCorrected
- true or false.public MathContext getMathContext()
public void setMathContext(MathContext mathContext)
mathContext
- the MathContext.public int[] getAllowedSummaries(Class<?> type)
SummaryCalculator
getAllowedSummaries
in interface SummaryCalculator
type
- the data type.
public int[] getAllowedSummaries(Class<?> type, ConverterContext context)
getAllowedSummaries
in interface SummaryCalculator
type
- the data type.context
- the converter context. If the type is the same and you want it to have different summary types,
you can use the converter context to make them different.
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |