-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAlternative.java
More file actions
84 lines (74 loc) · 2.19 KB
/
Copy pathAlternative.java
File metadata and controls
84 lines (74 loc) · 2.19 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* An alternative item or course of action.
* Implements Serializable to facilitate saving and restoring
* collections of Alternative objects.
* @author Dr. Jody Paul
* @version 20241113.4
*/
public class Alternative implements Comparable<Alternative>,
java.io.Serializable {
/** Serialization identifier. */
private static final long serialVersionUID = 202411130104L;
/** The default final score is 0. */
public static final int DEFAULT_SCORE = 0;
/** The descriptor of this alternative. */
private String descriptor;
/** The final score of this alternative. */
private int finalScore;
/**
* Constructor that establishes the descriptor
* and sets the final score to the default.
* @param theDescriptor the descriptor of the new alternative
*/
public Alternative(final String theDescriptor) {
this.descriptor = theDescriptor;
this.finalScore = DEFAULT_SCORE;
}
/**
* Modify the final score.
* @param newScore the new value for final score
*/
public void setFinalScore(final int newScore) {
this.finalScore = newScore;
}
/**
* Access the desciptor of this alternative.
* @return the descriptor
*/
public String getDescriptor() {
return this.descriptor;
}
/**
* Access the final score of this alternative.
* @return the final score
*/
public int getFinalScore() {
return this.finalScore;
}
@Override
public String toString() {
return this.descriptor + " == " + this.finalScore;
}
@Override
public int hashCode() {
return this.descriptor.hashCode();
}
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Alternative alt = (Alternative) o;
return this.descriptor.equals(alt.descriptor);
}
@Override
public int compareTo(final Alternative alt) {
if (this == alt) {
return 0;
}
return Integer.compare(this.finalScore, alt.finalScore);
}
}