|
sharkysoft.com | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.sharkysoft.util.EnumeratedType
Type-safe enumeration.
Details: An EnumeratedType defines a finite set of
values for a property.
In C, enumerate types are typically represented using the
enum construct. This offers many of the benefits of
type-ints to represent the values. Unfortunately, Java has no such
construct, and it has become common and acceptable to directly represent
enumerated types using final ints. Unfortunately, this
adaptation lacks type safety.
EnumeratedType facilitates the declaration of type-ints and typed objects. Methods that accept or return
enumerated types can do so using type-ints when necessary, such as
in a switch statement. Using enumerated types derived from this
base class not only encourages healthy code, but it also makes debugging
easier, since each type-toString.
| Constructor Summary | |
protected |
EnumeratedType(int inValue,
java.lang.String isString)
Initializes type-safe object value. |
| Method Summary | |
int |
compareTo(java.lang.Object ipValue)
Orders enumerated values. |
static EnumeratedType |
toEnumeratedType(int inValue)
Converts int value to object value. |
int |
toInt()
Converts object value to integer value. |
java.lang.String |
toString()
Converts object value to string form. |
static java.lang.String |
toString(int inValue)
Converts integer value to string form. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
protected EnumeratedType(int inValue,
java.lang.String isString)
Details: This constructor initializes type-safe object values.
inValue is the magic int value associated with
the enumerated value (usually declared as public static final
int in the subclass). isString is the string
representation of the same value, which is usually just the
int identifier in string form.
inValue - int representation of valueisString - string representation of value| Method Detail |
public int toInt()
Details: toInt returns the unique "magic
integer" associated with this type-safe value. This is useful in
switch statements and other situations where int
represention of the value might be more efficient.
public java.lang.String toString()
Details: toString converts this type-
public static EnumeratedType toEnumeratedType(int inValue)
Details: toEnumeratedType returns the type-int value.
Because this is a generic implementation that returns an
EnumeratedType, rather than the specific object type related
defined by the subclass, it is a good idea to define a static
helper method in the subclass that returns a more specifically typed
value.
inValue - integer value
public static java.lang.String toString(int inValue)
Details: toString converts the given integer value
to a string. This may be useful for debugging.
inValue - integer value
public int compareTo(java.lang.Object ipValue)
Details: compareTo satisfies the contract of
compareTo in interface java.lang.Comparable.
Enumerated values are ordered according to their magic integer.
This implementation throws a ClassCastException if one
object's class does not descend from the other object's class.
compareTo in interface java.lang.ComparableipValue - value to commpare
|
sharkysoft.com | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
Copyright © 1997-2004 Sharkysoft (sharkysoft.com). All rights reserved.