-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMergedCollection.java
More file actions
42 lines (33 loc) · 1.05 KB
/
MergedCollection.java
File metadata and controls
42 lines (33 loc) · 1.05 KB
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
package org.psjava.util;
import java.util.Iterator;
import org.psjava.ds.PSCollection;
public class MergedCollection {
public static <T> PSCollection<T> wrap(final Iterable<? extends PSCollection<? extends T>> collections) {
return new PSCollection<T>() {
@Override
public Iterator<T> iterator() {
return MergedIterator.create(collections);
}
@Override
public boolean isEmpty() {
for (PSCollection<? extends T> c : collections)
if (!c.isEmpty())
return false;
return true;
}
@Override
public int size() {
int sum = 0;
for (PSCollection<? extends T> c : collections)
sum += c.size();
return sum;
}
@Override
public String toString() {
return IterableToString.toString(this);
}
};
}
private MergedCollection() {
}
}