Package com.onwbp.base.text
Class Nomenclature<T>
- java.lang.Object
-
- com.onwbp.base.text.Nomenclature<T>
-
public class Nomenclature<T> extends Object
ANomenclature
is an ordered collection ofNomenclatureItem
instances.- See Also:
NomenclatureItem
-
-
Field Summary
Fields Modifier and Type Field Description static Step
_items
static Comparator
ComparatorByLabel
static Nomenclature
EMPTY
-
Constructor Summary
Constructors Constructor Description Nomenclature()
Creates aNomenclature
with label size equal to 1.Nomenclature(int numberOfLabels)
Creates aNomenclature
with the specified label size.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Nomenclature<T>
addItem(NomenclatureItem<T> anItem)
Adds aNomenclatureItem
to this instance.Nomenclature<T>
addItemValue(T aValue, String aLabel)
Adds aNomenclatureItemValue
with the specified content to this instance.Nomenclature<T>
addItemValue(T aValue, String[] labels)
Adds to this instance aNomenclatureItemValue
with the specified content.Nomenclature<T>
addItemValue(T aValue, String[] labels, Locale[] locales)
Adds aNomenclatureItemValue
with the specified content to this instance.Nomenclature<T>
addItemWithMessage(T aValue, UserMessage aMessage)
Adds aNomenclatureItemWithMessage
with the specified content to this instance.Nomenclature<T>
addNomenclature(Nomenclature<T> anotherNomenclature)
Adds all the items of the specifiedNomenclature
to this instance.static <T> Comparator<NomenclatureItem<T>>
comparatorByLabel()
Returns a label comparator.static <T> Nomenclature<T>
empty()
Returns the empty nomenclature (immutable).boolean
equals(Object x)
NomenclatureItem<T>
findNomenclatureItemWithValue(Object aSearchedValue)
Returns the firstNomenclatureItem
whose value is equal to the argument.List<T>
getAllValues()
Returns all the item's values.static <U> Comparator<NomenclatureItem<U>>
getComparatorByLabel()
List<NomenclatureItem<T>>
getItems()
Returns all items (internal, used for debug tag)NomenclatureItem<T>
getItems(int index)
Returns the item at the specified position in thisNomenclature
.Iterator<NomenclatureItem<T>>
getItemsIterator()
Returns an iterator over all the items of thisNomenclature
.int
getLabelsSize()
Returns the number of labels that each item of thisNomenclature
must have.int
getSize()
Returns the number of items in thisNomenclature
.int
hashCode()
void
setItems(List<NomenclatureItem<T>> aList)
void
setLastItemAsDefault(boolean isDefault)
Set the default to the last added item.void
sortByLabel()
String
toString()
-
-
-
Field Detail
-
_items
public static final Step _items
-
EMPTY
public static final Nomenclature EMPTY
-
ComparatorByLabel
public static final Comparator ComparatorByLabel
-
-
Method Detail
-
empty
public static final <T> Nomenclature<T> empty()
Returns the empty nomenclature (immutable). Unlike the like-named field, this method is parameterized.- Since:
- 5.8.1
-
comparatorByLabel
public static final <T> Comparator<NomenclatureItem<T>> comparatorByLabel()
Returns a label comparator. Unlike the like-named field, this method is parameterized.- Since:
- 5.8.1
-
addItem
public Nomenclature<T> addItem(NomenclatureItem<T> anItem) throws IllegalArgumentException
Adds aNomenclatureItem
to this instance. The item is added at the end of the ordered list of items.- Returns:
- this instance
- Throws:
IllegalArgumentException
- If the item to be added does not have the same number of labels as the number specified in this constructor.- See Also:
Nomenclature(int)
,addNomenclature(com.onwbp.base.text.Nomenclature<T>)
-
addItemValue
public Nomenclature<T> addItemValue(T aValue, String[] labels)
Adds to this instance aNomenclatureItemValue
with the specified content.
-
addItemValue
public Nomenclature<T> addItemValue(T aValue, String[] labels, Locale[] locales)
Adds aNomenclatureItemValue
with the specified content to this instance. Each label corresponds to the locale at the same index.
-
addItemValue
public Nomenclature<T> addItemValue(T aValue, String aLabel)
Adds aNomenclatureItemValue
with the specified content to this instance.
-
addItemWithMessage
public Nomenclature<T> addItemWithMessage(T aValue, UserMessage aMessage)
Adds aNomenclatureItemWithMessage
with the specified content to this instance.- Since:
- 5.7.1
- See Also:
addItem(com.onwbp.base.text.NomenclatureItem<T>)
-
addNomenclature
public Nomenclature<T> addNomenclature(Nomenclature<T> anotherNomenclature) throws RuntimeException
Adds all the items of the specifiedNomenclature
to this instance. Items are added in the same order at the end of the list of items.- Returns:
- this instance
- Throws:
RuntimeException
- If the nomenclature to be added does not have the same number of labels as the number specified in this instance.- See Also:
addItem(com.onwbp.base.text.NomenclatureItem<T>)
-
findNomenclatureItemWithValue
public NomenclatureItem<T> findNomenclatureItemWithValue(Object aSearchedValue)
Returns the firstNomenclatureItem
whose value is equal to the argument. Returnsnull
if no item is found.
-
getAllValues
public List<T> getAllValues()
Returns all the item's values. Only items that returntrue
for the methodisValueItem()
are included in the returned list.- See Also:
NomenclatureItem.isValueItem()
-
getComparatorByLabel
public static final <U> Comparator<NomenclatureItem<U>> getComparatorByLabel()
-
getItems
public List<NomenclatureItem<T>> getItems()
Returns all items (internal, used for debug tag)
-
getItems
public NomenclatureItem<T> getItems(int index)
Returns the item at the specified position in thisNomenclature
.
-
getItemsIterator
public Iterator<NomenclatureItem<T>> getItemsIterator()
Returns an iterator over all the items of thisNomenclature
.
-
getLabelsSize
public int getLabelsSize()
Returns the number of labels that each item of thisNomenclature
must have.- See Also:
Nomenclature(int)
-
getSize
public int getSize()
Returns the number of items in thisNomenclature
.
-
setItems
public void setItems(List<NomenclatureItem<T>> aList)
-
setLastItemAsDefault
public void setLastItemAsDefault(boolean isDefault) throws IllegalStateException
Set the default to the last added item.- Throws:
IllegalStateException
- If this nomenclature has no items- See Also:
NomenclatureItem.setDefaultItem(boolean)
-
sortByLabel
public void sortByLabel()
-
-