Package adams.core
Class ConfigurableEnumeration<T extends ConfigurableEnumeration.AbstractItem>
- java.lang.Object
-
- adams.core.ConfigurableEnumeration<T>
-
- All Implemented Interfaces:
Serializable
,Iterable<T>
- Direct Known Subclasses:
ExifTagEnum
,PropertiesBasedEnumeration
public abstract class ConfigurableEnumeration<T extends ConfigurableEnumeration.AbstractItem> extends Object implements Serializable, Iterable<T>
A more flexible way for enumerations.- Version:
- $Revision$
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConfigurableEnumeration.AbstractItem<E extends ConfigurableEnumeration>
Represents a single item of an enumeration.
-
Constructor Summary
Constructors Constructor Description ConfigurableEnumeration()
Initializes the enumeration.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected T[]
check(T[] items)
Checks the uniqueness of the items.protected abstract T[]
initialize()
Initializes the items.Iterator<T>
iterator()
Returns an iterator over the items.abstract T
newItem(String id, String display)
Initializes the enum type.T
parse(String s)
Parses the given string and returns the associated Item, making use of label and ID.String
toString()
Just returns all the underlying items as comma-separated list.T[]
values()
Returns the items of the enumeration.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
m_Items
protected T extends ConfigurableEnumeration.AbstractItem[] m_Items
the items of the enumeration.
-
-
Method Detail
-
initialize
protected abstract T[] initialize()
Initializes the items.- Returns:
- the items
-
check
protected T[] check(T[] items)
Checks the uniqueness of the items. Also ensures that items are not null.- Parameters:
items
- the items to check- Returns:
- the items
- Throws:
IllegalArgumentException
- if not unique or null
-
values
public T[] values()
Returns the items of the enumeration.- Returns:
- the items
-
parse
public T parse(String s)
Parses the given string and returns the associated Item, making use of label and ID.- Parameters:
s
- the string to parse- Returns:
- the item, null if failed to locate item
-
newItem
public abstract T newItem(String id, String display)
Initializes the enum type.- Parameters:
id
- the ID of the enum type, can be nulldisplay
- the display text, can be null
-
iterator
public Iterator<T> iterator()
Returns an iterator over the items.- Specified by:
iterator
in interfaceIterable<T extends ConfigurableEnumeration.AbstractItem>
- Returns:
- the iterator
-
-