public final class NamedList
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
This class is biased towards sequential accesses. If it is used with name lookups, the list should be small. It is implemented as a linked list rather than hash table to preserve ordering information, and thus would not provide efficient name lookup for large lists. Also, it permits the name of an object in the list to change without this list being informed.
An instance of this class may have a container, but that container is only used for error reporting.
Nameable
,
Serialized FormConstructor and Description |
---|
NamedList()
Construct an empty NamedList with no container.
|
NamedList(Nameable container)
Construct an empty list with a Nameable container.
|
NamedList(NamedList original)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
append(Nameable element)
Add an element to the end of the list.
|
java.lang.Object |
clone()
Build an independent copy of the list.
|
java.util.List |
elementList()
Return an unmodifiable list with the contents of this named list.
|
java.util.Enumeration |
elements()
Deprecated.
Use elementList() instead.
|
Nameable |
first()
Get the first element.
|
Nameable |
get(java.lang.String name)
Get an element by name.
|
boolean |
includes(Nameable element)
Return true if the specified object is on the list.
|
void |
insertAfter(java.lang.String name,
Nameable element)
Insert a new element after the specified element.
|
void |
insertBefore(java.lang.String name,
Nameable element)
Insert a new element before the specified element.
|
Nameable |
last()
Get the last element.
|
int |
moveDown(Nameable element)
Move the specified element down by one in the list.
|
int |
moveToFirst(Nameable element)
Move the specified element to the beginning of the list.
|
int |
moveToIndex(Nameable element,
int index)
Move the specified element to the specified position in the list.
|
int |
moveToLast(Nameable element)
Move the specified element to the end of the list.
|
int |
moveUp(Nameable element)
Move the specified element up by one in the list.
|
void |
prepend(Nameable element)
Add an element to the beginning of the list.
|
void |
remove(Nameable element)
Remove the specified element.
|
Nameable |
remove(java.lang.String name)
Remove an element specified by name.
|
void |
removeAll()
Remove all elements from the list.
|
int |
size()
Return the number of elements in the list.
|
java.lang.String |
toString()
Return a string description of the list.
|
public NamedList()
public NamedList(Nameable container)
container
- The container (for error reporting).public NamedList(NamedList original)
original
- The list to copy.public void append(Nameable element) throws IllegalActionException, NameDuplicationException
element
- Element to be added to the list.IllegalActionException
- If the argument has no name.NameDuplicationException
- If the name coincides with
an element already on the list.public java.lang.Object clone()
clone
in class java.lang.Object
public java.util.List elementList()
@Deprecated public java.util.Enumeration elements()
public Nameable first() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- If the list is empty.public Nameable get(java.lang.String name)
name
- The name of the desired element.public boolean includes(Nameable element)
element
- Element to be searched for in the list.public void insertAfter(java.lang.String name, Nameable element) throws IllegalActionException, NameDuplicationException
name
- The element after which to insert the new element.element
- The element to insert.IllegalActionException
- If the element to insert has no name.NameDuplicationException
- If the element to insert has a
name that coincides with one already on the list.public void insertBefore(java.lang.String name, Nameable element) throws IllegalActionException, NameDuplicationException
name
- The element before which to insert the new element.element
- The element to insert.IllegalActionException
- If the element to insert has no name.NameDuplicationException
- If the element to insert has a
name that coincides with one already on the list.public Nameable last() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- If the list is empty.public int moveDown(Nameable element) throws IllegalActionException
element
- Element to move down in the list.IllegalActionException
- If the argument is not
on the list.public int moveToFirst(Nameable element) throws IllegalActionException
element
- Element to move to the top of the list.IllegalActionException
- If the argument is not
on the list.public int moveToIndex(Nameable element, int index) throws IllegalActionException
element
- Element to move.index
- The position to which to move it.IllegalActionException
- If the argument is not
on the list, or if the specified position is out of range.public int moveToLast(Nameable element) throws IllegalActionException
element
- Element to move to the end of the list.IllegalActionException
- If the argument is not
on the list.public int moveUp(Nameable element) throws IllegalActionException
element
- Element to move up in the list.IllegalActionException
- If the argument is not
on the list.public void prepend(Nameable element) throws IllegalActionException, NameDuplicationException
element
- Element to be added to the list.IllegalActionException
- If the argument is not
on the list.IllegalActionException
- If the argument has no name.NameDuplicationException
- If the name coincides with
an element already on the list.public void remove(Nameable element)
element
- Element to be removed.public Nameable remove(java.lang.String name)
name
- Name of the element to be removed.public void removeAll()
public int size()
public java.lang.String toString()
toString
in class java.lang.Object