View Javadoc
1   /*
2    * Copyright 2005-2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
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   */
16  package org.kuali.ole.gl.batch;
17  
18  import java.util.Comparator;
19  import java.util.Map;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.gl.GeneralLedgerConstants;
23  import org.kuali.ole.gl.businessobject.OriginEntryFieldUtil;
24  import org.kuali.ole.sys.OLEPropertyConstants;
25  
26  public class ScrubberSortComparator implements Comparator<String> {
27  
28          OriginEntryFieldUtil oefu = new OriginEntryFieldUtil();
29          Map<String, Integer> pMap = oefu.getFieldBeginningPositionMap();
30      int originEntryRecordLength = GeneralLedgerConstants.getSpaceAllOriginEntryFields().length(); 
31              
32      private class Range {
33          public Range( int start, int end ) { this.start = start; this.end = end; }
34          public int start;
35          public int end;
36      }
37      
38      Range[] compareRanges;
39      {
40          compareRanges = new Range[6];
41          compareRanges[0] = new Range(pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE), pMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER));
42          compareRanges[1] = new Range(pMap.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE), pMap.get(OLEPropertyConstants.FINANCIAL_OBJECT_CODE));
43          compareRanges[2] = new Range(pMap.get(OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE), pMap.get(OLEPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE));
44          compareRanges[3] = new Range(pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE), pMap.get(OLEPropertyConstants.TRANSACTION_ENCUMBRANCE_UPDT_CD));
45          compareRanges[4] = new Range(pMap.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR), pMap.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE));
46          compareRanges[5] = new Range(pMap.get(OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE), pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE));
47      }
48      
49      public int compare(String string1, String string2) {
50          string1 = StringUtils.rightPad(string1, originEntryRecordLength, ' ');
51          string2 = StringUtils.rightPad(string2, originEntryRecordLength, ' ');
52  
53          StringBuilder sb1 = new StringBuilder();
54          sb1.append(string1.substring(compareRanges[0].start,compareRanges[0].end));
55          sb1.append(string1.substring(compareRanges[1].start,compareRanges[1].end));
56          sb1.append(string1.substring(compareRanges[2].start,compareRanges[2].end));
57          sb1.append(string1.substring(compareRanges[3].start,compareRanges[3].end));
58          sb1.append(string1.substring(compareRanges[4].start,compareRanges[4].end));
59          sb1.append(string1.substring(compareRanges[5].start,compareRanges[5].end));
60              
61          StringBuilder sb2 = new StringBuilder();
62          sb2.append(string2.substring(compareRanges[0].start,compareRanges[0].end));
63          sb2.append(string2.substring(compareRanges[1].start,compareRanges[1].end));
64          sb2.append(string2.substring(compareRanges[2].start,compareRanges[2].end));
65          sb2.append(string2.substring(compareRanges[3].start,compareRanges[3].end));
66          sb2.append(string2.substring(compareRanges[4].start,compareRanges[4].end));
67          sb2.append(string2.substring(compareRanges[5].start,compareRanges[5].end));
68              
69          return sb1.toString().compareTo(sb2.toString());
70      }
71  }