shared
Class MEnum

java.lang.Object
  |
  +--shared.MEnum

public class MEnum
extends java.lang.Object

The MEnum class implements a dynamic enumeration type. This type is implemented using a list of (name, value) pairs which define the enumeration. The same name is assumed not to appear twice in the list. We do not check for this condition until the destructor because it requires time quadratic on the length of the list to check.


Constructor Summary
MEnum()
          Constructor.
MEnum(MEnum other)
          Copy constructor.
MEnum(java.lang.String name, int value)
          Constructor which takes a name and a value.
 
Method Summary
 void append(MEnum other)
          Appends one enumeration onto another.
 void assign(MEnum src)
          Makes this MEnum object equivalent to the given MEnum object.
 boolean check_value(int value)
          Checks if the value is not in this MEnum object.
 void display(java.io.Writer out)
          Displays the enumeration.
 void display(java.io.Writer out, boolean full)
          Displays the enumeration.
 java.lang.String name_from_value(int value)
          Finds the name given a value.
 void OK()
          Invariant checker.
 int value_from_name(java.lang.String name)
          Finds a value given its name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MEnum

public MEnum()
Constructor.

MEnum

public MEnum(java.lang.String name,
             int value)
Constructor which takes a name and a value. Creates an enumeration with one element.
Parameters:
name - The name of a value to be placed in this MEnum object.
value - The value to be placed in this MEnum object.

MEnum

public MEnum(MEnum other)
Copy constructor. We need this or we won't be able to do nice initialization This is also a nice place to put a sanity check (debug mode only). This results in having the sanity check performed once on initialization, which is reasonable.
Parameters:
other - The MEnum object to be copied.
Method Detail

OK

public void OK()
Invariant checker. Checks array bounds, and checks for negative values, null names, and duplicate names. This takes O(n^2), so we surrounded it with DBG statements, (in the caller) and call it rarely.

append

public void append(MEnum other)
Appends one enumeration onto another. Returns the resulting combined enumeration so that operations may be chained.
Parameters:
other - The MEnum object to be appended to this MEnum object.

assign

public void assign(MEnum src)
Makes this MEnum object equivalent to the given MEnum object.
Parameters:
src - The MEnum object to which this MEnum object will be equivalent.

display

public void display(java.io.Writer out,
                    boolean full)
Displays the enumeration. If full is TRUE, displays the values along with the names.
Parameters:
out - The Writer to which this MEnum object will be displayed.
full - TRUE if values are to be displayed with their names, FALSE if only names are to be displayed.

display

public void display(java.io.Writer out)
Displays the enumeration. Does not display MEnum values.
Parameters:
out - The Writer to which this MEnum object will be displayed.

value_from_name

public int value_from_name(java.lang.String name)
Finds a value given its name. Returns -1 on failure. We return an error status rather than aborting because the functions which call this are part of the user interface code for the option help system.
Parameters:
name - The name for which a value is requested.
Returns:
The value associated with the name of -1 if the name is not found in this MEnum object.

name_from_value

public java.lang.String name_from_value(int value)
Finds the name given a value. In case we have two names for the same value, returns the first one in the list. If the value is not found, returns "".
Parameters:
value - The value for which a name is requested.
Returns:
The name associated with this value or an empty string if the value is not found in this MEnum object.
See Also:
value_from_name(String)

check_value

public boolean check_value(int value)
Checks if the value is not in this MEnum object.
Parameters:
value - The value to be checked.
Returns:
TRUE if the value is associated with a name.