|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectptolemy.graph.LabeledList
public class LabeledList
A list of unique objects (elements) with a mapping from the elements into consecutive integer labels. The labels are consecutive integers between 0 and N-1 inclusive, where N is the total number of elements in the list. This list features O(1) list insertion, O(1) testing for membership in the list, O(1) access of a list element from its associated label, and O(1) access of a label from its corresponding element. Removal from the list is, however, an O(1) operation. The element labels are useful, for example, in creating mappings from list elements into elements of arbitrary arrays. More generally, element labels can be used to maintain arbitrary m-dimensional matrices that are indexed by the list elements (via the associated element labels).
Element labels maintain their consistency (remain constant) during
periods when no elements are removed from the list. When elements are
removed, the labels assigned to the remaining elements may
change (see remove(Object) for details).
Elements themselves must be non-null and distinct, as determined by the
equals method.
This class supports all required operations of
the List interface, except
for the List.subList(int, int) operation,
which results in an UnsupportedOperationException.
| Red (cxh) |
| Red (cxh) |
| Field Summary | |
|---|---|
private java.util.ArrayList |
_elements
The elements that are associated with this list. |
private java.util.HashMap |
_labels
Translation from list element to label. |
| Constructor Summary | |
|---|---|
LabeledList()
Construct an empty list. |
|
LabeledList(int size)
Construct an empty list with enough storage allocated to hold the specified number of elements. |
|
| Method Summary | |
|---|---|
private java.lang.String |
_elementDump(java.lang.Object element)
Return a dump of a list element that is suitable for inclusion in an error message. |
private void |
_labelElements(int startIndex)
Fill in the labels map with the appropriate indices of the array list, starting at a specified index. |
void |
add(int index,
java.lang.Object element)
Unsupported optional method of the List interface. |
boolean |
add(java.lang.Object element)
Add an element to the list. |
boolean |
addAll(java.util.Collection collection)
Unsupported optional method of the List interface. |
boolean |
addAll(int index,
java.util.Collection collection)
Unsupported optional method of the List interface. |
void |
clear()
Clear all of the elements in this list. |
boolean |
contains(java.lang.Object object)
Return true if the specified object is an element of this list. |
boolean |
containsAll(java.util.Collection collection)
Returns true if this list contains all of the elements of the specified collection. |
boolean |
equals(java.lang.Object object)
Compares the specified object with this list for equality. |
java.lang.Object |
get(int label)
Return the element that has a specified label. |
int |
hashCode()
Return the hash code value for this list. |
int |
indexOf(java.lang.Object element)
Return the label in this list of the specified element; return -1 if the element is null or this list does not contain the element. |
boolean |
isEmpty()
Returns true if this list contains no elements. |
java.util.Iterator |
iterator()
Return an iterator over the elements in the list. |
int |
label(java.lang.Object element)
Return the label of the specified element. |
int |
lastIndexOf(java.lang.Object element)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. |
java.util.ListIterator |
listIterator()
Return a list iterator over the elements in the list. |
java.util.ListIterator |
listIterator(int index)
Return a list iterator over the elements in this list, starting at a specified position in the list. |
java.lang.Object |
remove(int label)
Remove and return an element with a specified label from this list. |
boolean |
remove(java.lang.Object element)
Remove an element from this list. |
boolean |
removeAll(java.util.Collection collection)
Unsupported optional method of the List interface. |
boolean |
retainAll(java.util.Collection collection)
Unsupported optional method of the List interface. |
java.lang.Object |
set(int index,
java.lang.Object element)
Unsupported optional method of the List interface. |
int |
size()
Return the number of elements in this list. |
java.util.List |
subList(int fromIndex,
int toIndex)
Unsupported method of the List interface. |
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this list in proper sequence. |
java.lang.Object[] |
toArray(java.lang.Object[] array)
Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array. |
java.lang.String |
toString()
Return a string representation of this list with elements separated by new lines, and element labels omitted from the representation. |
java.lang.String |
toString(java.lang.String delimiter,
boolean includeLabels)
Return a string representation of this list, given a delimiter for separating successive elements, and a flag that indicates whether element labels should be included in the string. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private java.util.ArrayList _elements
private java.util.HashMap _labels
| Constructor Detail |
|---|
public LabeledList()
public LabeledList(int size)
size - The number of elements.| Method Detail |
|---|
public boolean add(java.lang.Object element)
add in interface java.util.Collectionadd in interface java.util.Listelement - The element to insert.
java.lang.IllegalArgumentException - If the specified element is null,
or if it already exists in the list.
public void add(int index,
java.lang.Object element)
add in interface java.util.Listindex - Unused.element - Unused.
java.lang.UnsupportedOperationException - Always thrown.public boolean addAll(java.util.Collection collection)
addAll in interface java.util.CollectionaddAll in interface java.util.Listcollection - Unused.
java.lang.UnsupportedOperationException - Always thrown.
public boolean addAll(int index,
java.util.Collection collection)
addAll in interface java.util.Listindex - Unused.collection - Unused.
java.lang.UnsupportedOperationException - Always thrown.public void clear()
clear in interface java.util.Collectionclear in interface java.util.Listpublic boolean contains(java.lang.Object object)
contains in interface java.util.Collectioncontains in interface java.util.Listobject - The specified object.
public boolean containsAll(java.util.Collection collection)
containsAll in interface java.util.CollectioncontainsAll in interface java.util.Listcollection - The specified collection.
public boolean equals(java.lang.Object object)
equals in interface java.util.Collectionequals in interface java.util.Listequals in class java.lang.Objectobject - The object.
public java.lang.Object get(int label)
get in interface java.util.Listlabel - The label.
java.lang.IndexOutOfBoundsException - If there is no element that
has the specified label.public int hashCode()
hashCode in interface java.util.CollectionhashCode in interface java.util.ListhashCode in class java.lang.Objectpublic int indexOf(java.lang.Object element)
indexOf in interface java.util.Listelement - The element.
label(Object)public boolean isEmpty()
isEmpty in interface java.util.CollectionisEmpty in interface java.util.Listpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listpublic final int label(java.lang.Object element)
element - The specified element.
java.lang.IllegalArgumentException - If the specified element is not
in this list.
java.lang.NullPointerException - If the specified element is null.indexOf(Object)public int lastIndexOf(java.lang.Object element)
indexOf(Object), and is maintained only for conformance
with the list interface.
lastIndexOf in interface java.util.Listpublic java.util.ListIterator listIterator()
listIterator in interface java.util.Listpublic java.util.ListIterator listIterator(int index)
listIterator in interface java.util.Listindex - The specified starting position.
public boolean remove(java.lang.Object element)
remove in interface java.util.Collectionremove in interface java.util.Listelement - The element.
public java.lang.Object remove(int label)
remove in interface java.util.Listlabel - The specified label.
java.lang.IndexOutOfBoundsException - If there is no element with
the specified label.public boolean removeAll(java.util.Collection collection)
removeAll in interface java.util.CollectionremoveAll in interface java.util.Listcollection - Unused.
java.lang.UnsupportedOperationException - Always thrown.public boolean retainAll(java.util.Collection collection)
retainAll in interface java.util.CollectionretainAll in interface java.util.Listcollection - Unused.
java.lang.UnsupportedOperationException - Always thrown.
public java.lang.Object set(int index,
java.lang.Object element)
set in interface java.util.Listindex - Unused.element - Unused.
java.lang.UnsupportedOperationException - Always thrown.public int size()
size in interface java.util.Collectionsize in interface java.util.List
public java.util.List subList(int fromIndex,
int toIndex)
subList in interface java.util.ListfromIndex - Unused.toIndex - Unused.
java.lang.UnsupportedOperationException - Always thrown.public java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in interface java.util.Listpublic java.lang.Object[] toArray(java.lang.Object[] array)
toArray in interface java.util.CollectiontoArray in interface java.util.Listarray - The specified array.
public java.lang.String toString(java.lang.String delimiter,
boolean includeLabels)
delimiter - The delimiter that separates elements in the
generated string.includeLabels - If this is true, then precede each
element with its label (followed by a colon and space) in the
generated string; otherwise, omit the labels.
public java.lang.String toString()
toString in class java.lang.Objectprivate java.lang.String _elementDump(java.lang.Object element)
private void _labelElements(int startIndex)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||