1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.sun.syndication.common;
18
19 import java.io.Serializable;
20
21 /***
22 * Base class for enumerations (to bad is too early for Java 1.5).
23 * <p>
24 * Enum objects are inmutable.
25 * <p>
26 * @author Alejandro Abdelnur
27 *
28 */
29 public class Enum implements Serializable,Cloneable {
30 String _name;
31
32 /***
33 * Creates an Enum object with the given name.
34 * <p>
35 * @param name of the Enum.
36 *
37 */
38 protected Enum(String name) {
39 _name = name;
40 }
41
42 /***
43 * Returns the String representation of the Enum.
44 * <p>
45 * @return the Enum String representation.
46 *
47 */
48 public String toString() {
49 return _name;
50 }
51
52 /***
53 * Clones the Enum.
54 * <p>
55 * @return a clone of the Enum object, as Enum objects are inmutable, it returns the same object.
56 *
57 */
58 public Object clone() {
59 return this;
60 }
61
62 /***
63 * Indicates whether some other Enum is "equal to" this one as defined by the Object equals() method.
64 * <p>
65 * @param obj the object to compare with.
66 * @return <b>true</b> if 'this' object is equal to the 'obj' object.
67 *
68 */
69 public boolean equals(Object obj) {
70 boolean eq = false;
71 if (this.getClass().isInstance(obj)) {
72 Enum e = (Enum) obj;
73 eq = (_name.equals(e._name));
74 }
75 return eq;
76 }
77
78 /***
79 * Returns a hashcode value for the Enum.
80 * <p>
81 * It follows the contract defined by the Object hashCode() method.
82 * <p>
83 * @return the hashcode of the Enum object.
84 *
85 */
86 public int hashCode() {
87 return _name.hashCode();
88 }
89
90 }