| Method from java.util.LinkedList Detail: |
public boolean add(E object) {
return addLastImpl(object);
}
Adds the specified object at the end of this {@code LinkedList}. |
public void add(int location,
E object) {
if (0 < = location && location < = size) {
Link< E > link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i < = location; i++) {
link = link.next;
}
} else {
for (int i = size; i > location; i--) {
link = link.previous;
}
}
Link< E > previous = link.previous;
Link< E > newLink = new Link< E >(object, previous, link);
previous.next = newLink;
link.previous = newLink;
size++;
modCount++;
} else {
throw new IndexOutOfBoundsException();
}
}
Inserts the specified object into this {@code LinkedList} at the
specified location. The object is inserted before any previous element at
the specified location. If the location is equal to the size of this
{@code LinkedList}, the object is added at the end. |
public boolean addAll(Collection<? extends E> collection) {
int adding = collection.size();
if (adding == 0) {
return false;
}
Collection< ? extends E > elements = (collection == this) ?
new ArrayList< E >(collection) : collection;
Link< E > previous = voidLink.previous;
for (E e : elements) {
Link< E > newLink = new Link< E >(e, previous, null);
previous.next = newLink;
previous = newLink;
}
previous.next = voidLink;
voidLink.previous = previous;
size += adding;
modCount++;
return true;
}
Adds the objects in the specified Collection to this {@code LinkedList}. |
public boolean addAll(int location,
Collection<? extends E> collection) {
if (location < 0 || location > size) {
throw new IndexOutOfBoundsException();
}
int adding = collection.size();
if (adding == 0) {
return false;
}
Collection< ? extends E > elements = (collection == this) ?
new ArrayList< E >(collection) : collection;
Link< E > previous = voidLink;
if (location < (size / 2)) {
for (int i = 0; i < location; i++) {
previous = previous.next;
}
} else {
for (int i = size; i >= location; i--) {
previous = previous.previous;
}
}
Link< E > next = previous.next;
for (E e : elements) {
Link< E > newLink = new Link< E >(e, previous, null);
previous.next = newLink;
previous = newLink;
}
previous.next = next;
next.previous = previous;
size += adding;
modCount++;
return true;
}
Inserts the objects in the specified collection at the specified location
in this {@code LinkedList}. The objects are added in the order they are
returned from the collection's iterator. |
public void addFirst(E object) {
addFirstImpl(object);
}
Adds the specified object at the beginning of this {@code LinkedList}. |
public void addLast(E object) {
addLastImpl(object);
}
Adds the specified object at the end of this {@code LinkedList}. |
public void clear() {
if (size > 0) {
size = 0;
voidLink.next = voidLink;
voidLink.previous = voidLink;
modCount++;
}
}
Removes all elements from this {@code LinkedList}, leaving it empty. |
public Object clone() {
try {
LinkedList< E > l = (LinkedList< E >) super.clone();
l.size = 0;
l.voidLink = new Link< E >(null, null, null);
l.voidLink.previous = l.voidLink;
l.voidLink.next = l.voidLink;
l.addAll(this);
return l;
} catch (CloneNotSupportedException e) {
return null;
}
}
Returns a new {@code LinkedList} with the same elements and size as this
{@code LinkedList}. |
public boolean contains(Object object) {
Link< E > link = voidLink.next;
if (object != null) {
while (link != voidLink) {
if (object.equals(link.data)) {
return true;
}
link = link.next;
}
} else {
while (link != voidLink) {
if (link.data == null) {
return true;
}
link = link.next;
}
}
return false;
}
Searches this {@code LinkedList} for the specified object. |
public Iterator<E> descendingIterator() {
return new ReverseLinkIterator< E >(this);
}
|
public E element() {
return getFirstImpl();
}
|
public E get(int location) {
if (0 < = location && location < size) {
Link< E > link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i < = location; i++) {
link = link.next;
}
} else {
for (int i = size; i > location; i--) {
link = link.previous;
}
}
return link.data;
}
throw new IndexOutOfBoundsException();
}
|
public E getFirst() {
return getFirstImpl();
}
Returns the first element in this {@code LinkedList}. |
public E getLast() {
Link< E > last = voidLink.previous;
if (last != voidLink) {
return last.data;
}
throw new NoSuchElementException();
}
Returns the last element in this {@code LinkedList}. |
public int indexOf(Object object) {
int pos = 0;
Link< E > link = voidLink.next;
if (object != null) {
while (link != voidLink) {
if (object.equals(link.data)) {
return pos;
}
link = link.next;
pos++;
}
} else {
while (link != voidLink) {
if (link.data == null) {
return pos;
}
link = link.next;
pos++;
}
}
return -1;
}
|
public int lastIndexOf(Object object) {
int pos = size;
Link< E > link = voidLink.previous;
if (object != null) {
while (link != voidLink) {
pos--;
if (object.equals(link.data)) {
return pos;
}
link = link.previous;
}
} else {
while (link != voidLink) {
pos--;
if (link.data == null) {
return pos;
}
link = link.previous;
}
}
return -1;
}
Searches this {@code LinkedList} for the specified object and returns the
index of the last occurrence. |
public ListIterator<E> listIterator(int location) {
return new LinkIterator< E >(this, location);
}
Returns a ListIterator on the elements of this {@code LinkedList}. The
elements are iterated in the same order that they occur in the
{@code LinkedList}. The iteration starts at the specified location. |
public boolean offer(E o) {
return addLastImpl(o);
}
|
public boolean offerFirst(E e) {
return addFirstImpl(e);
}
|
public boolean offerLast(E e) {
return addLastImpl(e);
}
|
public E peek() {
return peekFirstImpl();
}
|
public E peekFirst() {
return peekFirstImpl();
}
|
public E peekLast() {
Link< E > last = voidLink.previous;
return (last == voidLink) ? null : last.data;
}
|
public E poll() {
return size == 0 ? null : removeFirst();
}
|
public E pollFirst() {
return (size == 0) ? null : removeFirstImpl();
}
|
public E pollLast() {
return (size == 0) ? null : removeLastImpl();
}
|
public E pop() {
return removeFirstImpl();
}
|
public void push(E e) {
addFirstImpl(e);
}
|
public E remove() {
return removeFirstImpl();
}
|
public E remove(int location) {
if (0 < = location && location < size) {
Link< E > link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i < = location; i++) {
link = link.next;
}
} else {
for (int i = size; i > location; i--) {
link = link.previous;
}
}
Link< E > previous = link.previous;
Link< E > next = link.next;
previous.next = next;
next.previous = previous;
size--;
modCount++;
return link.data;
}
throw new IndexOutOfBoundsException();
}
Removes the object at the specified location from this {@code LinkedList}. |
public boolean remove(Object object) {
return removeFirstOccurrenceImpl(object);
}
|
public E removeFirst() {
return removeFirstImpl();
}
Removes the first object from this {@code LinkedList}. |
public boolean removeFirstOccurrence(Object o) {
return removeFirstOccurrenceImpl(o);
}
|
public E removeLast() {
return removeLastImpl();
}
Removes the last object from this {@code LinkedList}. |
public boolean removeLastOccurrence(Object o) {
Iterator< E > iter = new ReverseLinkIterator< E >(this);
return removeOneOccurrence(o, iter);
}
|
public E set(int location,
E object) {
if (0 < = location && location < size) {
Link< E > link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i < = location; i++) {
link = link.next;
}
} else {
for (int i = size; i > location; i--) {
link = link.previous;
}
}
E result = link.data;
link.data = object;
return result;
}
throw new IndexOutOfBoundsException();
}
Replaces the element at the specified location in this {@code LinkedList}
with the specified object. |
public int size() {
return size;
}
Returns the number of elements in this {@code LinkedList}. |
public Object[] toArray() {
int index = 0;
Object[] contents = new Object[size];
Link< E > link = voidLink.next;
while (link != voidLink) {
contents[index++] = link.data;
link = link.next;
}
return contents;
}
Returns a new array containing all elements contained in this
{@code LinkedList}. |
public T[] toArray(T[] contents) {
int index = 0;
if (size > contents.length) {
Class< ? > ct = contents.getClass().getComponentType();
contents = (T[]) Array.newInstance(ct, size);
}
Link< E > link = voidLink.next;
while (link != voidLink) {
contents[index++] = (T) link.data;
link = link.next;
}
if (index < contents.length) {
contents[index] = null;
}
return contents;
}
Returns an array containing all elements contained in this
{@code LinkedList}. If the specified array is large enough to hold the
elements, the specified array is used, otherwise an array of the same
type is created. If the specified array is used and is larger than this
{@code LinkedList}, the array element following the collection elements
is set to null. |