1 | /*
|
---|
2 | * Counter.java
|
---|
3 | * Copyright (C) 2000 Eibe Frank
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program 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 this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 |
|
---|
20 | import java.io.*;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Class that implements a simple counter.
|
---|
24 | *
|
---|
25 | * @author Eibe Frank ([email protected])
|
---|
26 | * @version 1.0
|
---|
27 | */
|
---|
28 | public class Counter implements Serializable {
|
---|
29 |
|
---|
30 | /** Integer value stored */
|
---|
31 | private int m_val = 1;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Initializes the counter to 1
|
---|
35 | */
|
---|
36 | public Counter() {
|
---|
37 |
|
---|
38 | m_val = 1;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Initializes the counter to the given value
|
---|
43 | */
|
---|
44 | public Counter(int val) {
|
---|
45 |
|
---|
46 | m_val = val;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Increments the counter.
|
---|
51 | */
|
---|
52 | public void increment() {
|
---|
53 |
|
---|
54 | m_val++;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Gets the value.
|
---|
59 | * @return the value
|
---|
60 | */
|
---|
61 | public int value() {
|
---|
62 |
|
---|
63 | return m_val;
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Returns string containing value.
|
---|
68 | */
|
---|
69 | public String toString() {
|
---|
70 |
|
---|
71 | return String.valueOf(m_val);
|
---|
72 | }
|
---|
73 | }
|
---|