View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.core.api.util;
17  
18  
19  import org.apache.commons.lang.ObjectUtils;
20  import org.apache.commons.lang.StringUtils;
21  
22  public class KpmeUtils {
23      public static String formatAssignmentKey(String groupKeyCode, Long jobNumber, Long workArea, Long task) {
24          String assignmentKey = StringUtils.EMPTY;
25  
26          String jobNumberString = ObjectUtils.toString(jobNumber, "0");
27          String workAreaString = ObjectUtils.toString(workArea, "0");
28          String taskString = ObjectUtils.toString(task, "0");
29  
30          if (!jobNumberString.equals("0") || !workAreaString.equals("0") || !taskString.equals("0")) {
31              assignmentKey = StringUtils.join(new String[] {groupKeyCode, jobNumberString, workAreaString, taskString}, HrApiConstants.ASSIGNMENT_KEY_DELIMITER);
32          }
33  
34          return assignmentKey;
35      }
36  
37      public static <T extends Comparable<? super T>> int nullSafeCompare(T s1, T s2) {
38          if(s1 == null && s2 != null) { return -1;}
39          if(s1 != null && s2 == null) { return 1;}
40          if(s1 == null) { return 0;}
41          return s1.compareTo(s2);
42      }
43  }