import org.apache.avalon.framework.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 );
private JavaVersion( final String name, final int value )
{
super( name, value );
}
}
The above class could then be used as follows:
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.context.ContextException;
public class MyComponent implements Contextualizable
{
JavaVersion requiredVer = JavaVersion.JAVA1_2;
public void contextualize(Context context)
throws ContextException
{
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.Note
between 4.0 and 4.1, the constructors' access has been changed
from public to protected. This is to prevent users
of the Enum breaking type-safety by defining new Enum items. All Enum items
should be defined in the Enum class, as shown above.
| Modifier and Type | Field and Description |
|---|---|
| private final int | m_value
The value contained in enum. |
| Access | Constructor and Description |
|---|---|
| protected | ValuedEnum(final String
the name of enum item. name, final int the value of enum item. value)Constructor for enum item. |
| protected | ValuedEnum(final String
the name of enum item. name, final int the value of enum item. value, final Map<K, V> the map)Map to add enum item to.Constructor for enum item so that it gets added to Map at creation. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: the equality statusthe other object o)Overrides org. |
| public final int | |
| public int | hashCode()
Overrides org. |
| public final boolean | Returns: true if equalthe other enum other)Test if enum item is equal in value to other enum. |
| public final boolean | Returns: true if greater thanthe other enum other)Test if enum item is greater than in value to other enum. |
| public final boolean | Returns: true if greater than or equalthe other enum other)Test if enum item is greater than or equal in value to other enum. |
| public final boolean | Returns: true if less thanthe other enum other)Test if enum item is less than in value to other enum. |
| public final boolean | Returns: true if less than or equalthe other enum other)Test if enum item is less than or equal in value to other enum. |
| public String | Returns: String in the formtype[name=value], eg.:
JavaVersion[Java 1.0=100].Overrides org. |
| m_value | back to summary |
|---|---|
| private final int m_value The value contained in enum. | |
| ValuedEnum | back to summary |
|---|---|
| protected ValuedEnum(final String name, final int value) Constructor for enum item. Note access changed from
| |
| ValuedEnum | back to summary |
|---|---|
| protected ValuedEnum(final String name, final int value, final Map<K, V> map) Constructor for enum item so that it gets added to Map at creation. Adding to a map is useful for implementing find...() style methods. Note access changed from | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides org. Tests for equality. Two Enum:s are considered equal if they are of the same class, have the same name, and same value.
| |
| getValue | back to summary |
|---|---|
| public final int getValue() Get value of enum item.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides org. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| isEqualTo | back to summary |
|---|---|
| public final boolean isEqualTo(final ValuedEnum other) Test if enum item is equal in value to other enum.
| |
| isGreaterThan | back to summary |
|---|---|
| public final boolean isGreaterThan(final ValuedEnum other) Test if enum item is greater than in value to other enum.
| |
| isGreaterThanOrEqual | back to summary |
|---|---|
| public final boolean isGreaterThanOrEqual(final ValuedEnum other) Test if enum item is greater than or equal in value to other enum.
| |
| isLessThan | back to summary |
|---|---|
| public final boolean isLessThan(final ValuedEnum other) Test if enum item is less than in value to other enum.
| |
| isLessThanOrEqual | back to summary |
|---|---|
| public final boolean isLessThanOrEqual(final ValuedEnum other) Test if enum item is less than or equal in value to other enum.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Override toString method to produce human readable description.
| |