|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.kernel.util.NamedList
public final class NamedList
An ordered list of objects with names. The objects must implement the Nameable interface. The names are required to be unique and non-null.
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 Form
Green (cxh) |
Green (eal) |
Field Summary | |
---|---|
private Nameable |
_container
|
private java.util.HashMap<java.lang.String,Nameable> |
_hashedList
|
private boolean |
_hashEnabled
|
private java.util.LinkedList<Nameable> |
_namedList
|
private static java.lang.String |
_NULL_NAME_EXCEPTION_STRING
|
private static int |
_threshhold
|
Constructor Summary | |
---|---|
NamedList()
Construct an empty NamedList with no container. |
|
NamedList(Nameable container)
Construct an empty list with a Nameable container. |
|
NamedList(NamedList original)
Copy constructor. |
Method Summary | |
---|---|
private int |
_getIndexOf(java.lang.String name)
|
private void |
_insertAt(int index,
Nameable element)
|
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. |
private void |
enableHash()
|
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. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private Nameable _container
private static final int _threshhold
private java.util.LinkedList<Nameable> _namedList
private java.util.HashMap<java.lang.String,Nameable> _hashedList
private boolean _hashEnabled
private static final java.lang.String _NULL_NAME_EXCEPTION_STRING
Constructor Detail |
---|
public NamedList()
public NamedList(Nameable container)
container
- The container (for error reporting).public NamedList(NamedList original)
original
- The list to copy.Method Detail |
---|
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()
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()
private int _getIndexOf(java.lang.String name)
private void _insertAt(int index, Nameable element) throws IllegalActionException, NameDuplicationException
IllegalActionException
NameDuplicationException
private void enableHash()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |