1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.api.util;
17
18
19 import org.apache.commons.collections.MapUtils;
20 import org.apache.commons.lang.ObjectUtils;
21 import org.apache.commons.lang.StringUtils;
22 import org.joda.time.LocalDate;
23 import org.kuali.kpme.core.api.assignment.Assignment;
24
25 import java.util.*;
26
27 public class KpmeUtils {
28 public static String formatAssignmentKey(String groupKeyCode, Long jobNumber, Long workArea, Long task) {
29 String assignmentKey = StringUtils.EMPTY;
30
31 String jobNumberString = ObjectUtils.toString(jobNumber, "0");
32 String workAreaString = ObjectUtils.toString(workArea, "0");
33 String taskString = ObjectUtils.toString(task, "0");
34
35 if (!jobNumberString.equals("0") || !workAreaString.equals("0") || !taskString.equals("0")) {
36 assignmentKey = StringUtils.join(new String[] {groupKeyCode, jobNumberString, workAreaString, taskString}, HrApiConstants.ASSIGNMENT_KEY_DELIMITER);
37 }
38
39 return assignmentKey;
40 }
41
42 public static List<Assignment> getUniqueAssignments(Map<LocalDate, List<Assignment>> history) {
43 if (MapUtils.isEmpty(history)) {
44 return Collections.emptyList();
45 }
46 Set<Assignment> allAssignments = new HashSet<Assignment>();
47 for (List<Assignment> assignList : history.values()) {
48 allAssignments.addAll(assignList);
49 }
50 return new ArrayList<Assignment>(allAssignments);
51 }
52
53 public static <T extends Comparable<? super T>> int nullSafeCompare(T s1, T s2) {
54 if(s1 == null && s2 != null) { return -1;}
55 if(s1 != null && s2 == null) { return 1;}
56 if(s1 == null) { return 0;}
57 return s1.compareTo(s2);
58 }
59 }