|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.dpml.lang.Enum
net.dpml.lang.ValuedEnum
public abstract class ValuedEnum
Basic enum class for type-safe enums with values. Valued enum items can be compared and ordered with the provided methods. Should be used as an abstract base. For example:
import net.dpml.lang.ValuedEnum;
public final class JavaVersion
extends ValuedEnum
{
//standard enums for version of JVM
public static final JavaVersion JAVA1_0 = new JavaVersion( "Java 1.0", 100 );
public static final JavaVersion JAVA1_1 = new JavaVersion( "Java 1.1", 110 );
public static final JavaVersion JAVA1_2 = new JavaVersion( "Java 1.2", 120 );
public static final JavaVersion JAVA1_3 = new JavaVersion( "Java 1.3", 130 );
public static final JavaVersion JAVA1_4 = new JavaVersion( "Java 1.4", 140 );
private JavaVersion( final String name, final int value )
{
super( name, value );
}
}
Usage:
JavaVersion requiredVer = JavaVersion.JAVA1_2;
public Widget( Context context )
{
JavaVersion ver = (JavaVersion)context.get("java.version");
if( ver.isLessThan( requiredVer ) )
{
throw new RuntimeException( requiredVer.getName()+ " or higher required" );
}
}
}
As with Enum, the ValuedEnum(String, int, Map) constructor can be used to
populate a Map, from which further functionality can be derived.
| Constructor Summary | |
|---|---|
protected |
ValuedEnum(String name,
int value)
Constructor for enum item. |
protected |
ValuedEnum(String name,
int value,
Map map)
Constructor for enum item so that it gets added to Map at creation. |
| Method Summary | |
|---|---|
int |
compareTo(Object other)
Compare this instance with the supplied object. |
boolean |
equals(Object o)
Tests for equality. |
int |
getValue()
Get value of enum item. |
int |
hashCode()
Compute the hashcode value. |
boolean |
isEqualTo(ValuedEnum other)
Test if enum item is equal in value to other enum. |
boolean |
isGreaterThan(ValuedEnum other)
Test if enum item is greater than in value to other enum. |
boolean |
isGreaterThanOrEqual(ValuedEnum other)
Test if enum item is greater than or equal in value to other enum. |
boolean |
isLessThan(ValuedEnum other)
Test if enum item is less than in value to other enum. |
boolean |
isLessThanOrEqual(ValuedEnum other)
Test if enum item is less than or equal in value to other enum. |
String |
toString()
Override toString method to produce human readable description. |
| Methods inherited from class net.dpml.lang.Enum |
|---|
getName |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
protected ValuedEnum(String name,
int value)
name - the name of enum item.value - the value of enum item.
protected ValuedEnum(String name,
int value,
Map map)
name - the name of enum item.value - the value of enum item.map - the Map to add enum item to.| Method Detail |
|---|
public final int getValue()
public final boolean isEqualTo(ValuedEnum other)
other - the other enum
public final boolean isGreaterThan(ValuedEnum other)
other - the other enum
public final boolean isGreaterThanOrEqual(ValuedEnum other)
other - the other enum
public final boolean isLessThan(ValuedEnum other)
other - the other enum
public final boolean isLessThanOrEqual(ValuedEnum other)
other - the other enum
public boolean equals(Object o)
equals in class Enumo - the other object
public int hashCode()
hashCode in class Enumpublic String toString()
toString in class Enumtype:name#value, eg.:
JavaVersion[Java 1.0=100].public int compareTo(Object other)
compareTo in interface Comparableother - the object to compare against
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||