KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > ListWithPrefetches


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.access;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.ListIterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * A java.util.List wrapper that stores objects prefetched together with the main list.
31  *
32  * @since 1.2
33  * @author Andrus Adamchik
34  */

35 // TODO, andrus, 4/11/2006 - this object doesn't have to be a list. It is just a question
36
// of changing DataRowStore result caching API. Since we are doing it when already in 1.2
37
// beta, I am choosing the least invasive way that doesn't affect public API.
38
//
39
// Future alternatives may include caching the entire QueryResponse... or maybe leaving
40
// everything the way it is.
41
class ListWithPrefetches implements List JavaDoc {
42
43     private final List JavaDoc list;
44     private final Map JavaDoc prefetchResultsByPath;
45
46     ListWithPrefetches(List JavaDoc mainList, Map JavaDoc prefetchResultsByPath) {
47         if (mainList == null) {
48             throw new IllegalArgumentException JavaDoc("Main list is null");
49         }
50
51         this.list = mainList;
52         this.prefetchResultsByPath = prefetchResultsByPath != null ? Collections
53                 .unmodifiableMap(prefetchResultsByPath) : null;
54     }
55
56     Map JavaDoc getPrefetchResultsByPath() {
57         return prefetchResultsByPath;
58     }
59
60     public void add(int index, Object JavaDoc element) {
61         list.add(index, element);
62     }
63
64     public boolean add(Object JavaDoc o) {
65         return list.add(o);
66     }
67
68     public boolean addAll(Collection JavaDoc c) {
69         return list.addAll(c);
70     }
71
72     public boolean addAll(int index, Collection JavaDoc c) {
73         return list.addAll(index, c);
74     }
75
76     public void clear() {
77         list.clear();
78     }
79
80     public boolean contains(Object JavaDoc o) {
81         return list.contains(o);
82     }
83
84     public boolean containsAll(Collection JavaDoc c) {
85         return list.containsAll(c);
86     }
87
88     public boolean equals(Object JavaDoc o) {
89         return list.equals(o);
90     }
91
92     public Object JavaDoc get(int index) {
93         return list.get(index);
94     }
95
96     public int hashCode() {
97         return list.hashCode();
98     }
99
100     public int indexOf(Object JavaDoc o) {
101         return list.indexOf(o);
102     }
103
104     public boolean isEmpty() {
105         return list.isEmpty();
106     }
107
108     public Iterator JavaDoc iterator() {
109         return list.iterator();
110     }
111
112     public int lastIndexOf(Object JavaDoc o) {
113         return list.lastIndexOf(o);
114     }
115
116     public ListIterator JavaDoc listIterator() {
117         return list.listIterator();
118     }
119
120     public ListIterator JavaDoc listIterator(int index) {
121         return list.listIterator(index);
122     }
123
124     public Object JavaDoc remove(int index) {
125         return list.remove(index);
126     }
127
128     public boolean remove(Object JavaDoc o) {
129         return list.remove(o);
130     }
131
132     public boolean removeAll(Collection JavaDoc c) {
133         return list.removeAll(c);
134     }
135
136     public boolean retainAll(Collection JavaDoc c) {
137         return list.retainAll(c);
138     }
139
140     public Object JavaDoc set(int index, Object JavaDoc element) {
141         return list.set(index, element);
142     }
143
144     public int size() {
145         return list.size();
146     }
147
148     public List JavaDoc subList(int fromIndex, int toIndex) {
149         return list.subList(fromIndex, toIndex);
150     }
151
152     public Object JavaDoc[] toArray() {
153         return list.toArray();
154     }
155
156     public Object JavaDoc[] toArray(Object JavaDoc[] a) {
157         return list.toArray(a);
158     }
159 }
160
Popular Tags