1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.ole.gl.businessobject;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Comparator;
22 import java.util.Iterator;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25
26 import org.kuali.ole.sys.OLEPropertyConstants;
27 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
28
29
30
31
32 public class CorrectionChangeGroup extends PersistableBusinessObjectBase implements Comparable {
33 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CorrectionChangeGroup.class);
34
35 private String documentNumber;
36 private Integer correctionChangeGroupLineNumber;
37 private Integer correctionCriteriaNextLineNumber;
38 private Integer correctionChangeNextLineNumber;
39 private List<CorrectionCriteria> correctionCriteria;
40 private List<CorrectionChange> correctionChange;
41
42 public CorrectionChangeGroup(String documentNumber, Integer correctionChangeGroupLineNumber) {
43 setCorrectionChangeGroupLineNumber(correctionChangeGroupLineNumber);
44
45 correctionCriteria = new ArrayList();
46 correctionChange = new ArrayList();
47 correctionCriteriaNextLineNumber = new Integer(0);
48 correctionChangeNextLineNumber = new Integer(0);
49
50 setDocumentNumber(documentNumber);
51 }
52
53 public CorrectionChangeGroup() {
54 super();
55 correctionCriteria = new ArrayList();
56 correctionChange = new ArrayList();
57 correctionCriteriaNextLineNumber = new Integer(0);
58 correctionChangeNextLineNumber = new Integer(0);
59 }
60
61
62
63
64
65
66 public void addCorrectionChange(CorrectionChange cc) {
67 LOG.debug("addCorrectionChange() started");
68
69 cc.setDocumentNumber(documentNumber);
70 cc.setCorrectionChangeGroupLineNumber(correctionChangeGroupLineNumber);
71 cc.setCorrectionChangeLineNumber(correctionChangeNextLineNumber++);
72 correctionChange.add(cc);
73 }
74
75
76
77
78
79
80 public void addCorrectionCriteria(CorrectionCriteria cc) {
81 cc.setDocumentNumber(documentNumber);
82 cc.setCorrectionChangeGroupLineNumber(correctionChangeGroupLineNumber);
83 cc.setCorrectionCriteriaLineNumber(correctionCriteriaNextLineNumber++);
84 correctionCriteria.add(cc);
85 }
86
87
88
89
90
91
92 public void removeCorrectionChangeItem(int changeNumber) {
93 for (Iterator iter = correctionChange.iterator(); iter.hasNext();) {
94 CorrectionChange element = (CorrectionChange) iter.next();
95 if (changeNumber == element.getCorrectionChangeLineNumber().intValue()) {
96 iter.remove();
97 }
98 }
99 }
100
101
102
103
104
105
106 public void removeCorrectionCriteriaItem(int criteriaNumber) {
107 for (Iterator iter = correctionCriteria.iterator(); iter.hasNext();) {
108 CorrectionCriteria element = (CorrectionCriteria) iter.next();
109 if (criteriaNumber == element.getCorrectionCriteriaLineNumber().intValue()) {
110 iter.remove();
111 }
112 }
113 }
114
115
116
117
118
119
120
121 public CorrectionChange getCorrectionChangeItem(int changeNumber) {
122 for (Iterator iter = correctionChange.iterator(); iter.hasNext();) {
123 CorrectionChange element = (CorrectionChange) iter.next();
124 if (changeNumber == element.getCorrectionChangeLineNumber().intValue()) {
125 return element;
126 }
127 }
128
129 CorrectionChange cc = new CorrectionChange(getDocumentNumber(), correctionChangeGroupLineNumber, changeNumber);
130 correctionChange.add(cc);
131
132 return cc;
133 }
134
135
136
137
138
139
140
141
142 public CorrectionCriteria getCorrectionCriteriaItem(int criteriaNumber) {
143 for (Iterator iter = correctionCriteria.iterator(); iter.hasNext();) {
144 CorrectionCriteria element = (CorrectionCriteria) iter.next();
145 if (criteriaNumber == element.getCorrectionCriteriaLineNumber().intValue()) {
146 return element;
147 }
148 }
149
150 CorrectionCriteria cc = new CorrectionCriteria(getDocumentNumber(), correctionChangeGroupLineNumber, criteriaNumber);
151 correctionCriteria.add(cc);
152 return cc;
153 }
154
155 public String getDocumentNumber() {
156 return documentNumber;
157 }
158
159
160
161
162
163
164
165 public void setDocumentNumber(String documentNumber) {
166 this.documentNumber = documentNumber;
167
168 for (Iterator iter = correctionCriteria.iterator(); iter.hasNext();) {
169 CorrectionCriteria element = (CorrectionCriteria) iter.next();
170 element.setDocumentNumber(documentNumber);
171 }
172 for (Iterator iter = correctionChange.iterator(); iter.hasNext();) {
173 CorrectionChange element = (CorrectionChange) iter.next();
174 element.setDocumentNumber(documentNumber);
175 }
176 }
177
178 public Integer getCorrectionChangeGroupLineNumber() {
179 return correctionChangeGroupLineNumber;
180 }
181
182 public void setCorrectionChangeGroupLineNumber(Integer correctionChangeGroupLineNumber) {
183 this.correctionChangeGroupLineNumber = correctionChangeGroupLineNumber;
184 }
185
186 public Integer getCorrectionCriteriaNextLineNumber() {
187 return correctionCriteriaNextLineNumber;
188 }
189
190 public void setCorrectionCriteriaNextLineNumber(Integer correctionCriteriaNextLineNumber) {
191 this.correctionCriteriaNextLineNumber = correctionCriteriaNextLineNumber;
192 }
193
194 public Integer getCorrectionChangeNextLineNumber() {
195 return correctionChangeNextLineNumber;
196 }
197
198 public void setCorrectionChangeNextLineNumber(Integer correctionChangeNextLineNumber) {
199 this.correctionChangeNextLineNumber = correctionChangeNextLineNumber;
200 }
201
202 public List<CorrectionCriteria> getCorrectionCriteria() {
203 Collections.sort(correctionCriteria);
204 return correctionCriteria;
205 }
206
207 public void setCorrectionCriteria(List<CorrectionCriteria> correctionCriteria) {
208 this.correctionCriteria = correctionCriteria;
209 }
210
211 public List<CorrectionChange> getCorrectionChange() {
212 Collections.sort(correctionChange);
213 return correctionChange;
214 }
215
216 public void setCorrectionChange(List<CorrectionChange> correctionChange) {
217 this.correctionChange = correctionChange;
218 }
219
220
221
222
223
224
225 public int compareTo(Object o) {
226 CorrectionChangeGroup other = (CorrectionChangeGroup) o;
227
228 String thisFdocNbr = documentNumber == null ? "" : documentNumber;
229 String thatFdocNbr = other.documentNumber == null ? "" : other.documentNumber;
230
231 int c = thisFdocNbr.compareTo(thatFdocNbr);
232 if (c == 0) {
233 Integer thisNbr = correctionChangeGroupLineNumber == null ? 0 : correctionChangeGroupLineNumber;
234 Integer thatNbr = other.correctionChangeGroupLineNumber == null ? 0 : other.correctionChangeGroupLineNumber;
235 return thisNbr.compareTo(thatNbr);
236 }
237 else {
238 return c;
239 }
240 }
241
242
243
244
245 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
246 LinkedHashMap m = new LinkedHashMap();
247 m.put(OLEPropertyConstants.DOCUMENT_NUMBER, this.documentNumber);
248 if (this.correctionChangeGroupLineNumber != null) {
249 m.put("correctionChangeGroupLineNumber", this.correctionChangeGroupLineNumber.toString());
250 }
251 return m;
252 }
253
254
255
256
257
258 public static class CorrectionGroupLineNumberComparator implements Comparator {
259
260
261
262
263 public CorrectionGroupLineNumberComparator() {
264 }
265
266
267
268
269
270
271
272
273
274 public int compare(Object c1, Object c2) {
275
276 CorrectionChangeGroup ccg1 = (CorrectionChangeGroup) c1;
277 CorrectionChangeGroup ccg2 = (CorrectionChangeGroup) c2;
278
279 return ccg1.getCorrectionChangeGroupLineNumber().compareTo(ccg2.getCorrectionChangeGroupLineNumber());
280 }
281
282 }
283 }