001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.collections.facades;
022:
023: import java.util.*;
024:
025: /**
026: * @exclude
027: */
028: public class FastListCache {
029:
030: private transient List _list;
031:
032: public FastListCache(int size) {
033: _list = new ArrayList(size);
034: for (int i = 0; i < _list.size(); ++i) {
035: _list.set(i, CachedObject.NONE);
036: }
037: }
038:
039: public void add(Object o) {
040: _list.add(new CachedObject(o));
041: }
042:
043: public void add(int index, Object element) {
044: _list.add(index, new CachedObject(element));
045: }
046:
047: public void addAll(Collection c) {
048: _list.addAll(toCachedObjectCollection(c));
049: }
050:
051: public void addAll(int index, Collection c) {
052: _list.addAll(index, toCachedObjectCollection(c));
053: }
054:
055: public void clear() {
056: _list.clear();
057: }
058:
059: public boolean contains(Object o) {
060: return _list.contains(new CachedObject(o));
061: }
062:
063: public int indexOf(Object o) {
064: return _list.indexOf(new CachedObject(o));
065: }
066:
067: public void remove(Object o) {
068: _list.remove(new CachedObject(o));
069: }
070:
071: public void remove(int index) {
072: _list.remove(index);
073: }
074:
075: public void removeAll(Collection c) {
076: _list.removeAll(toCachedObjectCollection(c));
077: }
078:
079: public void retainAll(Collection c) {
080: _list.retainAll(toCachedObjectCollection(c));
081: }
082:
083: public void set(int index, Object element) {
084: _list.set(index, new CachedObject(element));
085: }
086:
087: private Collection toCachedObjectCollection(Collection c) {
088: ArrayList cachedObjectList = new ArrayList(c.size());
089: Iterator iter = c.iterator();
090: while (iter.hasNext()) {
091: cachedObjectList.add(new CachedObject(iter.next()));
092: }
093: return cachedObjectList;
094: }
095:
096: public CachedObject get(int index) {
097: return (CachedObject) _list.get(index);
098: }
099:
100: public boolean containsAll(Collection c) {
101: return _list.containsAll(toCachedObjectCollection(c));
102: }
103:
104: }
|