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.kuali.ole.gl.businessobject.OriginEntryFieldUtil;
22  import org.kuali.ole.sys.OLEPropertyConstants;
23  
24  public class DemergerSortComparator implements Comparator<String> {
25  
26          OriginEntryFieldUtil oefu = new OriginEntryFieldUtil();
27          Map<String, Integer> pMap = oefu.getFieldBeginningPositionMap();
28              
29      private class Range {
30          public Range( int start, int end ) { this.start = start; this.end = end; }
31          public int start;
32          public int end;
33      }
34              
35      Range[] compareRanges;
36      {
37          compareRanges = new Range[2];
38          compareRanges[0] = new Range(pMap.get(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE),             pMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER));
39          compareRanges[1] = new Range(pMap.get(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER),        pMap.get(OLEPropertyConstants.TRANSACTION_LEDGER_ENTRY_DESC));
40          }
41              
42      public int compare(String string1, String string2) {
43          StringBuilder sb1 = new StringBuilder();
44          sb1.append(string1.substring(compareRanges[0].start,compareRanges[0].end));
45          sb1.append(string1.substring(compareRanges[1].start,compareRanges[1].end));
46  
47          StringBuilder sb2 = new StringBuilder();
48          sb2.append(string2.substring(compareRanges[0].start,compareRanges[0].end));
49          sb2.append(string2.substring(compareRanges[1].start,compareRanges[1].end));
50              
51          return sb1.toString().compareTo(sb2.toString());
52      }
53  }