1 
2  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
3  //                                                                        \\
4  //                 Centre for Speech Technology Research                  \\
5  //                      University of Edinburgh, UK                       \\
6  //                        Copyright (c) 1996,1997                         \\
7  //                         All Rights Reserved.                           \\
8  //   Permission is hereby granted, free of charge, to use and distribute  \\
9  //   this software and its documentation without restriction, including   \\
10  //   without limitation the rights to use, copy, modify, merge, publish,  \\
11  //   distribute, sublicense, and/or sell copies of this work, and to      \\
12  //   permit persons to whom this work is furnished to do so, subject to   \\
13  //   the following conditions:                                            \\
14  //    1. The code must retain the above copyright notice, this list of    \\
15  //       conditions and the following disclaimer.                         \\
16  //    2. Any modifications must be clearly marked as such.                \\
17  //    3. Original authors' names are not deleted.                         \\
18  //    4. The authors' names are not used to endorse or promote products   \\
19  //       derived from this software without specific prior written        \\
20  //       permission.                                                      \\
21  //   THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        \\
22  //   DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING      \\
23  //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   \\
24  //   SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     \\
25  //   FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    \\
26  //   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   \\
27  //   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          \\
28  //   ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       \\
29  //   THIS SOFTWARE.                                                       \\
30  //                                                                        \\
31  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
32  //                                                                        \\
33  //                  Author: Richard Caley (rjc@cstr.ed.ac.uk)             \\
34  //  --------------------------------------------------------------------  \\
35  //  Simple Enumerated type superclass.                                    \\
36  //                                                                        \\
37  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
38 
39 package cstr.util ;
40 
41 import java.lang.*;
42 import java.util.*;
43 import java.awt.*;
44 
45 public abstract class Enum
46 {
47   String name;
48   String longName;
49   Object info;
50   int index;
51 
getValuesTable()52   abstract public EnumValues getValuesTable();
53 
init(String n)54   protected static EnumValues init(String n)
55     {
56       return new EnumValues(n);
57     }
58 
Enum(String s, String ls, Object o)59   protected Enum(String s, String ls, Object o)
60     {
61       setup(s, ls, o);
62     }
63 
Enum(String s, String ls, boolean real)64   protected Enum(String s, String ls, boolean real)
65     {
66       setup(s, ls, real?null:Enum.class);
67     }
68 
setup(String s, String ls, Object o)69   protected void setup(String s, String ls, Object o)
70     {
71       name=s;
72       longName=ls;
73       info=o;
74 
75       EnumValues values = getValuesTable();
76 
77       index=values.add(this);
78     }
79 
alias(String a)80   protected void alias(String a)
81     {
82       EnumValues values = getValuesTable();
83       values.add(this, a);
84     }
85 
getValue(String s, EnumValues values)86   protected static Enum getValue(String s, EnumValues values)
87     throws IllegalArgumentException
88     {
89       return values.getValue(s);
90     }
91 
getValues(EnumValues values)92   protected static Object getValues(EnumValues values)
93     {
94       return (Object)values.getValues();
95     }
96 
isReal()97   public boolean isReal()
98     {
99       return info != Enum.class;
100     }
101 
toString()102   public String toString()
103     {
104       return name;
105     }
106 
toString(boolean lng)107   public String toString(boolean lng)
108     {
109       return lng?longName:name;
110     }
111 
getInfo()112   public Object getInfo()
113     {
114       return info;
115     }
116 
117 }
118