1 package org.kuali.common.util.metainf.model;
2
3 import com.google.common.collect.ImmutableList;
4 import org.kuali.common.util.metainf.spring.MetaInfDataLocation;
5 import org.kuali.common.util.metainf.spring.MetaInfDataType;
6
7 import java.util.Collections;
8 import java.util.Comparator;
9 import java.util.List;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class MetaInfResourceConfigurablePathComparator implements Comparator<MetaInfResource> {
27
28 private ConfigurablePathComparator comparator = ConfigurablePathComparator.builder().build();
29
30 @Override
31 public int compare(MetaInfResource one, MetaInfResource two) {
32 return comparator.compare(one.getLocation(), two.getLocation());
33 }
34
35 public static Builder builder() {
36 return new Builder();
37 }
38
39 public static class Builder {
40
41
42 private List<String> qualifierOrder = Collections.emptyList();
43 private List<MetaInfDataLocation> locationOrder = Collections.emptyList();
44 private List<MetaInfDataType> typeOrder = Collections.emptyList();
45
46 public Builder qualifierOrder(List<String> qualifierOrder) {
47 this.qualifierOrder = qualifierOrder;
48 return this;
49 }
50
51 public Builder locationOrder(List<MetaInfDataLocation> locationOrder) {
52 this.locationOrder = locationOrder;
53 return this;
54 }
55
56 public Builder typeOrder(List<MetaInfDataType> typeOrder) {
57 this.typeOrder = typeOrder;
58 return this;
59 }
60
61 public MetaInfResourceConfigurablePathComparator build() {
62 this.qualifierOrder = ImmutableList.copyOf(qualifierOrder);
63 this.locationOrder = ImmutableList.copyOf(locationOrder);
64 this.typeOrder = ImmutableList.copyOf(typeOrder);
65 return new MetaInfResourceConfigurablePathComparator(this);
66 }
67
68 }
69
70 private MetaInfResourceConfigurablePathComparator(Builder builder) {
71 ConfigurablePathComparator.Builder comparatorBuilder = ConfigurablePathComparator.builder();
72 comparatorBuilder = comparatorBuilder.qualifierOrder(builder.qualifierOrder);
73 comparatorBuilder = comparatorBuilder.locationOrder(builder.locationOrder);
74 comparatorBuilder = comparatorBuilder.typeOrder(builder.typeOrder);
75 comparator = comparatorBuilder.build();
76 }
77
78 }