1 | public final class DialShape implements Serializable {↵ | | 1 | public final class RangeType implements Serializable {↵
|
|
2 | /** For serialization. */↵ | | 2 | /** For serialization. */↵
|
3 | private static final long serialVersionUID = -3471933055190251131L;↵ | | 3 | private static final long serialVersionUID = -9073319010650549239L;↵
|
4 | ↵ | | 4 | ↵
|
5 | /** Circle. */↵ | | 5 | /** Full range (positive and negative). */↵
|
6 | public static final DialShape CIRCLE = new DialShape("DialShape.CIRCLE");↵ | | 6 | public static final RangeType FULL = new RangeType("RangeType.FULL");↵
|
|
7 | /** Chord. */↵ | | 7 | /** Positive range. */↵
|
8 | public static final DialShape CHORD = new DialShape("DialShape.CHORD↵ | | 8 | public static final RangeType POSITIVE ↵
|
9 | ");↵ | | 9 | = new RangeType("RangeType.POSITIVE");↵
|
|
10 | /** Pie. */↵ | | 10 | /** Negative range. */↵
|
11 | public static final DialShape PIE = new DialShape("DialShape.PI↵ | | 11 | public static final RangeType NEGATIVE ↵
|
12 | E");↵ | | 12 | = new RangeType("RangeType.NEGATIVE");↵
|
|
13 | /** The name. */↵ | | 13 | /** The name. */↵
|
14 | private String name;↵ | | 14 | private String name;↵
|
|
15 | /**↵ | | 15 | /**↵
|
16 | * Private constructor.↵ | | 16 | * Private constructor.↵
|
17 | *↵ | | 17 | *↵
|
18 | * @param name the name.↵ | | 18 | * @param name the name.↵
|
19 | */↵ | | 19 | */↵
|
20 | private DialShape(String name) {↵ | | 20 | private RangeType(String name) {↵
|
21 | this.name = name;↵ | | 21 | this.name = name;↵
|
22 | }↵ | | 22 | }↵
|
|
23 | /**↵ | | 23 | /**↵
|
24 | * Returns a string representing the object.↵ | | 24 | * Returns a string representing the object.↵
|
25 | *↵ | | 25 | *↵
|
26 | * @return The string.↵ | | 26 | * @return The string.↵
|
27 | */↵ | | 27 | */↵
|
28 | public String toString() {↵ | | 28 | public String toString() {↵
|
29 | return this.name;↵ | | 29 | return this.name;↵
|
30 | }↵ | | 30 | }↵
|
|
31 | /**↵ | | 31 | /**↵
|
32 | * Returns <code>true</code> if this object is equal to the specified ↵ | | 32 | * Returns <code>true</code> if this object is equal to the specified ↵
|
33 | * object, and <code>false</code> otherwise.↵ | | 33 | * object, and <code>false</code> otherwise.↵
|
34 | *↵ | | 34 | *↵
|
35 | * @param obj the other object.↵ | | 35 | * @param obj the other object.↵
|
36 | *↵ | | 36 | *↵
|
37 | * @return A boolean.↵ | | 37 | * @return A boolean.↵
|
38 | */↵ | | 38 | */↵
|
39 | public boolean equals(Object obj) {↵ | | 39 | public boolean equals(Object obj) {↵
|
|
40 | if (this == obj) {↵ | | 40 | if (this == obj) {↵
|
41 | return true;↵ | | 41 | return true;↵
|
42 | }↵ | | 42 | }↵
|
43 | if (!(obj instanceof DialShape)) {↵ | | 43 | if (!(obj instanceof RangeType)) {↵
|
44 | return false;↵ | | 44 | return false;↵
|
45 | }↵ | | 45 | }↵
|
46 | DialShape shape = (DialShape) obj;↵ | | 46 | RangeType that = (RangeType) obj;↵
|
47 | if (!this.name.equals(shape.toString())) {↵ | | 47 | if (!this.name.equals(that.toString())) {↵
|
48 | return false;↵ | | 48 | return false;↵
|
49 | }↵ | | 49 | }↵
|
50 | return true;↵ | | 50 | return true;↵
|
51 | }↵ | | 51 | }↵
|
52 | ↵ | | 52 | ↵
|
53 | /**↵ | | 53 | /**↵
|
54 | * Returns a hash code for this instance.↵ | | 54 | * Returns a hash code value for the object.↵
|
55 | * ↵ | | 55 | *↵
|
56 | * @return A hash code.↵ | | 56 | * @return The hashcode↵
|
57 | */↵ | | 57 | */↵
|
58 | public int hashCode() {↵ | | 58 | public int hashCode() {↵
|
59 | return this.name.hashCode();↵ | | 59 | return this.name.hashCode();↵
|
60 | }↵ | | 60 | }↵
|
61 | ↵ | | |
|
62 | /**↵ | | 61 | /**↵
|
63 | * Ensures that serialization returns the unique instances.↵ | | 62 | * Ensures that serialization returns the unique instances.↵
|
64 | * ↵ | | 63 | * ↵
|
65 | * @return The object.↵ | | 64 | * @return The object.↵
|
66 | * ↵ | | 65 | * ↵
|
67 | * @throws ObjectStreamException if there is a problem.↵ | | 66 | * @throws ObjectStreamException if there is a problem.↵
|
68 | */↵ | | 67 | */↵
|
69 | private Object readResolve() throws ObjectStreamException {↵ | | 68 | private Object readResolve() throws ObjectStreamException {↵
|
70 | if (this.equals(DialShape.CIRCLE)) {↵ | | 69 | if (this.equals(RangeType.FULL)) {↵
|
71 | return DialShape.CIRCLE;↵ | | 70 | return RangeType.FULL;↵
|
72 | }↵ | | 71 | }↵
|
73 | else if (this.equals(DialShape.CHORD)) {↵ | | 72 | else if (this.equals(RangeType.POSITIVE)) {↵
|
74 | return DialShape.CHORD;↵ | | 73 | return RangeType.POSITIVE;↵
|
75 | } ↵ | | 74 | }↵
|
76 | else if (this.equals(DialShape.PIE)) {↵ | | 75 | else if (this.equals(RangeType.NEGATIVE)) {↵
|
77 | return DialShape.PIE;↵ | | 76 | return RangeType.NEGATIVE;↵
|
78 | } ↵ | | 77 | }↵
|
79 | return null | | 78 | return null
|