View Javadoc

1   /*
2    * Copyright 2004 Sun Microsystems, Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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 == 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  }