KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > util > Enum


1 /**
2  * $RCSfile: Enum.java,v $
3  * $Revision: 1.2 $
4  * $Date: 2004/10/21 07:28:12 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.util;
13
14 /**
15  * A type safe enumeration object. Used for indicating distinct states
16  * in a generic manner. Most child classes should extend Enum and
17  * create static instances.
18  *
19  * @author Iain Shigeoka
20  */

21 public class Enum {
22     private String JavaDoc name;
23
24     protected Enum(String JavaDoc name) {
25         this.name = name;
26     }
27
28     /**
29      * Returns the name of the enum.
30      *
31      * @return the name of the enum.
32      */

33     public String JavaDoc getName() {
34         return name;
35     }
36
37     public boolean equals(Object JavaDoc object) {
38         if (this == object) {
39             return true;
40         }
41         else if ((this.getClass().isInstance(object)) && name.equals(((Enum JavaDoc)object).name)) {
42             return true;
43         }
44         else {
45             return false;
46         }
47     }
48
49     public int hashCode() {
50         return name.hashCode();
51     }
52
53     public String JavaDoc toString() {
54         return name;
55     }
56 }
57
Popular Tags