1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
package org.kuali.rice.core.api.criteria; |
9 | |
|
10 | |
import javax.xml.bind.annotation.XmlAccessType; |
11 | |
import javax.xml.bind.annotation.XmlAccessorType; |
12 | |
import javax.xml.bind.annotation.XmlElement; |
13 | |
import javax.xml.bind.annotation.XmlElements; |
14 | |
import javax.xml.bind.annotation.XmlType; |
15 | |
import java.util.Collections; |
16 | |
import java.util.HashSet; |
17 | |
import java.util.Set; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
@XmlAccessorType(XmlAccessType.NONE) |
29 | |
@XmlType(name = AbstractCompositePredicate.Constants.TYPE_NAME) |
30 | |
abstract class AbstractCompositePredicate extends AbstractPredicate implements CompositePredicate { |
31 | |
|
32 | |
private static final long serialVersionUID = 6164560054223588779L; |
33 | 1 | private static final String LINE_SEPARATOR = System.getProperty("line.separator"); |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
@XmlElements(value = { |
42 | |
@XmlElement(name = AndPredicate.Constants.ROOT_ELEMENT_NAME, type = AndPredicate.class, required = true), |
43 | |
@XmlElement(name = EqualPredicate.Constants.ROOT_ELEMENT_NAME, type = EqualPredicate.class, required = true), |
44 | |
@XmlElement(name = GreaterThanPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanPredicate.class, required = true), |
45 | |
@XmlElement(name = GreaterThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanOrEqualPredicate.class, required = true), |
46 | |
@XmlElement(name = InPredicate.Constants.ROOT_ELEMENT_NAME, type = InPredicate.class, required = true), |
47 | |
@XmlElement(name = LessThanPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanPredicate.class, required = true), |
48 | |
@XmlElement(name = LessThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanOrEqualPredicate.class, required = true), |
49 | |
@XmlElement(name = LikePredicate.Constants.ROOT_ELEMENT_NAME, type = LikePredicate.class, required = true), |
50 | |
@XmlElement(name = NotEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = NotEqualPredicate.class, required = true), |
51 | |
@XmlElement(name = NotInPredicate.Constants.ROOT_ELEMENT_NAME, type = NotInPredicate.class, required = true), |
52 | |
@XmlElement(name = NotLikePredicate.Constants.ROOT_ELEMENT_NAME, type = NotLikePredicate.class, required = true), |
53 | |
@XmlElement(name = NotNullPredicate.Constants.ROOT_ELEMENT_NAME, type = NotNullPredicate.class, required = true), |
54 | |
@XmlElement(name = NullPredicate.Constants.ROOT_ELEMENT_NAME, type = NullPredicate.class, required = true), |
55 | |
@XmlElement(name = OrPredicate.Constants.ROOT_ELEMENT_NAME, type = OrPredicate.class, required = true) |
56 | |
}) |
57 | |
private final Set<Predicate> predicates; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | 20 | AbstractCompositePredicate() { |
64 | 20 | this.predicates = null; |
65 | 20 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 29 | AbstractCompositePredicate(final Set<Predicate> predicates) { |
75 | 29 | if (predicates == null) { |
76 | 2 | this.predicates = Collections.emptySet(); |
77 | |
} else { |
78 | 27 | final Set<Predicate> temp = new HashSet<Predicate>(); |
79 | 27 | for (Predicate predicate: predicates) { |
80 | 70 | if (predicate != null) { |
81 | 70 | temp.add(predicate); |
82 | |
} |
83 | |
} |
84 | 27 | this.predicates = Collections.unmodifiableSet(temp); |
85 | |
} |
86 | 29 | } |
87 | |
|
88 | |
@Override |
89 | |
public Set<Predicate> getPredicates() { |
90 | 15 | return Collections.unmodifiableSet(predicates); |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | 0 | static class Constants { |
97 | |
final static String TYPE_NAME = "CompositePredicateType"; |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
public final String toString() { |
102 | 0 | StringBuilder b = new StringBuilder(CriteriaSupportUtils.findDynName(this.getClass().getSimpleName())); |
103 | 0 | b.append("("); |
104 | 0 | if (!predicates.isEmpty()) { |
105 | 0 | for (Predicate p : predicates) { |
106 | 0 | b.append(LINE_SEPARATOR); |
107 | |
|
108 | 0 | b.append(p); |
109 | 0 | b.append(", "); |
110 | |
} |
111 | 0 | b.deleteCharAt(b.lastIndexOf(", ")); |
112 | 0 | b.append(LINE_SEPARATOR); |
113 | |
} |
114 | 0 | b.append(')'); |
115 | 0 | return b.toString(); |
116 | |
} |
117 | |
} |