01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.backend.list.helper.fields;
16:
17: import java.util.ArrayList;
18: import java.util.Collection;
19: import java.util.Iterator;
20: import java.util.LinkedHashSet;
21: import java.util.List;
22:
23: /**
24: * Composite implementation of {@link Fields}
25: * that combine the results of its children.
26: * <p>
27: * The concatenation of all fields are returned with no duplications.
28: *
29: * @see Fields
30: *
31: * @author Rein Raudjärv
32: *
33: * @since 1.1
34: */
35: public class ConcatFields implements Fields {
36:
37: private List children = new ArrayList();
38:
39: /**
40: * Adds an instance of {@link Fields} which results are used.
41: */
42: public void add(Fields fields) {
43: children.add(fields);
44: }
45:
46: public Collection getNames() {
47: // Concatenate all fields without duplicating any name
48: Collection result = new LinkedHashSet();
49:
50: for (Iterator it = children.iterator(); it.hasNext();) {
51: Fields child = (Fields) it.next();
52: result.addAll(child.getNames());
53: }
54: return result;
55: }
56:
57: public Collection getResultSetNames() {
58: // Concatenate all fields without duplicating any name
59: Collection result = new LinkedHashSet();
60:
61: for (Iterator it = children.iterator(); it.hasNext();) {
62: Fields child = (Fields) it.next();
63: result.addAll(child.getResultSetNames());
64: }
65: return result;
66: }
67:
68: }
|