private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(_size); Listable cur = _head.next(); while (cur != null) { out.writeObject(cur.value()); cur = cur.next(); } }
/** * Returns a {@link String} representation of this list, suitable for debugging. * @return a {@link String} representation of this list, suitable for debugging. */ public String toString() { StringBuffer buf = new StringBuffer(); buf.append("["); for(Listable elt = _head.next(), past = null; null != elt && past != _head.prev(); elt = (past = elt).next()) { if(_head.next() != elt) { buf.append(", "); } buf.append(elt.value()); } buf.append("]"); return buf.toString(); }
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(_size); Listable cur = _head.next(); while (cur != null) { out.writeObject(cur.value()); cur = cur.next(); } }
/** * Removes the element at the specified position in this list (optional * operation). Shifts any subsequent elements to the left (subtracts one * from their indices). Returns the element that was removed from the * list. * * @param index the index of the element to removed. * @return the element previously at the specified position. * * @throws IndexOutOfBoundsException if the index is out of range (index * < 0 || index >= size()). */ public Object remove(int index) { Listable elt = getListableAt(index); Object ret = elt.value(); removeListable(elt); return ret; }
/** * Returns <tt>true</tt> if this list contains the specified element. * More formally, returns <tt>true</tt> if and only if this list contains * at least one element <tt>e</tt> such that * <tt>(o==null ? e==null : o.equals(e))</tt>. * * @param o element whose presence in this list is to be tested. * @return <tt>true</tt> if this list contains the specified element. */ public boolean contains(Object o) { for(Listable elt = _head.next(), past = null; null != elt && past != _head.prev(); elt = (past = elt).next()) { if((null == o && null == elt.value()) || (o != null && o.equals(elt.value()))) { return true; } } return false; }
public Object next() { checkForComod(); if(!hasNext()) { throw new NoSuchElementException(); } else { Object ret = _cur.next().value(); _lastReturned = _cur.next(); _cur.setPrev(_cur.next()); _cur.setNext(_cur.next().next()); _nextIndex++; return ret; } }
public Object previous() { checkForComod(); if(!hasPrevious()) { throw new NoSuchElementException(); } else { Object ret = _cur.prev().value(); _lastReturned = _cur.prev(); _cur.setNext(_cur.prev()); _cur.setPrev(_cur.prev().prev()); _nextIndex--; return ret; } }
/** * Removes the last element of this list, if any. */ public Object removeLast() { if(_head.prev() != null) { Object val = _head.prev().value(); removeListable(_head.prev()); return val; } else { throw new NoSuchElementException(); } }
/** * Removes the first element of this list, if any. */ public Object removeFirst() { if(_head.next() != null) { Object val = _head.next().value(); removeListable(_head.next()); return val; } else { throw new NoSuchElementException(); } }
/** * Returns the element at the specified position in this list. * * @param index index of element to return. * @return the element at the specified position in this list. * * @throws IndexOutOfBoundsException if the index is out of range (index * < 0 || index >= size()). */ public Object get(int index) { return getListableAt(index).value(); }
/** * Returns the element at the end of this list. */ public Object getLast() { try { return _head.prev().value(); } catch(NullPointerException e) { throw new NoSuchElementException(); } }
/** * Returns an array containing all of the elements in this list in proper * sequence. Obeys the general contract of the {@link Collection#toArray} method. * * @return an array containing all of the elements in this list in proper * sequence. */ public Object[] toArray() { Object[] array = new Object[_size]; int i = 0; for(Listable elt = _head.next(), past = null; null != elt && past != _head.prev(); elt = (past = elt).next()) { array[i++] = elt.value(); } return array; }
/** * Returns the element at the beginning of this list. */ public Object getFirst() { try { return _head.next().value(); } catch(NullPointerException e) { throw new NoSuchElementException(); } }
public Object next() { checkForComod(); if(!hasNext()) { throw new NoSuchElementException(); } else { Object ret = _cur.next().value(); _lastReturned = _cur.next(); _cur.setPrev(_cur.next()); _cur.setNext(_cur.next().next()); _nextIndex++; return ret; } }
public Object previous() { checkForComod(); if(!hasPrevious()) { throw new NoSuchElementException(); } else { Object ret = _cur.prev().value(); _lastReturned = _cur.prev(); _cur.setNext(_cur.prev()); _cur.setPrev(_cur.prev().prev()); _nextIndex--; return ret; } }
/** * Removes the last element of this list, if any. */ public Object removeLast() { if(_head.prev() != null) { Object val = _head.prev().value(); removeListable(_head.prev()); return val; } else { throw new NoSuchElementException(); } }
/** * Removes the first element of this list, if any. */ public Object removeFirst() { if(_head.next() != null) { Object val = _head.next().value(); removeListable(_head.next()); return val; } else { throw new NoSuchElementException(); } }
/** * Returns the element at the specified position in this list. * * @param index index of element to return. * @return the element at the specified position in this list. * * @throws IndexOutOfBoundsException if the index is out of range (index * < 0 || index >= size()). */ public Object get(int index) { return getListableAt(index).value(); }
/** * Returns the element at the end of this list. */ public Object getLast() { try { return _head.prev().value(); } catch(NullPointerException e) { throw new NoSuchElementException(); } }
/** * Returns the element at the beginning of this list. */ public Object getFirst() { try { return _head.next().value(); } catch(NullPointerException e) { throw new NoSuchElementException(); } }