01: package org.libresource.form;
02:
03: import java.util.ArrayList;
04: import java.util.Collection;
05: import java.util.Iterator;
06:
07: public class FormResultSet extends ArrayList<Form> {
08: private static final long serialVersionUID = 1L;
09: private ArrayList<String> ids;
10: private ArrayList<String> labels;
11: private ArrayList<IdLabelBean> idLabels;
12:
13: public FormResultSet() {
14: super ();
15: ids = new ArrayList<String>();
16: labels = new ArrayList<String>();
17: }
18:
19: @Override
20: public boolean add(Form e) {
21: if (ids.size() == 0) {
22: ids.addAll(e.getIds());
23: labels.addAll(e.getFieldsLabel());
24: } else {
25: for (String id : e.getIds()) {
26: if (!ids.contains(id)) {
27: ids.add(id);
28: labels.add(e.getLabel(id));
29: }
30: }
31: }
32:
33: return super .add(e);
34: }
35:
36: public ArrayList<String> getIds() {
37: return ids;
38: }
39:
40: public void setIds(ArrayList<String> ids) {
41: this .ids = ids;
42: }
43:
44: public ArrayList<String> getLabels() {
45: return labels;
46: }
47:
48: public void setLabels(ArrayList<String> labels) {
49: this .labels = labels;
50: }
51:
52: public void filter(Collection<String> idToKeep) {
53: Iterator<String> idIterator = ids.iterator();
54: Iterator<String> labelIterator = labels.iterator();
55: while (idIterator.hasNext()) {
56: labelIterator.next();
57: if (!idToKeep.contains(idIterator.next())) {
58: labelIterator.remove();
59: idIterator.remove();
60: }
61: }
62: }
63:
64: public ArrayList<IdLabelBean> getIdsLabels() {
65: if (idLabels == null) {
66: idLabels = new ArrayList<IdLabelBean>();
67: Iterator<String> idsIterator = ids.iterator();
68: Iterator<String> labelIterator = labels.iterator();
69: while (idsIterator.hasNext()) {
70: idLabels.add(new IdLabelBean(idsIterator.next(),
71: labelIterator.next()));
72: }
73: }
74:
75: return idLabels;
76: }
77:
78: }
|