public class CodedList<V> extends Object implements CList<V>
size() is an O(1) operation.iterator() or visit methods are used)Use CList.NIL for nil.
| Modifier and Type | Class and Description |
|---|---|
protected class |
CodedList.CListIterator<V> |
protected class |
CodedList.CListReverseIterator<V> |
| Modifier | Constructor and Description |
|---|---|
protected |
CodedList(CodedList<V> other) |
protected |
CodedList(V element,
CList<V> list)
Constructor.
|
protected |
CodedList(V element,
CodedList<V> list,
int pos) |
| Modifier and Type | Method and Description |
|---|---|
CList<V> |
cons(V element)
Add an element to the head of the list.
|
boolean |
contains(V element)
Test for element.
|
protected boolean |
contains(V element,
int pos) |
V |
head()
Get the head of the list.
|
boolean |
isEmpty()
Test if empty.
|
Iterator<V> |
iterator()
Iterate through the elements in the list.
|
Iterator<V> |
reverseIterator()
Get the elements in reverse order.
|
boolean |
reverseVisit(ConditionalVisitor<V> visitor)
Visit all elements in reverse order until
visitor.visit() returns true; |
protected boolean |
reverseVisit(ConditionalVisitor<V> visitor,
int pos,
CList<V> last) |
void |
reverseVisit(Visitor<V> visitor)
Visit all elements in reverse order.
|
protected void |
reverseVisit(Visitor<V> visitor,
int pos,
CList<V> last) |
int |
size()
Get the number of elements in the collection.
|
CList<V> |
tail()
Get the rest of the list after the head.
|
void |
toCollection(Collection<V> collection)
Copy elements in list to collection in order.
|
protected void |
toCollection(Collection<V> collection,
int pos) |
boolean |
visit(ConditionalVisitor<V> visitor)
Visit each element in order until visit returns false.
|
protected boolean |
visit(ConditionalVisitor<V> visitor,
int pos) |
void |
visit(Visitor<V> visitor)
Visit each element in order.
|
protected void |
visit(Visitor<V> visitor,
int pos) |
protected CodedList(V element, CList<V> list)
cons.element - list - public boolean isEmpty()
AccessisEmpty() is guaranteed to be an O(1)
operation; it should always be used in preference to
size() == 0, as the latter may have cost up to O(n);public int size()
Accesssize() may have cost O(1), O(log(n) up
to O(n).public boolean contains(V element)
CListprotected boolean contains(V element, int pos)
public CList<V> cons(V element)
CListpublic CList<V> tail()
CListgetFirst/getRest are not the most efficient
way to traverse the list elements.tail in interface CList<V>CList.iterator()protected boolean visit(ConditionalVisitor<V> visitor, int pos)
protected boolean reverseVisit(ConditionalVisitor<V> visitor, int pos, CList<V> last)
public void visit(Visitor<V> visitor)
CListpublic boolean visit(ConditionalVisitor<V> visitor)
CListIf the list is empty, returns true.
public void reverseVisit(Visitor<V> visitor)
AccessreverseVisit in interface Access<V>public boolean reverseVisit(ConditionalVisitor<V> visitor)
Accessvisitor.visit() returns true;reverseVisit in interface Access<V>visitor.visit() returned true;
otherwise falseprotected void toCollection(Collection<V> collection, int pos)
public void toCollection(Collection<V> collection)
CListtoCollection in interface CList<V>public Iterator<V> iterator()
CListCopyright © 2015. All rights reserved.