01: package org.bouncycastle.util;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Iterator;
06: import java.util.List;
07:
08: /**
09: * A simple collection backed store.
10: */
11: public class CollectionStore implements Store {
12: private Collection _local;
13:
14: /**
15: * Basic constructor.
16: *
17: * @param collection - initial contents for the store, this is copied.
18: */
19: public CollectionStore(Collection collection) {
20: _local = new ArrayList(collection);
21: }
22:
23: /**
24: * Return the matches in the collection for the passed in selector.
25: *
26: * @param selector the selector to match against.
27: * @return a possibly empty collection of matching objects.
28: */
29: public Collection getMatches(Selector selector) {
30: if (selector == null) {
31: return new ArrayList(_local);
32: } else {
33: List col = new ArrayList();
34: Iterator iter = _local.iterator();
35:
36: while (iter.hasNext()) {
37: Object obj = iter.next();
38:
39: if (selector.match(obj)) {
40: col.add(obj);
41: }
42: }
43:
44: return col;
45: }
46: }
47: }
|