📄 baselistimpl.java
字号:
public int indexOf(Object o) { ListIterator itr = listIterator(); int size = size(); for (int pos = 0; pos < size; pos++) if (equals(o, itr.next())) return pos; return -1; } /** * Obtain an Iterator over this list, whose sequence is the list order. * This implementation uses size(), get(int), and remove(int) of the * backing list, and does not support remove unless the list does. This * implementation is fail-fast if you correctly maintain modCount. * Also, this implementation is specified by Sun to be distinct from * listIterator, although you could easily implement it as * <code>return listIterator(0)</code>. * * @return an Iterator over the elements of this list, in order * @see #modCount */ public Iterator iterator() {// TODO: replace when FakeFactoryGenerator is ready// return = _BaseList_IteratorImplFactory.getDefault.create(self()); return (Iterator) database().createObject(_BaseList_IteratorImpl.class.getName(), BaseList.class.getName(), new Object[] {self()}); } /** * Obtain the last index at which a given object is to be found in this * list. This implementation grabs listIterator(size()), then searches * backwards for a match or returns -1. * * @return the greatest integer n such that <code>o == null ? get(n) == null * : o.equals(get(n))</code>, or -1 if there is no such index */ public int lastIndexOf(Object o) { int pos = size(); ListIterator itr = listIterator(pos); while (--pos >= 0) if (equals(o, itr.previous())) return pos; return -1; } /** * Obtain a ListIterator over this list, starting at the beginning. This * implementation returns listIterator(0). * * @return a ListIterator over the elements of this list, in order, starting * at the beginning */ public ListIterator listIterator() { return listIterator(0); } /** * Obtain a ListIterator over this list, starting at a given position. * A first call to next() would return the same as get(index), and a * first call to previous() would return the same as get(index - 1). * <p> * * This implementation uses size(), get(int), set(int, Object), * add(int, Object), and remove(int) of the backing list, and does not * support remove, set, or add unless the list does. This implementation * is fail-fast if you correctly maintain modCount. * * @param index the position, between 0 and size() inclusive, to begin the * iteration from * @return a ListIterator over the elements of this list, in order, starting * at index * @throws IndexOutOfBoundsException if index < 0 || index > size() * @see #modCount */ public ListIterator listIterator(final int index) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException("Index: " + index + ", Size:" + size()); }// TODO: replace when FakeFactoryGenerator is ready return (ListIterator) database().createObject(_BaseList_ListIteratorImpl.class, new Class[] {BaseList.class, int.class}, new Object[] {self(), new Integer(index)}); } /** * Remove the element at a given position in this list (optional operation). * Shifts all remaining elements to the left to fill the gap. This * implementation always throws an UnsupportedOperationException. * If you want fail-fast iterators, be sure to increment modCount when * overriding this. * * @param index the position within the list of the object to remove * @return the object that was removed * @throws UnsupportedOperationException if this list does not support the * remove operation * @throws IndexOutOfBoundsException if index < 0 || index >= size() * @see #modCount */ public Object remove(int index) { throw new UnsupportedOperationException(); } /** * Remove a subsection of the list. This is called by the clear and * removeRange methods of the class which implements subList, which are * difficult for subclasses to override directly. Therefore, this method * should be overridden instead by the more efficient implementation, if one * exists. Overriding this can reduce quadratic efforts to constant time * in some cases! * <p> * * This implementation first checks for illegal or out of range arguments. It * then obtains a ListIterator over the list using listIterator(fromIndex). * It then calls next() and remove() on this iterator repeatedly, toIndex - * fromIndex times. * * @param fromIndex the index, inclusive, to remove from. * @param toIndex the index, exclusive, to remove to. */ public void _org_ozoneDB_removeRange(int fromIndex, int toIndex) { ListIterator itr = listIterator(fromIndex); for (int index = fromIndex; index < toIndex; index++) { itr.next(); itr.remove(); } } /** * Replace an element of this list with another object (optional operation). * This implementation always throws an UnsupportedOperationException. * * @param index the position within this list of the element to be replaced * @param o the object to replace it with * @return the object that was replaced * @throws UnsupportedOperationException if this list does not support the * set operation * @throws IndexOutOfBoundsException if index < 0 || index >= size() * @throws ClassCastException if o cannot be added to this list due to its * type * @throws IllegalArgumentException if o cannot be added to this list for * some other reason */ public Object set(int index, Object o) { throw new UnsupportedOperationException(); } /** * Obtain a List view of a subsection of this list, from fromIndex * (inclusive) to toIndex (exclusive). If the two indices are equal, the * sublist is empty. The returned list should be modifiable if and only * if this list is modifiable. Changes to the returned list should be * reflected in this list. If this list is structurally modified in * any way other than through the returned list, the result of any subsequent * operations on the returned list is undefined. * <p> * * This implementation returns a subclass of AbstractList. It stores, in * private fields, the offset and size of the sublist, and the expected * modCount of the backing list. If the backing list implements RandomAccess, * the sublist will also. * <p> * * The subclass's <code>set(int, Object)</code>, <code>get(int)</code>, * <code>add(int, Object)</code>, <code>remove(int)</code>, * <code>addAll(int, Collection)</code> and * <code>removeRange(int, int)</code> methods all delegate to the * corresponding methods on the backing abstract list, after * bounds-checking the index and adjusting for the offset. The * <code>addAll(Collection c)</code> method merely returns addAll(size, c). * The <code>listIterator(int)</code> method returns a "wrapper object" * over a list iterator on the backing list, which is created with the * corresponding method on the backing list. The <code>iterator()</code> * method merely returns listIterator(), and the <code>size()</code> method * merely returns the subclass's size field. * <p> * * All methods first check to see if the actual modCount of the backing * list is equal to its expected value, and throw a * ConcurrentModificationException if it is not. * * @param fromIndex the index that the returned list should start from * (inclusive) * @param toIndex the index that the returned list should go to (exclusive) * @return a List backed by a subsection of this list * @throws IndexOutOfBoundsException if fromIndex < 0 * || toIndex > size() * @throws IllegalArgumentException if fromIndex > toIndex * @see ConcurrentModificationException * @see RandomAccess */ public List subList(int fromIndex, int toIndex) { // This follows the specification of AbstractList, but is inconsistent // with the one in List. Don't you love Sun's inconsistencies? if (fromIndex > toIndex) throw new IllegalArgumentException(fromIndex + " > " + toIndex); if (fromIndex < 0 || toIndex > size()) throw new IndexOutOfBoundsException(); if (this instanceof RandomAccess) { return (List) database().createObject( _BaseList_RandomAccessSubListImpl.class, new Class[] {BaseList.class, int.class, int.class}, new Object[] {self(), new Integer(fromIndex), new Integer(toIndex)}); } return (List) database().createObject( _BaseList_SubListImpl.class, new Class[] {BaseList.class, int.class, int.class}, new Object[] {self(), new Integer(fromIndex), new Integer(toIndex)} ); } public List getClientList() { return (List) getClientCollection(); } protected Iterator internalIterator() { // todo fix this, need to return an iterator return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -