1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.api.criteria;
17
18 import org.kuali.rice.core.api.mo.ModelBuilder;
19
20 import java.io.Serializable;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class LookupCustomizer<T> {
49
50
51 private final Transform<Predicate,Predicate> predicateTransform;
52 private final Transform<T, T> resultTransform;
53
54 private LookupCustomizer(Builder<T> builder) {
55 this.predicateTransform = builder.getPredicateTransform() != null ? builder.getPredicateTransform() : IndentityTransform.<Predicate, Predicate>getInstance();
56 this.resultTransform = builder.getResultTransform() != null ? builder.getResultTransform() : IndentityTransform.<T, T>getInstance();
57 }
58
59 public Transform<Predicate, Predicate> getPredicateTransform() {
60 return predicateTransform;
61 }
62
63 public Transform<T, T> getResultTransform() {
64 return resultTransform;
65 }
66
67 public static final class Builder<T> implements ModelBuilder, Serializable {
68
69 private Transform<Predicate, Predicate> predicateTransform;
70 private Transform<T, T> resultTransform;
71
72 private Builder() {
73
74 }
75
76 public static <T> Builder<T> create() {
77 return new Builder<T>();
78 }
79
80 public Transform<Predicate, Predicate> getPredicateTransform() {
81 return predicateTransform;
82 }
83
84 public void setPredicateTransform(final Transform<Predicate, Predicate> predicateTransform) {
85 this.predicateTransform = predicateTransform;
86 }
87
88 public Transform<T, T> getResultTransform() {
89 return resultTransform;
90 }
91
92 public void setResultTransform(final Transform<T, T> resultTransform) {
93 this.resultTransform = resultTransform;
94 }
95
96 @Override
97 public LookupCustomizer<T> build() {
98 return new LookupCustomizer<T>(this);
99 }
100 }
101 public interface Transform<P, R> {
102 R apply(P input);
103 }
104
105
106
107
108
109
110 private static final class IndentityTransform<I> implements Transform<I, I> {
111
112 @SuppressWarnings("unchecked")
113 private static final Transform INSTANCE = new IndentityTransform();
114
115 @SuppressWarnings("unchecked")
116 public static <P, R> Transform<P, R> getInstance() {
117 return INSTANCE;
118 }
119
120 @Override
121 public I apply(final I input) {
122 return input;
123 }
124 }
125 }