public class EnumDomain
extends java.lang.Object
String
elements.
It contains a list of all elements in that domain.
Each element is a reference to DomainElement (not visible).
Domain can be searched for elements by giving it's index or name.
You can compare elements in domain. Higher index means that the element follows another one (with lower index). The index is assigned when you add elements to the domain, so the earlier element is added, the lower is it's index (starting from zero). Each element's name is uniqe in the domain (it has only one index assigned to it).
Constructor | Description |
---|---|
EnumDomain() |
Creates an empty domain.
|
EnumDomain(java.lang.String[] elements) |
Creates a domain and sets elements from the table.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addElement(java.lang.String name) |
Creates a new element and stores it in the domain.
|
boolean |
compareTo(java.lang.Object arg0) |
Compares two enum domains.
|
int |
getIndex(java.lang.String value) |
Looking for an element with given name.
|
java.lang.String |
getName(int index) |
Returns name of an element in specified position in the domain.
|
int |
size() |
Reads the size of the domain.
|
java.lang.String |
toString() |
Returns a
String which contains a set of names of all elements from the domain. |
public EnumDomain()
addElement(String)
public EnumDomain(java.lang.String[] elements)
elements
- string table with elements of the domainInvalidValueException
- when the name in the table is incorrectjava.lang.NullPointerException
- when param (table or its element) is nulladdElement(String)
public int getIndex(java.lang.String value)
value
- name of the elementInvalidValueException
- if the element hasn't been foundjava.lang.NullPointerException
- when the name is nullpublic java.lang.String getName(int index)
index
- position in the domainInvalidValueException
- when the index is out of boundspublic int size()
public void addElement(java.lang.String name)
name
- value of the element;
it must be a number [0-9]+
or an identifier [A-Za-z_][A-Za-z_0-9]*
InvalidValueException
- when tha name doesn't match the patternjava.lang.NullPointerException
- when tha name is nullpublic java.lang.String toString()
String
which contains a set of names of all elements from the domain.
Elements are listed enclosed in brackets and separated by commas.toString
in class java.lang.Object
public boolean compareTo(java.lang.Object arg0)
DomainElement.compareTo
method).arg0
- object to be compared to this enum domain (should be also enum domain)true
if two domains are equal, false
otherwisejava.lang.ClassCastException
- if given object is not EnumDomain
java.lang.NullPointerException
- when the object is null