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