/** * Returns the element at the beginning of this list. */ public Object getFirst() { try { return _head.next().value(); } catch(NullPointerException e) { throw new NoSuchElementException(); } }
public void add(Object o) { checkForComod(); _cur.setPrev(insertListable(_cur.prev(),_cur.next(),o)); _lastReturned = null; _nextIndex++; _expectedModCount++; }
/** * Returns the element at the beginning of this list. */ public Object getFirst() { try { return _head.next().value(); } catch(NullPointerException e) { throw new NoSuchElementException(); } }
/** * Inserts the specified element at the beginning of this list. * (Equivalent to {@link #add(int,java.lang.Object) <tt>add(0,o)</tt>}). * * @param o element to be prepended to this list. * @return <tt>true</tt> */ public boolean addFirst(Object o) { insertListable(null,_head.next(),o); return true; }
/** * 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; }
public boolean hasNext() { checkForComod(); return(null != _cur.next() && _cur.prev() != _head.prev()); }
public void remove() { checkForComod(); if(null == _lastReturned) { throw new IllegalStateException(); } else { _cur.setNext(_lastReturned == _head.prev() ? null : _lastReturned.next()); _cur.setPrev(_lastReturned == _head.next() ? null : _lastReturned.prev()); removeListable(_lastReturned); _lastReturned = null; _nextIndex--; _expectedModCount++; } }
ListIter(int index) { if(index == 0) { _cur = new Listable(null,_head.next(),null); _nextIndex = 0; } else if(index == _size) { _cur = new Listable(_head.prev(),null,null); _nextIndex = _size; } else { Listable temp = getListableAt(index); _cur = new Listable(temp.prev(),temp,null); _nextIndex = index; } }
/** * Inserts the specified element at the beginning of this list. * (Equivalent to {@link #add(int,java.lang.Object) <tt>add(0,o)</tt>}). * * @param o element to be prepended to this list. * @return <tt>true</tt> */ public boolean addFirst(Object o) { insertListable(null,_head.next(),o); return true; }
public void add(Object o) { checkForComod(); _cur.setPrev(insertListable(_cur.prev(),_cur.next(),o)); _lastReturned = null; _nextIndex++; _expectedModCount++; }