01: package org.geotools.data.memory;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Collections;
06: import java.util.Iterator;
07: import java.util.List;
08:
09: import org.geotools.catalog.GeoResourceInfo;
10: import org.geotools.data.Transaction;
11: import org.opengis.feature.type.Name;
12: import org.opengis.feature.type.TypeName;
13: import org.opengis.filter.Filter;
14: import org.opengis.filter.capability.FilterCapabilities;
15:
16: /**
17: * Used to quickly adapt a collection for APIs expecting to
18: * be able to query generic content.
19: * <p>
20: * Please note that this is read-only access.
21: *
22: * @author Jody Garnett
23: */
24: public final class CollectionSource {
25:
26: private Collection collection;
27:
28: public CollectionSource(Collection collection) {
29: this .collection = Collections
30: .unmodifiableCollection(collection);
31: }
32:
33: public Collection content() {
34: return collection;
35: }
36:
37: public Collection content(String query, String queryLanguage) {
38: throw new UnsupportedOperationException(
39: "Please help me hook up the parser!");
40: }
41:
42: public Collection content(Filter filter) {
43: return content(filter, Integer.MAX_VALUE);
44: }
45:
46: public Collection content(Filter filter, int countLimit) {
47: List list = new ArrayList();
48: int count = 0;
49: for (Iterator i = collection.iterator(); i.hasNext()
50: && count < countLimit;) {
51: Object obj = i.next();
52: if (filter.evaluate(obj)) {
53: list.add(obj);
54: count++;
55: }
56: }
57: return Collections.unmodifiableList(list);
58: }
59:
60: public Object describe() {
61: return Object.class; // TODO: be more specific
62: }
63:
64: public void dispose() {
65: collection = null;
66: }
67:
68: public FilterCapabilities getFilterCapabilities() {
69: return null;
70: }
71:
72: public Name getName() {
73: return new org.geotools.feature.type.TypeName(
74: "localhost/memory");
75: }
76:
77: public void setTransaction(Transaction t) {
78: // ignored
79: }
80:
81: public GeoResourceInfo getInfo() {
82: return null; // TODO: info? at least scan through for bounds
83: }
84:
85: }
|