-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounterObject.java
More file actions
62 lines (51 loc) · 1.46 KB
/
CounterObject.java
File metadata and controls
62 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Abstract class that is used to be the value inserted in a Node or
* in a BiNode object.
*
* Since a CounterObject is a Comparable it could be used elsewhere...
*
* In order to use this clas one must provide the three abstract methods bodies.
*/
public abstract class CounterObject implements Comparable {
protected int occurs; // occurrences of this CounterObject
/**
* Tests if this object is less than the other.
*
* @param other
*
* @return true if this is less than the other; false otherwise.
*/
public abstract boolean lessThan (CounterObject other);
/**
* Tests if this object is greater than the other.
*
* @param other
*
* @return true if this is greater than the other; false otherwise.
*/
public abstract boolean greaterThan (CounterObject other);
/**
*
* @return anything you need!
*/
public abstract Object getValue();
/**
* Compares this to the other CounterObjects calling the abstract methods.
*/
public int compareTo(Object other) {
if (this.lessThan((CounterObject)other))
return -1;
if (this.greaterThan((CounterObject)other))
return 1;
return 0;
}
public void addOccurrence() {
this.occurs++;
}
public int getOccurrences() {
return this.occurs;
}
public void setOccurrences (int occurs) {
this.occurs = occurs;
}
} //==> class CounterObject