
edu.nps.moves.disenum.RestStatus Maven / Gradle / Ivy
Show all versions of dis-enums Show documentation
package edu.nps.moves.disenum;
import java.util.HashMap;
import edu.nps.moves.siso.EnumNotFoundException;
/** Enumeration values for RestStatus
* The enumeration values are generated from the SISO DIS XML EBV document (R35), which was
* obtained from http://discussions.sisostds.org/default.asp?action=10&fd=31
*
* Note that this has two ways to look up an enumerated instance from a value: a fast
* but brittle array lookup, and a slower and more garbage-intensive, but safer, method.
* if you want to minimize memory use, get rid of one or the other.
*
* Copyright 2008-2009. This work is licensed under the BSD license, available at
* http://www.movesinstitute.org/licenses
*
* @author DMcG, Jason Nelson
*/
public enum RestStatus
{
NOT_RESTED_HAS_NOT_SLEPT_IN_THE_LAST_THREE_DAYS(0, "Not rested (Has not slept in the last three days)"),
HAS_SLEPT_AN_AVERAGE_OF_1_HOUR_PER_DAY_IN_THE_LAST_THREE_DAYS(1, "Has slept an average of 1 hour per day in the last three days."),
HAS_SLEPT_AN_AVERAGE_OF_2_HOURS_PER_DAY_IN_THE_LAST_THREE_DAYS(2, "Has slept an average of 2 hours per day in the last three days."),
HAS_SLEPT_AN_AVERAGE_OF_3_HOURS_PER_DAY_IN_THE_LAST_THREE_DAYS(3, "Has slept an average of 3 hours per day in the last three days."),
HAS_SLEPT_AN_AVERAGE_OF_4_HOURS_PER_DAY_IN_THE_LAST_THREE_DAYS(4, "Has slept an average of 4 hours per day in the last three days."),
HAS_SLEPT_AN_AVERAGE_OF_5_HOURS_PER_DAY_IN_THE_LAST_THREE_DAYS(5, "Has slept an average of 5 hours per day in the last three days."),
HAS_SLEPT_AN_AVERAGE_OF_6_HOURS_PER_DAY_IN_THE_LAST_THREE_DAYS(6, "Has slept an average of 6 hours per day in the last three days."),
HAS_SLEPT_AN_AVERAGE_OF_7_HOURS_PER_DAY_IN_THE_LAST_THREE_DAYS(7, "Has slept an average of 7 hours per day in the last three days."),
FULLY_RESTED_HAS_SLEPT_AN_AVERAGE_OF_8_HOURS_PER_DAY_IN_THE_LAST_THREE_DAYS(8, "Fully rested (Has slept an average of 8 hours per day in the last three days)");
/** The enumerated value */
public final int value;
/** Text/english description of the enumerated value */
public final String description;
/** This is an array, with each slot corresponding to an enumerated value. This is a fast but brittle way to look up
* enumerated values. If there is no enumeration corresponding to the value it will fail, and it will also fail if the
* index it out of range of the array. But it is fast, and generates less garbage than the alternative of using
* getEnumerationForValue(). It should be used only in real-time environments, and be careful even then.
* Use as RestStatus.lookup[aVal] to get the enumeration that corresponds to a value.
* In non-realtime environments, the prefered method is getEnumerationForValue().
*/
static public RestStatus lookup[] = new RestStatus[9];
static private HashMapenumerations = new HashMap();
/* initialize the array and hash table at class load time */
static
{
for(RestStatus anEnum:RestStatus.values())
{
lookup[anEnum.value] = anEnum;
enumerations.put(new Integer(anEnum.getValue()), anEnum);
}
}
/** Constructor */
RestStatus(int value, String description)
{
this.value = value;
this.description = description;
}
/** Returns the string description associated with the enumerated instance with this value.
* If there is no enumerated instance for this value, the string Invalid enumeration: is returned.
*/
static public String getDescriptionForValue(int aVal)
{
String desc;
RestStatus val = enumerations.get(new Integer(aVal));
if(val == null)
desc = "Invalid enumeration: " + (new Integer(aVal)).toString();
else
desc = val.getDescription();
return desc;
}
/** Returns the enumerated instance with this value.
* If there is no enumerated instance for this value, the exception is thrown.
*/
static public RestStatus getEnumerationForValue(int aVal) throws EnumNotFoundException
{
RestStatus val;
val = enumerations.get(new Integer(aVal));
if(val == null)
throw new EnumNotFoundException("no enumeration found for value " + aVal + " of enumeration RestStatus");
return val;
}
/** Returns true if there is an enumerated instance for this value, false otherwise.
*/
static public boolean enumerationForValueExists(int aVal)
{
RestStatus val;
val = enumerations.get(new Integer(aVal));
if(val == null)
return false;
return true;
}
/** Returns the enumerated value for this enumeration */
public int getValue()
{
return value;
}
/** Returns a text descriptioni for this enumerated value. This is usually used as the basis for the enumeration name. */
public String getDescription()
{
return description;
}
}