package de.vanitasvitae.imi.codes; public enum SampleType { // Hard coded values. Prepended with an underscore to allow numeric values (eg. _2). _b('b', "Blood"), _u('u', "Urine"), ; // Members of the enum private final char name; private final String description; /** * Create a SampleType enum which is described by a name (one letter from the alphabet [a-zA-Z0-9]) and a * human readable description. * * @param name one letter name * @param description description */ SampleType(char name, String description) { this.name = name; this.description = description; } /** * Override {@link Enum#toString()} in order to return the name of the enum instead of its value. * * @return name */ @Override public String toString() { return "" + name; } /** * Return the human readable description of the enum. */ public String getDescription() { return description; } /** * Replacement method for {@link #valueOf(String)}. You MUST use this method instead, as we have to escape * the names of the enums with a underscore in order to allow for numerals to be used as enum name (for example "_0"). * This method takes a string value (eg. "u") and returns the corresponding enum ("_u"). * * @param name name of the enum without an underscore. * @return enum corresponding to the name. * * @throws IllegalArgumentException if no matching enum was found. */ public static SampleType getEnum(String name) { for (SampleType s : SampleType.values()) { if (s.toString().equals(name)) { return s; } } throw new IllegalArgumentException("No SampleType found for name \"" + name + "\"."); } }