public boolean hasNext() { return (nextIndex < parent.size()); }
public boolean hasNext() { return (nextIndex < parent.size()); }
/** * Checks whether the index is valid. * * @param index the index to check * @param startIndex the first allowed index * @param endIndex the last allowed index * @throws IndexOutOfBoundsException if the index is invalid */ private void checkInterval(int index, int startIndex, int endIndex) { if (index < startIndex || index > endIndex) { throw new IndexOutOfBoundsException("Invalid index:" + index + ", size=" + size()); } }
/** * Checks whether the index is valid. * * @param index the index to check * @param startIndex the first allowed index * @param endIndex the last allowed index * @throws IndexOutOfBoundsException if the index is invalid */ private void checkInterval(int index, int startIndex, int endIndex) { if (index < startIndex || index > endIndex) { throw new IndexOutOfBoundsException("Invalid index:" + index + ", size=" + size()); } }
/** * Converts the list into an array. * * @return the list as an array */ public Object[] toArray() { // override to go 20% faster Object[] array = new Object[size()]; if (root != null) { root.toArray(array, root.relativePosition); } return array; }
/** * Converts the list into an array. * * @return the list as an array */ public Object[] toArray() { // override to go 20% faster Object[] array = new Object[size()]; if (root != null) { root.toArray(array, root.relativePosition); } return array; }
/** * Gets a ListIterator over the list. * * @param fromIndex the index to start from * @return the new iterator */ public ListIterator listIterator(int fromIndex) { // override to go 75% faster // cannot use EmptyIterator as iterator.add() must work checkInterval(fromIndex, 0, size()); return new TreeListIterator(this, fromIndex); }
/** * Gets a ListIterator over the list. * * @param fromIndex the index to start from * @return the new iterator */ public ListIterator listIterator(int fromIndex) { // override to go 75% faster // cannot use EmptyIterator as iterator.add() must work checkInterval(fromIndex, 0, size()); return new TreeListIterator(this, fromIndex); }
/** * Gets the element at the specified index. * * @param index the index to retrieve * @return the element at the specified index */ public Object get(int index) { checkInterval(index, 0, size() - 1); return root.get(index).getValue(); }
/** * Gets the element at the specified index. * * @param index the index to retrieve * @return the element at the specified index */ public Object get(int index) { checkInterval(index, 0, size() - 1); return root.get(index).getValue(); }
/** * Removes the element at the specified index. * * @param index the index to remove * @return the previous object at that index */ public Object remove(int index) { modCount++; checkInterval(index, 0, size() - 1); Object result = get(index); root = root.remove(index); size--; return result; }
/** * Adds a new element to the list. * * @param index the index to add before * @param obj the element to add */ public void add(int index, Object obj) { modCount++; checkInterval(index, 0, size()); if (root == null) { root = new AVLNode(index, obj, null, null); } else { root = root.insert(index, obj); } size++; }
/** * Sets the element at the specified index. * * @param index the index to set * @param obj the object to store at the specified index * @return the previous object at that index * @throws IndexOutOfBoundsException if the index is invalid */ public Object set(int index, Object obj) { checkInterval(index, 0, size() - 1); AVLNode node = root.get(index); Object result = node.value; node.setValue(obj); return result; }
/** * Removes the element at the specified index. * * @param index the index to remove * @return the previous object at that index */ public Object remove(int index) { modCount++; checkInterval(index, 0, size() - 1); Object result = get(index); root = root.remove(index); size--; return result; }
/** * Sets the element at the specified index. * * @param index the index to set * @param obj the object to store at the specified index * @return the previous object at that index * @throws IndexOutOfBoundsException if the index is invalid */ public Object set(int index, Object obj) { checkInterval(index, 0, size() - 1); AVLNode node = root.get(index); Object result = node.value; node.setValue(obj); return result; }
/** * Adds a new element to the list. * * @param index the index to add before * @param obj the element to add */ public void add(int index, Object obj) { modCount++; checkInterval(index, 0, size()); if (root == null) { root = new AVLNode(index, obj, null, null); } else { root = root.insert(index, obj); } size++; }
/** * Converts the list into an array. * * @return the list as an array */ public Object[] toArray() { // override to go 20% faster Object[] array = new Object[size()]; if (root != null) { root.toArray(array, root.relativePosition); } return array; }
/** * Gets a ListIterator over the list. * * @param fromIndex the index to start from * @return the new iterator */ public ListIterator listIterator(int fromIndex) { // override to go 75% faster // cannot use EmptyIterator as iterator.add() must work checkInterval(fromIndex, 0, size()); return new TreeListIterator(this, fromIndex); }
/** * Gets the element at the specified index. * * @param index the index to retrieve * @return the element at the specified index */ public Object get(int index) { checkInterval(index, 0, size() - 1); return root.get(index).getValue(); }
/** * Gets the element at the specified index. * * @param index the index to retrieve * @return the element at the specified index */ public Object get(int index) { checkInterval(index, 0, size() - 1); return root.get(index).getValue(); }