Source code: Misc/Counter.java
1 package Misc;
2
3 import Exceptions.InvalidHeaderException;
4 /*
5 * Counter.java
6 *
7 * Created on 08 November 2002, 22:42
8 */
9
10 /**
11 *
12 * @author yc
13 */
14 public class Counter {
15
16 private int counter;
17 private int supplen;
18
19 /** Creates a new instance of Counter */
20 public Counter(int n, int supplen) {
21 this.counter = max(n,0);
22 this.supplen = supplen;
23 }
24
25 public void decCounter(int n)
26 throws InvalidHeaderException
27 {
28 if (n > counter)
29 throw new InvalidHeaderException();
30 counter = max(counter-n, 0);
31 // this is for information only
32 supplen = max(supplen-n,0);
33 }
34
35 public int getCounter() {
36 return this.counter;
37 }
38
39 public int getSupCounter(){
40 return this.supplen;
41 }
42
43 private int max(int n1,int n2)
44 {
45 if (n1 >= n2) return n1;
46 else return n2;
47
48 }
49
50 public String toString()
51 {
52 return String.valueOf(this.counter);
53 }
54 }