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