1 22 package org.jboss.test.cmp2.enums.ejb; 23 24 import java.io.Serializable ; 25 import java.io.ObjectStreamException ; 26 27 28 33 public abstract class ColorEnum 34 implements Serializable 35 { 36 private static int nextOrdinal = 0; 37 38 40 private static final ColorEnum VALUES[] = new ColorEnum[3]; 41 42 public static final ColorEnum RED = new Red("RED"); 43 public static final ColorEnum GREEN = new Green("GREEN"); 44 public static final ColorEnum BLUE = new Blue("BLUE"); 45 46 48 private final Integer ordinal; 49 private final transient String name; 50 51 53 private ColorEnum(String name) 54 { 55 this.name = name; 56 this.ordinal = new Integer (nextOrdinal++); 57 VALUES[ordinal.intValue()] = this; 58 } 59 60 62 Object readResolve() 63 throws ObjectStreamException 64 { 65 return VALUES[ordinal.intValue()]; 66 } 67 68 70 public Integer getOrdinal() 71 { 72 return ordinal; 73 } 74 75 public String toString() 76 { 77 return name; 78 } 79 80 public ColorEnum valueOf(int ordinal) 81 { 82 return VALUES[ordinal]; 83 } 84 85 87 private static final class Red extends ColorEnum 88 { 89 public Red(String name) 90 { 91 super(name); 92 } 93 } 94 95 private static final class Green extends ColorEnum 96 { 97 public Green(String name) 98 { 99 super(name); 100 } 101 } 102 103 private static final class Blue extends ColorEnum 104 { 105 public Blue(String name) 106 { 107 super(name); 108 } 109 } 110 } 111 | Popular Tags |