KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > fjank > jcache > collection > CollectionProxy


1 /* Open Source Java Caching Service
2 * Copyright (C) 2002 Frank Karlstrøm
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * The author can be contacted by email: fjankk@users.sourceforge.net
18 */

19 package org.fjank.jcache.collection;
20
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import org.fjank.jcache.CacheGroup;
24 import org.fjank.jcache.CacheObject;
25
26 /**Acts as a proxy to the collectiton returned from the Map.
27  * @author Frank Karlstrøm
28  *
29  */

30 public class CollectionProxy implements Collection JavaDoc {
31     private Collection JavaDoc coll;
32     private CacheGroup group;
33     /**
34      * @param collection
35      * @param group
36      */

37     public CollectionProxy(Collection JavaDoc collection, CacheGroup group) {
38         this.coll=collection;
39         this.group=group;
40     }
41
42     /* (non-Javadoc)
43      * @see java.lang.Object#hashCode()
44      */

45     public int hashCode() {
46         return coll.hashCode();
47     }
48
49     /**
50      * @param o
51      * @return
52      */

53     public boolean add(Object JavaDoc o) {
54         return coll.add(o);
55     }
56
57     /* (non-Javadoc)
58      * @see java.lang.Object#toString()
59      */

60     public String JavaDoc toString() {
61         return coll.toString();
62     }
63
64     /**
65      * @return
66      */

67     public Object JavaDoc[] toArray() {
68         return coll.toArray();
69     }
70
71     /**
72      * @param c
73      * @return
74      */

75     public boolean addAll(Collection JavaDoc c) {
76         return coll.addAll(c);
77     }
78
79     /**
80      * @param c
81      * @return
82      */

83     public boolean retainAll(Collection JavaDoc c) {
84         return coll.retainAll(c);
85     }
86
87     /**
88      * @param o
89      * @return
90      */

91     public boolean contains(Object JavaDoc o) {
92         //naive implementation, but it works.
93
for (Iterator JavaDoc iter = coll.iterator(); iter.hasNext();) {
94             CacheObject obj = (CacheObject) iter.next();
95             if(obj.get()==o) return true;
96         }
97         return false;
98     }
99
100     /**
101      *
102      */

103     public void clear() {
104         coll.clear();
105     }
106
107     /**
108      * @param c
109      * @return
110      */

111     public boolean containsAll(Collection JavaDoc c) {
112         return coll.containsAll(c);
113     }
114
115     /**
116      * @return
117      */

118     public int size() {
119         return coll.size();
120     }
121
122     /**
123      * @param c
124      * @return
125      */

126     public boolean removeAll(Collection JavaDoc c) {
127         return coll.removeAll(c);
128     }
129
130     /**
131      * @return
132      */

133     public boolean isEmpty() {
134         return coll.isEmpty();
135     }
136
137     /* (non-Javadoc)
138      * @see java.lang.Object#equals(java.lang.Object)
139      */

140     public boolean equals(Object JavaDoc obj) {
141         return coll.equals(obj);
142     }
143
144     /**
145      * @param o
146      * @return
147      */

148     public boolean remove(Object JavaDoc o) {
149         return coll.remove(o);
150     }
151
152     /**
153      * @return
154      */

155     public Iterator JavaDoc iterator() {
156         return coll.iterator();
157     }
158
159     /**
160      * @param a
161      * @return
162      */

163     public Object JavaDoc[] toArray(Object JavaDoc[] a) {
164         return coll.toArray(a);
165     }
166
167 }
168
Popular Tags