Package com.onwbp.base.text
Class Nomenclature<T>
- java.lang.Object
-
- com.onwbp.base.text.Nomenclature<T>
-
public class Nomenclature<T> extends Object
ANomenclatureis an ordered collection ofNomenclatureIteminstances.- See Also:
NomenclatureItem
-
-
Field Summary
Fields Modifier and Type Field Description static Step_itemsstatic ComparatorComparatorByLabelstatic NomenclatureEMPTY
-
Constructor Summary
Constructors Constructor Description Nomenclature()Creates aNomenclaturewith label size equal to 1.Nomenclature(int numberOfLabels)Creates aNomenclaturewith 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 aNomenclatureItemto this instance.Nomenclature<T>addItemValue(T aValue, String aLabel)Adds aNomenclatureItemValuewith the specified content to this instance.Nomenclature<T>addItemValue(T aValue, String[] labels)Adds to this instance aNomenclatureItemValuewith the specified content.Nomenclature<T>addItemValue(T aValue, String[] labels, Locale[] locales)Adds aNomenclatureItemValuewith the specified content to this instance.Nomenclature<T>addItemWithMessage(T aValue, UserMessage aMessage)Adds aNomenclatureItemWithMessagewith the specified content to this instance.Nomenclature<T>addNomenclature(Nomenclature<T> anotherNomenclature)Adds all the items of the specifiedNomenclatureto this instance.static <T> Comparator<NomenclatureItem<T>>comparatorByLabel()Returns a label comparator.static <T> Nomenclature<T>empty()Returns the empty nomenclature (immutable).booleanequals(Object x)NomenclatureItem<T>findNomenclatureItemWithValue(Object aSearchedValue)Returns the firstNomenclatureItemwhose 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.intgetLabelsSize()Returns the number of labels that each item of thisNomenclaturemust have.intgetSize()Returns the number of items in thisNomenclature.inthashCode()voidsetItems(List<NomenclatureItem<T>> aList)voidsetLastItemAsDefault(boolean isDefault)Set the default to the last added item.voidsortByLabel()StringtoString()
-
-
-
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 aNomenclatureItemto 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 aNomenclatureItemValuewith the specified content.
-
addItemValue
public Nomenclature<T> addItemValue(T aValue, String[] labels, Locale[] locales)
Adds aNomenclatureItemValuewith 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 aNomenclatureItemValuewith the specified content to this instance.
-
addItemWithMessage
public Nomenclature<T> addItemWithMessage(T aValue, UserMessage aMessage)
Adds aNomenclatureItemWithMessagewith 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 specifiedNomenclatureto 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 firstNomenclatureItemwhose value is equal to the argument. Returnsnullif no item is found.
-
getAllValues
public List<T> getAllValues()
Returns all the item's values. Only items that returntruefor 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 thisNomenclaturemust 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 IllegalStateExceptionSet the default to the last added item.- Throws:
IllegalStateException- If this nomenclature has no items- See Also:
NomenclatureItem.setDefaultItem(boolean)
-
sortByLabel
public void sortByLabel()
-
-