1 22 package org.jboss.test.cmp2.enums.ejb; 23 24 29 public abstract class AnimalEnum 30 { 31 private static int nextOrdinal = 0; 32 33 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 43 private final Integer ordinal; 44 private final transient String name; 45 46 48 private AnimalEnum(String name) 49 { 50 this.name = name; 51 this.ordinal = new Integer (nextOrdinal++); 52 VALUES[ordinal.intValue()] = this; 53 } 54 55 57 59 public Integer getOrdinal() 60 { 61 return ordinal; 62 } 63 64 public String toString() 65 { 66 return name; 67 } 68 69 public AnimalEnum valueOf(int ordinal) 70 { 71 return VALUES[ordinal]; 72 } 73 74 76 private static final class Dog extends AnimalEnum 77 { 78 public Dog(String name) 79 { 80 super(name); 81 } 82 } 83 84 private static final class Cat extends AnimalEnum 85 { 86 public Cat(String name) 87 { 88 super(name); 89 } 90 } 91 92 private static final class Penguin extends AnimalEnum 93 { 94 public Penguin(String name) 95 { 96 super(name); 97 } 98 } 99 } 100 | Popular Tags |