View Javadoc

1   package net.obsearch.index.utils;
2   
3   /*
4    OBSearch: a distributed similarity search engine
5    This project is to similarity search what 'bit-torrent' is to downloads.
6    Copyright (C) 2007 Kyushu Institute of Technology
7   
8    This program is free software: you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10   the Free Software Foundation, either version 3 of the License, or
11   (at your option) any later version.
12  
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17  
18   You should have received a copy of the GNU General Public License
19   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20   */
21  
22  /**
23   * This class holds an integer.
24   * @author Arnoldo Jose Muller Molina
25   * @since 0
26   */
27  public class IntegerHolder implements Comparable<IntegerHolder> {
28  
29      /**
30       * Integer value to be stored.
31       */
32      private int value;
33  
34      /**
35       * @return the value of the integer
36       */
37      public int getValue() {
38          return value;
39      }
40  
41      /**
42       * Sets the value of the internal integer.
43       * @param value
44       *                The new value.
45       */
46      public void setValue(int value) {
47          this.value = value;
48      }
49  
50      /**
51       * Public constructor.
52       * @param value
53       *                the value to set.
54       */
55      public IntegerHolder(int value) {
56          super();
57          this.value = value;
58      }
59  
60      /**
61       * Increment the integer by 1.
62       */
63      public void inc() {
64          value++;
65      }
66  
67      /**
68       * Decrement the integer by 1.
69       */
70      public void dec() {
71          value--;
72      }
73  
74      /**
75       * @return String representation of the integer.
76       */
77      public String toString() {
78          return value + "";
79      }
80  
81      /**
82       * adds the value of x to this object's integer value.
83       * @param x
84       *                the value to add.
85       */
86      public void add(int x) {
87          value += x;
88      }
89  
90      /**
91       * Compares this IntegerHolder to another IntegerHolder.
92       */
93      public int compareTo(IntegerHolder o) {
94          IntegerHolder i = (IntegerHolder) o;
95          int res = 0;
96          if (value < i.value) {
97              res = -1; 
98          } else if (value > i.value) {
99              res = 1;
100         }
101         return res;
102     }
103 
104 }