Coverage Report - org.jtheque.utils.count.Counter
 
Classes in this File Line Coverage Branch Coverage Complexity
Counter
100%
12/12
N/A
1
 
 1  
 package org.jtheque.utils.count;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 /**
 20  
  * A counter.
 21  
  *
 22  
  * @author Baptiste Wicht
 23  
  */
 24  8
 public final class Counter {
 25  
     private int value;
 26  
 
 27  
     /**
 28  
      * Return the current value of the counter.
 29  
      *
 30  
      * @return The integer value of the counter.
 31  
      */
 32  
     public int getValue() {
 33  18
         return value;
 34  
     }
 35  
 
 36  
     /**
 37  
      * Increment the counter of 1.
 38  
      */
 39  
     public void increment() {
 40  4
         add(1);
 41  4
     }
 42  
 
 43  
     /**
 44  
      * Decrement the counter of 1.
 45  
      */
 46  
     public void decrement() {
 47  4
         remove(1);
 48  4
     }
 49  
 
 50  
     /**
 51  
      * Add i to the counter.
 52  
      *
 53  
      * @param i The value to add.
 54  
      */
 55  
     public void add(int i) {
 56  8
         value += i;
 57  8
     }
 58  
 
 59  
     /**
 60  
      * Remove i from the counter.
 61  
      *
 62  
      * @param i The value to remove.
 63  
      */
 64  
     void remove(int i) {
 65  4
         value -= i;
 66  4
     }
 67  
 
 68  
     /**
 69  
      * Clear the counter. This method set the current counter value to 0.
 70  
      */
 71  
     public void clear() {
 72  2
         value = 0;
 73  2
     }
 74  
 }