1
18 package org.torweg.pulse.component.statistics.util;
19
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.Map;
23 import java.util.Set;
24
25 import javax.xml.bind.annotation.XmlAccessOrder;
26 import javax.xml.bind.annotation.XmlAccessType;
27 import javax.xml.bind.annotation.XmlAccessorOrder;
28 import javax.xml.bind.annotation.XmlAccessorType;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlElementWrapper;
31 import javax.xml.bind.annotation.XmlRootElement;
32 import javax.xml.bind.annotation.XmlTransient;
33
34 import org.torweg.pulse.component.statistics.model.AbstractRegexVersioned;
35 import org.torweg.pulse.component.statistics.model.aggregation.AbstractRegexVersionedCounterAggregation;
36
37
49 @XmlRootElement(name = "abstract-regex-versioned-counter-aggregation-row-data")
50 @XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
51 @XmlAccessorType(XmlAccessType.FIELD)
52 public final class AbstractRegexVersionedCounterAggregationRowData<T extends AbstractRegexVersionedCounterAggregation<? extends AbstractRegexVersioned, ?>>
53 extends AbstractRowData<T> {
54
55
58 private static final long serialVersionUID = -8472054163624797954L;
59
60
63 @XmlElement(name = "counter")
64 private Integer counter;
65
66
69 @XmlElementWrapper(name = "counted-totals")
70 private final Map<String, CountedTotal<T>> countedTotals = new HashMap<String, CountedTotal<T>>();
71
72
75 @XmlTransient
76 private final Set<T> dataObjects = new HashSet<T>();
77
78
81 @Deprecated
82 protected AbstractRegexVersionedCounterAggregationRowData() {
83 super();
84 }
85
86
96 public AbstractRegexVersionedCounterAggregationRowData(final T dataObject) {
97 super();
98 aggregate(dataObject);
99 }
100
101
109 @Override
110 public Set<T> getDataObjects() {
111 return this.dataObjects;
112 }
113
114
129 @Override
130 protected AbstractRegexVersionedCounterAggregationRowData<T> create(
131 final T dataObject) {
132 return new AbstractRegexVersionedCounterAggregationRowData<T>(
133 dataObject);
134 }
135
136
144 @Override
145 protected void aggregate(final T dataObject) {
146
147 if (this.counter == null) {
148 this.counter = dataObject.getCount();
149 } else {
150 this.counter += dataObject.getCount();
151 }
152
153 if (this.countedTotals.containsKey(dataObject.getCounted()
154 .getCategory())) {
155 this.countedTotals.get(dataObject.getCounted().getCategory())
156 .aggregate(dataObject);
157 } else {
158 this.countedTotals.put(dataObject.getCounted().getCategory(),
159 new CountedTotal<T>(dataObject));
160 }
161
162 this.dataObjects.add(dataObject);
163
164 }
165
166 }
167