📄 _baselist_sublistimpl.java
字号:
/* * $Id: _BaseList_SubListImpl.java,v 1.2 2003/11/20 23:18:41 per_nyfelt Exp $ * This file is based on AbstractList.java from GNU Classpath. Quote:AbstractList.java -- Abstract implementation of most of ListCopyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. * end quote. * * This file is licenced under the same conditions as its original (GPL + * "special exception"). */package org.ozoneDB.collections;import java.util.Collection;import java.util.ConcurrentModificationException;import java.util.Iterator;import java.util.List;import java.util.ListIterator;/** * This class follows the implementation requirements set forth in * {@link java.util.AbstractList#subList(int, int)}. It matches Sun's implementation * by using a non-public top-level class in the same package. * * @author Original author unknown * @author Eric Blake <ebb9@email.byu.edu> * @author ported to Ozone by Leo Mekenkamp */public class _BaseList_SubListImpl extends BaseListImpl implements _BaseList_SubList { /** The original list. */ private final BaseList backingList; /** The index of the first element of the sublist. */ private final int offset; /** The size of the sublist. */ private int size; /** * Construct the sublist. * * @param backingList the list this comes from * @param fromIndex the lower bound, inclusive * @param toIndex the upper bound, exclusive */ public _BaseList_SubListImpl(BaseList backingList, int fromIndex, int toIndex) { this.backingList = backingList; modCount = backingList._org_ozoneDB_getModCount(); offset = fromIndex; size = toIndex - fromIndex; } /** * This method checks the two modCount fields to ensure that there has * not been a concurrent modification, returning if all is okay. * * @throws ConcurrentModificationException if the backing list has been * modified externally to this sublist */ public void _org_ozoneDB_checkMod() { if (modCount != backingList._org_ozoneDB_getModCount()) { throw new ConcurrentModificationException(); } } /** * This method checks that a value is between 0 and size (inclusive). If * it is not, an exception is thrown. * * @param index the value to check * @throws IndexOutOfBoundsException if the value is out of range */ public void _org_ozoneDB_checkBoundsInclusive(int index) { if (index < 0 || index > size) throw new IndexOutOfBoundsException("Index: " + index + ", Size:" + size); } /** * This method checks that a value is between 0 (inclusive) and size * (exclusive). If it is not, an exception is thrown. * * @param index the value to check * @throws IndexOutOfBoundsException if the value is out of range */ // This will get inlined, since it is private. public void _org_ozoneDB_checkBoundsExclusive(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + ", Size:" + size); } /** * Specified by AbstractList.subList to return the private field size. * * @return the sublist size */ public int size() { _org_ozoneDB_checkMod(); return size; } /** * Specified by AbstractList.subList to delegate to the backing list. * * @param index the location to modify * @param o the new value * @return the old value */ public Object set(int index, Object o) { _org_ozoneDB_checkMod(); _org_ozoneDB_checkBoundsExclusive(index); return backingList.set(index + offset, o); } /** * Specified by AbstractList.subList to delegate to the backing list. * * @param index the location to get from * @return the object at that location */ public Object get(int index) { _org_ozoneDB_checkMod(); _org_ozoneDB_checkBoundsExclusive(index); return backingList.get(index + offset); } /** * Specified by AbstractList.subList to delegate to the backing list. * * @param index the index to insert at * @param o the object to add */ public void add(int index, Object o) { _org_ozoneDB_checkMod(); _org_ozoneDB_checkBoundsInclusive(index); backingList.add(index + offset, o); size++; modCount = backingList._org_ozoneDB_getModCount(); } /** * Specified by AbstractList.subList to delegate to the backing list. * * @param index the index to remove * @return the removed object */ public Object remove(int index) { _org_ozoneDB_checkMod(); _org_ozoneDB_checkBoundsExclusive(index); Object o = backingList.remove(index + offset); size--; modCount = backingList._org_ozoneDB_getModCount(); return o; } /** * Specified by AbstractList.subList to delegate to the backing list. * This does no bounds checking, as it assumes it will only be called * by trusted code like clear() which has already checked the bounds. * * @param fromIndex the lower bound, inclusive * @param toIndex the upper bound, exclusive */ public void _org_ozoneDB_removeRange(int fromIndex, int toIndex) { _org_ozoneDB_checkMod(); backingList._org_ozoneDB_removeRange(offset + fromIndex, offset + toIndex); size -= toIndex - fromIndex; modCount = backingList._org_ozoneDB_getModCount(); } /** * Specified by AbstractList.subList to delegate to the backing list. * * @param index the location to insert at * @param c the collection to insert * @return true if this list was modified, in other words, c is non-empty */ public boolean addAll(int index, Collection c) { _org_ozoneDB_checkMod(); _org_ozoneDB_checkBoundsInclusive(index); int csize = c.size(); boolean result = backingList.addAll(offset + index, c); size += csize; modCount = backingList._org_ozoneDB_getModCount(); return result; } /** * Specified by AbstractList.subList to return addAll(size, c). * * @param c the collection to insert * @return true if this list was modified, in other words, c is non-empty */ public boolean addAll(Collection c) { return addAll(size, c); } public Iterator _org_ozoneDB_internalIterator() { throw new RuntimeException("_org_ozoneDB_internalIterator(), Not yet Implemented"); } /** * Specified by AbstractList.subList to return listIterator(). * * @return an iterator over the sublist */ public Iterator iterator() { return listIterator(); }// public int modCount() {// return modCount;// } /** * Specified by AbstractList.subList to return a wrapper around the * backing list's iterator. * * @param index the start location of the iterator * @return a list iterator over the sublist */ public ListIterator listIterator(final int index) { _org_ozoneDB_checkMod(); _org_ozoneDB_checkBoundsInclusive(index); OzoneListIterator iterator = (OzoneListIterator) backingList.listIterator(index + offset);// TODO: replace when FakeFactoryGenerator is ready ListIterator result = (ListIterator) database().createObject( _BaseList_SubList_listIterator.class, new Class[] {_BaseList_SubList.class, OzoneListIterator.class}, new Object[] {self(), iterator} ); return result; } public int _org_ozoneDB_getModCount() { return modCount; } public void _org_ozoneDB_incSize(int amount) { size += amount; } public List getClientList() { List result = backingList._org_ozoneDB_emptyClientCollection(); result.addAll((List) self()); return result; } public int _org_ozoneDB_getOffset() { return offset; } public List _org_ozoneDB_emptyClientCollection() { return backingList._org_ozoneDB_emptyClientCollection(); } public void _org_ozoneDB_syncModCountWithBackingList() { modCount = backingList._org_ozoneDB_getModCount(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -