|
Sydney | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Object | +--AbstractList
Defined in abstract_list.js
| Constructor Summary | |
AbstractList
()
An abstract base class for lists. |
|
| Method Summary | |
void
|
append(<Object> item)
Appends the given item to the end of the list. |
void
|
clear()
Empties the list. |
boolean
|
contains(<Object> item)
Searches the list for item and returns true if it
is found.
|
void
|
copy(<Object> source, <boolean> keepOldItems)
Copies the contents of the source into this list.
|
Object
|
getHead()
Returns the item at the head of the list. |
int
|
getIndexOf(<Object> item)
Returns the index of item in this list.
|
Object
|
getItemAfter(<Object> item)
Retrieves the item after item in this list.
|
Object
|
getItemAt(<int> index)
Returns the item in the list whose index is index.
|
Object
|
getItemBefore(<Object> item)
Retrieves the item before item in this list.
|
int
|
getLength()
Returns the length of the list. |
Object
|
getTail()
Returns the item at the tail of the list. |
void
|
insertAfter(<Object> newItem, <Object> oldItem)
Inserts newItem after oldItem.
|
void
|
insertBefore(<Object> newItem, <Object> oldItem)
Inserts newItem before oldItem.
|
void
|
insertItemAt(<Object> item, <int> index)
Inserts item at index index.
|
boolean
|
isEmpty()
Returns true if and only if the list is empty.
|
Iterator
|
iterator()
Returns an iterator on this list. |
string
|
join(<string> separator)
Joins the elements of the list into a string, separated by separator.
|
void
|
prepend(<Object> item)
Inserts item into this list before the head.
|
Object
|
remove(<Object> item)
Removes item from this list and returns it.
|
void
|
removeAll(<AbstractList> list)
Removes all elements from this list that are also in list.
|
Object
|
removeHead()
Removes the head of this list and returns it. |
Object
|
removeItemAt(<int> index)
Removes and returns the item at the given index. |
Object
|
removeTail()
Removes the tail of this list and returns it. |
Object
|
replace(<Object> newItem, <Object> oldItem)
Replaces oldItem with newItem in
this list.
|
Iterator
|
reverseIterator()
Returns a reverse iterator on this list. |
AbstractList
|
selectRangeInto(<Object> startObj, <Object> endObj, <AbstractList> list)
Selects all elements of this list between startObj and
endObj inclusive and copies them into list.
|
void
|
sort(<Function> comparator)
Destructively sorts the list. |
Array
|
toArray()
Returns an array containing the same items as this list, in the same order. |
string
|
toString()
Returns a string representation of this list. |
| Constructor Detail |
function AbstractList()
_getListPointerForIndex, _getListPointerForItem,
_insertAt, and _removeFrom).
| Method Detail |
void append(<Object> item)
item - the object to add to the end of the list.
void clear()
clear(), the list is
empty—list.getHead(),
list.getTail() will both return null and
list.getLength() will return 0.
Implementation note: this method removes the items from the list one at a time, starting with the tail.
boolean contains(<Object> item)
item and returns true if it
is found.
item - the value to search for
true if item is in the list and false otherwise.
void copy(<Object> source, <boolean> keepOldItems)
source into this list. If
keepOldItems is true, then the elements in
source will be appended to this list, otherwise this list is
cleared first.
source - either an Array, an AbstractList, or a single object. If source is an array or a list, source's elements will be copied into this list. If source is a single object, it will be copied into this list. If source is null or undefined, then no elements are added to this list (this means that list.copy(null, false) is equivalent to list.clear()).
keepOldItems - (Optional) - a boolean indicating whether or not to keep the items already in this list (true) or to clear this list before inserting any new items (false). Defaults to false.
Object getHead()
int getIndexOf(<Object> item)
item in this list. Returns
this.getLength() if item is not in the list.
Implementation note: this method makes use of iterators to find
item's index in linear time.
item - the item to look for
item, or this.getLength() if item is not in the list.
Object getItemAfter(<Object> item)
item in this list.
item - the item to search for
item
Object getItemAt(<int> index)
index.
index - the index of the item to return
index
Object getItemBefore(<Object> item)
item in this list.
item - the item to search for
item
int getLength()
Object getTail()
void insertAfter(<Object> newItem, <Object> oldItem)
newItem after oldItem.
Inserts newItem at the beginning of the list
if oldItem is not in the list.
newItem - the item to insert into this list
oldItem - the item to insert newItem after
void insertBefore(<Object> newItem, <Object> oldItem)
newItem before oldItem.
Inserts newItem at the end of the list if
oldItem is not in the list.
newItem - the item to insert into this list
oldItem - the item to insert newItem before
void insertItemAt(<Object> item, <int> index)
item at index index.
If there are any items already in the list with indices
greater than or equal to index, all those
items are ‘shuffled right’ by one.
item - the item to insert
index - the index at which to insert item
boolean isEmpty()
true if and only if the list is empty.
true if the list is empty and false otherwise
Iterator iterator()
Iterators have the following interface:
boolean hasNext()true if calling next() will not
cause an errorObject next()A common idiom is as follows:
var it = list.iterator();
while(it.hasNext()) {
var cursor = it.next();
// do something with cursor
}
The above code will make one iteration of the while-loop for each item
in the list. cursor will assume the value of each item in
the list in order, starting with list.getHead() and ending
with list.getTail(), at which point the loop will terminate.
There is no guarantee that an iterator will remain valid in the face of modifications to the list. Generally speaking no changes should be made to a list while there are iterators active on it.
string join(<string> separator)
separator.
separator - the string to put between consecutive elements of the list
string composed of all elements of the list, separated by separator
void prepend(<Object> item)
item into this list before the head.
item - this item to insert
Object remove(<Object> item)
item from this list and returns it.
item - the item to remove
item is returned
void removeAll(<AbstractList> list)
list.
list - a list of elements to remove from this list
Object removeHead()
Object removeItemAt(<int> index)
index - the index of the item to remove
index
Object removeTail()
Object replace(<Object> newItem, <Object> oldItem)
oldItem with newItem in
this list. Does nothing if oldItem is not in
this list or if newItem could not be inserted.
newItem - the item to insert into the list
oldItem - the item in the list to be replaced by newItem
oldItem is returned if it was in the list—otherwise null is returned.
Iterator reverseIterator()
next() will
return the list's items in the opposite order to a forward iterator.
Specifically, the first call to next() will return
the tail of the list, and successive calls to next()
will ‘advance’ the iterator towards the head of the
list. The last successful call to next() on a
reverse iterator returns the head of the list, and then
invalidates the iterator.
AbstractList selectRangeInto(<Object> startObj, <Object> endObj, <AbstractList> list)
startObj and
endObj inclusive and copies them into list. It
doesn't matter if endObj comes before startObj in
the list—the algorithm will behave as if they were swapped. If the
list contains duplicates of startObj or endObj the
resulting selection is undefined. For conveniece, list is the
return value so you can say
var newList = oldList.selectRangeInto(foo, bar, new LinkedList());and have everything work out.
startObj - the object at the "start" of the range
endObj - the object at the "end" of the range
list - the list into which the selection should be inserted
list with the selection inserted
void sort(<Function> comparator)
comparator - a function taking two arguments and returning an integer: comparator is null or not provided then the elements of the list are sorted lexicographically according to their value after being converted to a string.
Array toArray()
Array containing all the items in this list, and in the same order as this list.
string toString()
|
Sydney | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||