001: package org.conform.util;
002:
003: import java.util.*;
004:
005: public class ListView implements List {
006: Collection collection = Collections.EMPTY_LIST;
007: Iterator iterator;
008: int index = -1;
009: Object object;
010:
011: public ListView(Collection collection) {
012: this .collection = collection;
013: }
014:
015: public Object get(int index) {
016: if (index < this .index || iterator == null) {
017: iterator = collection.iterator();
018: this .index = -1;
019: }
020: for (; this .index < index; this .index++)
021: object = iterator.next();
022:
023: return object;
024: }
025:
026: public Object remove(int index) {
027: Object object = get(index);
028: collection.remove(object);
029: iterator = null;
030: return object;
031: }
032:
033: public void add(int index, Object element) {
034: add(object);
035: }
036:
037: public int indexOf(Object o) {
038: throw new UnsupportedOperationException(
039: "index of not supported");
040: }
041:
042: public int lastIndexOf(Object o) {
043: return indexOf(o);
044: }
045:
046: public boolean addAll(int index, Collection c) {
047: boolean result = addAll(c);
048: if (result)
049: iterator = null;
050: return result;
051: }
052:
053: public List subList(int fromIndex, int toIndex) {
054: throw new UnsupportedOperationException("sublist not supported");
055: }
056:
057: public ListIterator listIterator() {
058: throw new UnsupportedOperationException(
059: "list iterator not supported");
060: }
061:
062: public ListIterator listIterator(int index) {
063: throw new UnsupportedOperationException(
064: "list iterator not supported");
065: }
066:
067: public Object set(int index, Object element) {
068: Object object = get(index);
069: collection.remove(object);
070: add(element);
071: return object;
072: }
073:
074: public int hashCode() {
075: return collection.hashCode();
076: }
077:
078: public int size() {
079: return collection.size();
080: }
081:
082: public void clear() {
083: collection.clear();
084: }
085:
086: public boolean isEmpty() {
087: return collection.isEmpty();
088: }
089:
090: public Object[] toArray() {
091: return collection.toArray();
092: }
093:
094: public boolean add(Object o) {
095: boolean result = collection.add(o);
096: if (result)
097: iterator = null;
098: return result;
099: }
100:
101: public boolean contains(Object o) {
102: return collection.contains(o);
103: }
104:
105: public boolean equals(Object o) {
106: return collection.equals(o);
107: }
108:
109: public boolean remove(Object o) {
110: return collection.remove(o);
111: }
112:
113: public boolean addAll(Collection c) {
114: boolean result = collection.addAll(c);
115: if (result)
116: iterator = null;
117: return result;
118: }
119:
120: public boolean containsAll(Collection c) {
121: return collection.containsAll(c);
122: }
123:
124: public boolean removeAll(Collection c) {
125: boolean result = collection.removeAll(c);
126: if (result)
127: iterator = null;
128: return result;
129: }
130:
131: public boolean retainAll(Collection c) {
132: boolean result = collection.retainAll(c);
133: if (result)
134: iterator = null;
135: return result;
136: }
137:
138: public Iterator iterator() {
139: return collection.iterator();
140: }
141:
142: public Object[] toArray(Object a[]) {
143: return collection.toArray(a);
144: }
145:
146: public Collection getCollection() {
147: return collection;
148: }
149: }
|