KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > modfact > jmi > reflect > EnumType


1 package org.objectweb.modfact.jmi.reflect;
2
3 import javax.jmi.reflect.*;
4 import java.util.*;
5
6 public class EnumType implements java.io.Serializable JavaDoc {
7     
8     String JavaDoc[] typeName;
9     String JavaDoc[] labels;
10     RefEnum_impl[] enums;
11     
12     public EnumType() {
13     }
14     
15     EnumType(List typeName, List labels) {
16       this.typeName = (String JavaDoc[])typeName.toArray(new String JavaDoc[0]);
17       this.labels = (String JavaDoc[])labels.toArray(new String JavaDoc[0]);
18       enums = new RefEnum_impl[this.labels.length];
19       for(int i=0; i<this.labels.length; i++) {
20         enums[i] = new RefEnum_impl(i);
21       }
22     }
23     
24     public RefEnum getEnum(String JavaDoc label) {
25       for(int i=0; i<labels.length; i++) {
26         if(label.equals(labels[i]))
27             return enums[i];
28       }
29       throw new RuntimeException JavaDoc( typeName[typeName.length-1]
30             +": invalide label '" +label +"'");
31     }
32
33     private class RefEnum_impl implements javax.jmi.reflect.RefEnum, java.io.Serializable JavaDoc {
34     
35       private int index;
36     
37       public RefEnum_impl() {
38       }
39     
40       RefEnum_impl(int index) {
41         this.index = index;
42       }
43     
44       public java.util.List JavaDoc refTypeName() {
45         return RefBaseObjectImpl.arrayToList(typeName);
46       }
47     
48       public int hashCode() {
49         return labels[index].hashCode();
50       }
51       
52       public boolean equals(Object JavaDoc o) {
53         if(!(o instanceof RefEnum_impl)) return false;
54         RefEnum_impl other = (RefEnum_impl) o;
55         if(index != other.index) return false;
56         return refTypeName().equals(other.refTypeName());
57       }
58     
59       public String JavaDoc toString() {
60         return labels[index];
61       }
62   } // end nested Class
63
}
64
Popular Tags