01: package com.vividsolutions.jump.workbench.model.cache;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Iterator;
06: import java.util.List;
07:
08: import com.vividsolutions.jts.geom.Envelope;
09: import com.vividsolutions.jump.feature.Feature;
10: import com.vividsolutions.jump.feature.FeatureCollection;
11: import com.vividsolutions.jump.feature.FeatureSchema;
12:
13: /**
14: * Thread safety is achieved by (1) synchronizing the methods, and (2) creating
15: * new Collections in #getFeatures, #query, and #iterator to prevent
16: * ConcurrentModificationExceptions.
17: */
18: // Used as the cache for a CachedDynamicFeatureCollection [Jon Aquino
19: // 2005-03-04]
20: public class ThreadSafeFeatureCollectionWrapper implements
21: FeatureCollection {
22:
23: private FeatureCollection featureCollection;
24:
25: public ThreadSafeFeatureCollectionWrapper(
26: FeatureCollection featureCollection) {
27: this .featureCollection = featureCollection;
28: }
29:
30: public synchronized FeatureSchema getFeatureSchema() {
31: return featureCollection.getFeatureSchema();
32: }
33:
34: public synchronized Envelope getEnvelope() {
35: return featureCollection.getEnvelope();
36: }
37:
38: public synchronized int size() {
39: return featureCollection.size();
40: }
41:
42: public synchronized boolean isEmpty() {
43: return featureCollection.isEmpty();
44: }
45:
46: public synchronized List getFeatures() {
47: return new ArrayList(featureCollection.getFeatures());
48: }
49:
50: public synchronized Iterator iterator() {
51: return new ArrayList(featureCollection.getFeatures())
52: .iterator();
53: }
54:
55: public synchronized List query(Envelope envelope) {
56: return new ArrayList(featureCollection.query(envelope));
57: }
58:
59: public synchronized void add(Feature feature) {
60: featureCollection.add(feature);
61:
62: }
63:
64: public synchronized void addAll(Collection features) {
65: featureCollection.addAll(features);
66:
67: }
68:
69: public synchronized void removeAll(Collection features) {
70: featureCollection.removeAll(features);
71:
72: }
73:
74: public synchronized void remove(Feature feature) {
75: featureCollection.remove(feature);
76:
77: }
78:
79: public synchronized void clear() {
80: featureCollection.clear();
81:
82: }
83:
84: public synchronized Collection remove(Envelope env) {
85: return featureCollection.remove(env);
86: }
87:
88: }
|