1 | public class Difference extends BaseResourceCollectionContainer {↵ | | 1 | public class Intersect extends BaseResourceCollectionContainer {↵
|
|
2 | /**↵ | | 2 | /**↵
|
3 | * Calculate the difference of the nested ResourceCollections.↵ | | 3 | * Calculate the intersection of the nested ResourceCollections.↵
|
4 | * @return a Collection of Resources.↵ | | 4 | * @return a Collection of Resources.↵
|
5 | */↵ | | 5 | */↵
|
6 | protected Collection getCollection() {↵ | | 6 | protected Collection getCollection() {↵
|
7 | List rc = getResourceCollections();↵ | | 7 | List rcs = getResourceCollections();↵
|
8 | int size = rc.size();↵ | | 8 | int size = rcs.size();↵
|
9 | if (size < 2) {↵ | | 9 | if (size < 2) {↵
|
10 | throw new BuildException("The difference of " + size↵ | | 10 | throw new BuildException("The intersection of " + size↵
|
11 | + " resource collection" + ((size == 1) ? "" : "s")↵ | | 11 | + " resource collection" + ((size == 1) ? "" : "s")↵
|
12 | + " is undefined.");↵ | | 12 | + " is undefined.");↵
|
13 | }↵ | | 13 | }↵
|
14 | HashSet hs = new HashSet();↵ | | |
|
15 | ArrayList al = new ArrayList();↵ | | 14 | ArrayList al = new ArrayList();↵
|
16 | for (Iterator rcIter = rc.iterator(); rcIter.hasNext();) {↵ | | 15 | Iterator rc = rcs.iterator();↵
|
17 | for (Iterator r = nextRC(rcIter).iterator(); r.hasNext();) {↵ | | |
|
18 | Object next = r↵ | | |
|
19 | .next();↵ | | 16 | al.addAll(collect(rc.next()));↵
|
20 | if (hs.add(next)) {↵ | | 17 | while (rc.hasNext()) {↵
|
21 | al.add(next);↵ | | 18 | ↵
|
22 | } else {↵ | | |
|
23 | al.remove(next);↵ | | |
|
24 | }↵ | | |
|
25 | }↵ | | |
|
26 | }↵ | | |
|
27 | return al↵ | | 19 | al.retainAll(collect(rc.next()));↵
|
| | | 20 | }↵
|
| | | 21 | return al;↵
|
| | | 22 | }↵
|
|
| | | 23 | private ArrayList collect(Object o) {↵
|
28 | ;↵ | | 24 | ArrayList result = new ArrayList();↵
|
29 | }↵ | | 25 | ↵
|
|
30 | private static ResourceCollection nextRC(Iterator i) {↵ | | 26 | for (Iterator i = ((ResourceCollection) o).iterator(); i.hasNext();) {↵
|
31 | return (ResourceCollection) i.next()↵ | | 27 | result.add(i.next());↵
|
| | | 28 | }↵
|
32 | ;↵ | | 29 | return result;↵
|
33 | | | 30 |
|