1    /*
2     * Copyright 2009 :torweg free software group
3     *
4     * This program is free software: you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation, either version 3 of the License, or
7     * (at your option) any later version.
8     * 
9     * This program is distributed in the hope that it will be useful,
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    * GNU General Public License for more details.
13    * 
14    * You should have received a copy of the GNU General Public License
15    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16    *
17    */
18   package org.torweg.pulse.component.statistics.model.aggregation;
19   
20   import javax.persistence.Basic;
21   import javax.persistence.MappedSuperclass;
22   import javax.xml.bind.annotation.XmlAccessOrder;
23   import javax.xml.bind.annotation.XmlAccessType;
24   import javax.xml.bind.annotation.XmlAccessorOrder;
25   import javax.xml.bind.annotation.XmlAccessorType;
26   import javax.xml.bind.annotation.XmlElement;
27   import javax.xml.bind.annotation.XmlRootElement;
28   
29   /**
30    * Abstract bass class representing a basic {@code AbstractAggregation}
31    * providing additional counter functionality.
32    * 
33    * @author Daniel Dietz
34    * @version $Revision: 1555 $
35    */
36   @XmlRootElement(name = "visit-count-aggregation")
37   @XmlAccessorOrder(XmlAccessOrder.UNDEFINED)
38   @XmlAccessorType(XmlAccessType.FIELD)
39   @MappedSuperclass
40   public abstract class AbstractCountAggregation extends AbstractAggregation
41           implements ICount {
42   
43       /**
44        * The serialVersionUID.
45        */
46       private static final long serialVersionUID = 2626430460787967562L;
47   
48       /**
49        * The internal counter.
50        */
51       @Basic
52       @XmlElement(name = "counter")
53       private int counter = 0;
54   
55       /**
56        * Returns the counter.
57        * 
58        * @return the <tt>counter</tt>
59        */
60       public final int getCount() {
61           return this.counter;
62       }
63   
64       /**
65        * Sets the internal counter to the given value.
66        * 
67        * @param i
68        *            the value to set
69        * 
70        * @throws IllegalArgumentException
71        *             if the given i is less than zero
72        */
73       protected final void setCount(final int i) {
74           if (i < 0) {
75               throw new IllegalArgumentException("Given i must not be < 0.");
76           }
77           this.counter = i;
78       }
79   
80       /**
81        * Adds 1 to the internal counter.
82        */
83       protected final void increase() {
84           this.counter++;
85       }
86   
87       /**
88        * Adds the given integer to the internal counter.
89        * 
90        * @param i
91        *            an integer
92        * 
93        * @throws IllegalArgumentException
94        *             if the given i is less than zero
95        */
96       protected final void increaseBy(final int i) {
97           if (i < 0) {
98               throw new IllegalArgumentException("Given i must not be < 0.");
99           }
100          this.counter += i;
101      }
102  
103  }
104