KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > enums > ejb > AnimalEnum


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.enums.ejb;
23
24 /**
25  * Enum implementations for animals.
26  *
27  * @author <a HREF="mailto:gturner@unzane.com">Gerald Turner</a>
28  */

29 public abstract class AnimalEnum
30 {
31    private static int nextOrdinal = 0;
32
33    // Constants
34

35    private static final AnimalEnum VALUES[] = new AnimalEnum[3];
36
37    public static final AnimalEnum DOG = new Dog("DOG");
38    public static final AnimalEnum CAT = new Cat("CAT");
39    public static final AnimalEnum PENGUIN = new Penguin("PENGUIN");
40
41    // Attributes
42

43    private final Integer JavaDoc ordinal;
44    private final transient String JavaDoc name;
45
46    // Constructor
47

48    private AnimalEnum(String JavaDoc name)
49    {
50       this.name = name;
51       this.ordinal = new Integer JavaDoc(nextOrdinal++);
52       VALUES[ordinal.intValue()] = this;
53    }
54
55    // Package
56

57    // Public
58

59    public Integer JavaDoc getOrdinal()
60    {
61       return ordinal;
62    }
63
64    public String JavaDoc toString()
65    {
66       return name;
67    }
68
69    public AnimalEnum valueOf(int ordinal)
70    {
71       return VALUES[ordinal];
72    }
73
74    // Inner
75

76    private static final class Dog extends AnimalEnum
77    {
78       public Dog(String JavaDoc name)
79       {
80          super(name);
81       }
82    }
83
84    private static final class Cat extends AnimalEnum
85    {
86       public Cat(String JavaDoc name)
87       {
88          super(name);
89       }
90    }
91
92    private static final class Penguin extends AnimalEnum
93    {
94       public Penguin(String JavaDoc name)
95       {
96          super(name);
97       }
98    }
99 }
100
Popular Tags