Package net.sf.basedb.util
Class Enumeration<K,V>
java.lang.Object
net.sf.basedb.util.Enumeration<K,V>
- All Implemented Interfaces:
Serializable
- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2017-04-11 08:43:47 +0200 (ti, 11 apr 2017) $
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate final List<Enumeration.Entry<K,
V>> private boolean
private static final long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
static Enumeration<String,
String> Create a new enumeration from a list strings.static Enumeration<String,
String> fromItems
(Collection<? extends Nameable> items, String noneOption) Create a new enumeration from a list of basic items.static Enumeration<String,
String> fromItems
(Collection<? extends Nameable> items, String noneOption, String noneValue) Create a new enumeration from a list of basic items.getEntriesByKey
(K key) Get a list with all entries that equals the given key.getEntriesByValue
(V value) Get a list with all entries that equals the given value.getEntry
(int index) getKey
(int index) getValue
(int index) boolean
isLocked()
void
lock()
void
remove
(int index) int
size()
void
sortKeys()
This method will sort the enumration on the keys usingCollections.sort(List, Comparator)
.void
This method will sort the enumration on the values usingCollections.sort(List, Comparator)
.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
entries
-
locked
private boolean locked
-
-
Constructor Details
-
Enumeration
public Enumeration()
-
-
Method Details
-
fromItems
public static Enumeration<String,String> fromItems(Collection<? extends Nameable> items, String noneOption) Create a new enumeration from a list of basic items. The key of the enumeration is the id of each item and the value is the name.- Parameters:
items
- A collection with itemsnoneOption
- If not null, this options will be inserted first in the enumeration with an empty string as the key
-
fromItems
public static Enumeration<String,String> fromItems(Collection<? extends Nameable> items, String noneOption, String noneValue) Create a new enumeration from a list of basic items. The key of the enumeration is the id of each item and the value is the name.- Parameters:
items
- A collection with itemsnoneOption
- If not null, this options will be inserted first in the enumeration with an empty string as the keynoneValue
- Value for the 'none' option (empty string by default)- Since:
- 3.11
-
from
Create a new enumeration from a list strings. The key and value are the same for each entry. A null value in the array will be translated to key="" and value="none"- Since:
- 3.11
-
isLocked
public boolean isLocked() -
lock
public void lock() -
size
public int size() -
add
-
getKey
-
getValue
-
getEntry
-
getEntriesByKey
Get a list with all entries that equals the given key.- Returns:
- A list which may be empty if no entries are found
- Since:
- 3.2.4
-
getEntriesByValue
Get a list with all entries that equals the given value.- Returns:
- A list which may be empty if no entries are found
- Since:
- 3.2.4
-
remove
public void remove(int index) -
sortKeys
public void sortKeys()This method will sort the enumration on the keys usingCollections.sort(List, Comparator)
. The comparator will try to use the keys 'compareTo' method if it implements the Comparable interface otherwilse it will treat the key as a String. -
sortValues
public void sortValues()This method will sort the enumration on the values usingCollections.sort(List, Comparator)
. The comparator will try to use the values 'compareTo' method if it implements the Comparable interface otherwilse it will treat the value as a String.
-