#804: IntAggregatedValues.java
projectforge-business/src/main/java/org/projectforge/statistics/IntAggregatedValues.java Statistics helper — concrete Integer aggregation for the Template Method statistics framework. Source: projectforge-business/src/main/java/org/projectforge/statistics/IntAggregatedValues.java 88 lines · 36 code · 44 comments · 8 blank
Provides the three arithmetic operations needed by
AbstractAggregatedValues (
#802) for the
Integer type:
getZero() → 0,
isZero() → null-or-zero check,
sum() → integer addition. Implements
Serializable for cache storage. Used by statistics builders that aggregate integer counters (timesheet counts, employee counts, etc.).
Template Method Pattern
The separation of aggregation logic into AbstractAggregatedValues<T> with three abstract methods (getZero, isZero, sum) is the Template Method pattern. The base class handles accumulation, min/max tracking, counter incrementing — all in a type-agnostic way. Subclasses only provide the three type-specific operations. This avoids duplicating the ~60-line aggregation logic for each numeric type (BigDecimal, Integer, Long).
Siblings
| Class | Type | Doc |
|---|
AbstractAggregatedValues<T> | Base (template) | #802 |
| IntAggregatedValues | Integer | #804 |
BigDecimalAggregatedValues | BigDecimal | #803 |
Why Not Generic?
Java generics don't support arithmetic operators (+) on type parameters — T + T doesn't compile. This forces the three abstract methods. An alternative would be to use Number and .intValue() everywhere, but that would lose type safety (mixing BigDecimal and Integer in the same aggregation) and precision (BigDecimal → int truncation). The Template Method approach preserves type safety at the cost of one subclass per numeric type.
Git History
868d6abb7 2025→2026 | 63081666f 2024→2025 | b6092df09 2023→2024 | 9ebb88522 Initial commit
Unchanged since initial commit — the three integer operations are trivially correct and need no maintenance.