| SynchronizedPassage.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: SynchronizedPassage.java 2226 2012-02-02 19:25:21Z dmsmith $
21 */
22 package org.crosswire.jsword.passage;
23
24 import java.io.IOException;
25 import java.io.Reader;
26 import java.io.Writer;
27 import java.util.Iterator;
28
29 import org.crosswire.jsword.versification.Versification;
30
31 /**
32 * This is a simple proxy to a real Passage object that makes all accesses
33 * synchronized. It is final to give the VM as much hope as possible at being
34 * able to inline stuff.
35 *
36 * @see gnu.lgpl.License for license details.<br>
37 * The copyright to this program is held by it's authors.
38 * @author Joe Walker [joe at eireneh dot com]
39 */
40 final class SynchronizedPassage implements Passage {
41 /**
42 * Construct a SynchronizedPassage from a real Passage to which we proxy.
43 *
44 * @param ref
45 * The real Passage
46 */
47 protected SynchronizedPassage(Passage ref) {
48 this.ref = ref;
49 }
50
51 /* (non-Javadoc)
52 * @see org.crosswire.jsword.passage.Passage#getVersification()
53 */
54 public Versification getVersification() {
55 return ref.getVersification();
56 }
57
58 /* (non-Javadoc)
59 * @see org.crosswire.jsword.passage.Key#addAll(org.crosswire.jsword.passage.Key)
60 */
61 public synchronized void addAll(Key key) {
62 ref.addAll(key);
63 }
64
65 /* (non-Javadoc)
66 * @see org.crosswire.jsword.passage.Key#removeAll(org.crosswire.jsword.passage.Key)
67 */
68 public synchronized void removeAll(Key key) {
69 ref.removeAll(key);
70 }
71
72 /* (non-Javadoc)
73 * @see org.crosswire.jsword.passage.Key#retainAll(org.crosswire.jsword.passage.Key)
74 */
75 public synchronized void retainAll(Key key) {
76 ref.retainAll(key);
77 }
78
79 /* (non-Javadoc)
80 * @see org.crosswire.jsword.passage.Passage#contains(org.crosswire.jsword.passage.Key)
81 */
82 public synchronized boolean contains(Key key) {
83 return ref.contains(key);
84 }
85
86 /* (non-Javadoc)
87 * @see org.crosswire.jsword.passage.Key#getChildCount()
88 */
89 public synchronized int getChildCount() {
90 return ref.getChildCount();
91 }
92
93 /* (non-Javadoc)
94 * @see org.crosswire.jsword.passage.Key#getCardinality()
95 */
96 public synchronized int getCardinality() {
97 return ref.getCardinality();
98 }
99
100 /* (non-Javadoc)
101 * @see org.crosswire.jsword.passage.Key#canHaveChildren()
102 */
103 public synchronized boolean canHaveChildren() {
104 return ref.canHaveChildren();
105 }
106
107 /* (non-Javadoc)
108 * @see java.lang.Iterable#iterator()
109 */
110 public synchronized Iterator<Key> iterator() {
111 return ref.iterator();
112 }
113
114 /* (non-Javadoc)
115 * @see org.crosswire.jsword.passage.Key#get(int)
116 */
117 public synchronized Key get(int index) {
118 return ref.get(index);
119 }
120
121 /* (non-Javadoc)
122 * @see org.crosswire.jsword.passage.Key#indexOf(org.crosswire.jsword.passage.Key)
123 */
124 public synchronized int indexOf(Key that) {
125 return ref.indexOf(that);
126 }
127
128 /* (non-Javadoc)
129 * @see org.crosswire.jsword.passage.Key#getParent()
130 */
131 public synchronized Key getParent() {
132 return ref.getParent();
133 }
134
135 /* (non-Javadoc)
136 * @see org.crosswire.jsword.passage.Key#getName()
137 */
138 public synchronized String getName() {
139 return ref.getName();
140 }
141
142 /* (non-Javadoc)
143 * @see org.crosswire.jsword.passage.Key#getName(org.crosswire.jsword.passage.Key)
144 */
145 public synchronized String getName(Key base) {
146 return ref.getName(base);
147 }
148
149 /* (non-Javadoc)
150 * @see org.crosswire.jsword.passage.Key#getRootName()
151 */
152 public synchronized String getRootName() {
153 return ref.getRootName();
154 }
155
156 /* (non-Javadoc)
157 * @see org.crosswire.jsword.passage.Key#getOsisRef()
158 */
159 public synchronized String getOsisRef() {
160 return ref.getOsisRef();
161 }
162
163 /* (non-Javadoc)
164 * @see org.crosswire.jsword.passage.Key#getOsisID()
165 */
166 public synchronized String getOsisID() {
167 return ref.getOsisID();
168 }
169
170 /* (non-Javadoc)
171 * @see org.crosswire.jsword.passage.Passage#getOverview()
172 */
173 public synchronized String getOverview() {
174 return ref.getOverview();
175 }
176
177 /* (non-Javadoc)
178 * @see org.crosswire.jsword.passage.Key#isEmpty()
179 */
180 public synchronized boolean isEmpty() {
181 return ref.isEmpty();
182 }
183
184 /* (non-Javadoc)
185 * @see org.crosswire.jsword.passage.Passage#countVerses()
186 */
187 public synchronized int countVerses() {
188 return ref.countVerses();
189 }
190
191 /* (non-Javadoc)
192 * @see org.crosswire.jsword.passage.Passage#hasRanges(org.crosswire.jsword.passage.RestrictionType)
193 */
194 public synchronized boolean hasRanges(RestrictionType restrict) {
195 return ref.hasRanges(restrict);
196 }
197
198 /* (non-Javadoc)
199 * @see org.crosswire.jsword.passage.Passage#countRanges(org.crosswire.jsword.passage.RestrictionType)
200 */
201 public synchronized int countRanges(RestrictionType restrict) {
202 return ref.countRanges(restrict);
203 }
204
205 /* (non-Javadoc)
206 * @see org.crosswire.jsword.passage.Passage#trimVerses(int)
207 */
208 public synchronized Passage trimVerses(int count) {
209 return ref.trimVerses(count);
210 }
211
212 /* (non-Javadoc)
213 * @see org.crosswire.jsword.passage.Passage#trimRanges(int, org.crosswire.jsword.passage.RestrictionType)
214 */
215 public synchronized Passage trimRanges(int count, RestrictionType restrict) {
216 return ref.trimRanges(count, restrict);
217 }
218
219 /* (non-Javadoc)
220 * @see org.crosswire.jsword.passage.Passage#booksInPassage()
221 */
222 public synchronized int booksInPassage() {
223 return ref.booksInPassage();
224 }
225
226 /* (non-Javadoc)
227 * @see org.crosswire.jsword.passage.Passage#getVerseAt(int)
228 */
229 public synchronized Verse getVerseAt(int offset) throws ArrayIndexOutOfBoundsException {
230 return ref.getVerseAt(offset);
231 }
232
233 /* (non-Javadoc)
234 * @see org.crosswire.jsword.passage.Passage#getRangeAt(int, org.crosswire.jsword.passage.RestrictionType)
235 */
236 public synchronized VerseRange getRangeAt(int offset, RestrictionType restrict) throws ArrayIndexOutOfBoundsException {
237 return ref.getRangeAt(offset, restrict);
238 }
239
240 /* (non-Javadoc)
241 * @see org.crosswire.jsword.passage.Passage#rangeIterator(org.crosswire.jsword.passage.RestrictionType)
242 */
243 public synchronized Iterator<Key> rangeIterator(RestrictionType restrict) {
244 return ref.rangeIterator(restrict);
245 }
246
247 /* (non-Javadoc)
248 * @see org.crosswire.jsword.passage.Passage#add(org.crosswire.jsword.passage.Key)
249 */
250 public synchronized void add(Key that) {
251 ref.add(that);
252 }
253
254 /* (non-Javadoc)
255 * @see org.crosswire.jsword.passage.Passage#remove(org.crosswire.jsword.passage.Key)
256 */
257 public synchronized void remove(Key that) {
258 ref.remove(that);
259 }
260
261 /* (non-Javadoc)
262 * @see org.crosswire.jsword.passage.Passage#containsAll(org.crosswire.jsword.passage.Passage)
263 */
264 public synchronized boolean containsAll(Passage that) {
265 return ref.containsAll(that);
266 }
267
268 /* (non-Javadoc)
269 * @see org.crosswire.jsword.passage.Key#clear()
270 */
271 public synchronized void clear() {
272 ref.clear();
273 }
274
275 /* (non-Javadoc)
276 * @see org.crosswire.jsword.passage.Key#blur(int, org.crosswire.jsword.passage.RestrictionType)
277 */
278 public synchronized void blur(int by, RestrictionType restrict) {
279 ref.blur(by, restrict);
280 }
281
282 /* (non-Javadoc)
283 * @see org.crosswire.jsword.passage.Passage#readDescription(java.io.Reader)
284 */
285 public synchronized void readDescription(Reader in) throws IOException, NoSuchVerseException {
286 ref.readDescription(in);
287 }
288
289 /* (non-Javadoc)
290 * @see org.crosswire.jsword.passage.Passage#writeDescription(java.io.Writer)
291 */
292 public synchronized void writeDescription(Writer out) throws IOException {
293 ref.writeDescription(out);
294 }
295
296 /* (non-Javadoc)
297 * @see org.crosswire.jsword.passage.Passage#optimizeReads()
298 */
299 public synchronized void optimizeReads() {
300 ref.optimizeReads();
301 }
302
303 /* (non-Javadoc)
304 * @see org.crosswire.jsword.passage.Passage#addPassageListener(org.crosswire.jsword.passage.PassageListener)
305 */
306 public synchronized void addPassageListener(PassageListener li) {
307 ref.addPassageListener(li);
308 }
309
310 /* (non-Javadoc)
311 * @see org.crosswire.jsword.passage.Passage#removePassageListener(org.crosswire.jsword.passage.PassageListener)
312 */
313 public synchronized void removePassageListener(PassageListener li) {
314 ref.removePassageListener(li);
315 }
316
317 @Override
318 public synchronized SynchronizedPassage clone() {
319 SynchronizedPassage clone = null;
320 try {
321 clone = (SynchronizedPassage) super.clone();
322 synchronized (clone) {
323 clone.ref = (Passage) ref.clone();
324 }
325 } catch (CloneNotSupportedException e) {
326 assert false : e;
327 }
328 return clone;
329 }
330
331 @Override
332 public synchronized int hashCode() {
333 return ref.hashCode();
334 }
335
336 @Override
337 public synchronized boolean equals(Object obj) {
338 return ref.equals(obj);
339 }
340
341 /* (non-Javadoc)
342 * @see java.lang.Comparable#compareTo(java.lang.Object)
343 */
344 public synchronized int compareTo(Key o) {
345 return ref.compareTo(o);
346 }
347
348 /**
349 * The object we are proxying to
350 */
351 private Passage ref;
352
353 /**
354 * Serialization ID
355 */
356 private static final long serialVersionUID = 3833181441264531251L;
357 }
358