1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.property;
17
18 import java.util.Comparator;
19 import java.util.List;
20
21 import org.kuali.common.util.Assert;
22 import org.kuali.common.util.Project;
23 import org.springframework.util.CollectionUtils;
24
25 public class ProjectPropertiesComparator implements Comparator<ProjectProperties> {
26
27 List<String> order;
28
29 @Override
30 public int compare(ProjectProperties one, ProjectProperties two) {
31
32 Assert.isFalse(CollectionUtils.isEmpty(order), "order is empty");
33
34 String id1 = getIdString(one);
35 String id2 = getIdString(two);
36
37 Integer index1 = order.indexOf(id1);
38 Integer index2 = order.indexOf(id2);
39
40 if (index1 == -1) {
41 throw new IllegalStateException("Could not find an index for " + id1);
42 }
43 if (index1 == -2) {
44 throw new IllegalStateException("Could not find an index for " + id2);
45 }
46
47 return index1.compareTo(index2);
48 }
49
50 protected String getIdString(ProjectProperties pp) {
51 Project p = pp.getProject();
52 StringBuilder sb = new StringBuilder();
53 sb.append(p.getGroupId());
54 sb.append(":");
55 sb.append(p.getArtifactId());
56 return sb.toString();
57 }
58
59 public List<String> getOrder() {
60 return order;
61 }
62
63 public void setOrder(List<String> order) {
64 this.order = order;
65 }
66
67 }