blob: 1cc9641af7e3ce21b329151a995ad9d831f767b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package org.bouncycastle.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
/**
* A simple collection backed store.
*/
public class CollectionStore<T>
implements Store<T>, Iterable<T>
{
private Collection<T> _local;
/**
* Basic constructor.
*
* @param collection - initial contents for the store, this is copied.
*/
public CollectionStore(
Collection<T> collection)
{
_local = new ArrayList<T>(collection);
}
/**
* Return the matches in the collection for the passed in selector.
*
* @param selector the selector to match against.
* @return a possibly empty collection of matching objects.
*/
public Collection<T> getMatches(Selector<T> selector)
{
if (selector == null)
{
return new ArrayList<T>(_local);
}
else
{
List<T> col = new ArrayList<T>();
Iterator<T> iter = _local.iterator();
while (iter.hasNext())
{
T obj = iter.next();
if (selector.match(obj))
{
col.add(obj);
}
}
return col;
}
}
public Iterator<T> iterator()
{
return getMatches(null).iterator();
}
}
|