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 javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlElement;
21 import javax.xml.bind.annotation.XmlElements;
22 import javax.xml.bind.annotation.XmlType;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.Set;
26
27
28
29
30
31
32
33
34
35
36 @XmlAccessorType(XmlAccessType.NONE)
37 @XmlType(name = AbstractCompositePredicate.Constants.TYPE_NAME)
38 abstract class AbstractCompositePredicate extends AbstractPredicate implements CompositePredicate {
39
40 private static final long serialVersionUID = 6164560054223588779L;
41 private static final String LINE_SEPARATOR = System.getProperty("line.separator");
42
43
44
45
46
47
48
49 @XmlElements(value = {
50 @XmlElement(name = AndPredicate.Constants.ROOT_ELEMENT_NAME, type = AndPredicate.class, required = false),
51 @XmlElement(name = EqualPredicate.Constants.ROOT_ELEMENT_NAME, type = EqualPredicate.class, required = false),
52 @XmlElement(name = EqualIgnoreCasePredicate.Constants.ROOT_ELEMENT_NAME, type = EqualIgnoreCasePredicate.class, required = false),
53 @XmlElement(name = ExistsSubQueryPredicate.Constants.ROOT_ELEMENT_NAME, type = ExistsSubQueryPredicate.class, required = false),
54 @XmlElement(name = GreaterThanPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanPredicate.class, required = false),
55 @XmlElement(name = GreaterThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanOrEqualPredicate.class, required = false),
56 @XmlElement(name = InPredicate.Constants.ROOT_ELEMENT_NAME, type = InPredicate.class, required = false),
57 @XmlElement(name = InIgnoreCasePredicate.Constants.ROOT_ELEMENT_NAME, type = InIgnoreCasePredicate.class, required = false),
58 @XmlElement(name = LessThanPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanPredicate.class, required = false),
59 @XmlElement(name = LessThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanOrEqualPredicate.class, required = false),
60 @XmlElement(name = LikePredicate.Constants.ROOT_ELEMENT_NAME, type = LikePredicate.class, required = false),
61 @XmlElement(name = LikeIgnoreCasePredicate.Constants.ROOT_ELEMENT_NAME, type = LikeIgnoreCasePredicate.class, required = false),
62 @XmlElement(name = NotEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = NotEqualPredicate.class, required = false),
63 @XmlElement(name = NotEqualIgnoreCasePredicate.Constants.ROOT_ELEMENT_NAME, type = NotEqualIgnoreCasePredicate.class, required = false),
64 @XmlElement(name = NotInPredicate.Constants.ROOT_ELEMENT_NAME, type = NotInPredicate.class, required = false),
65 @XmlElement(name = NotInIgnoreCasePredicate.Constants.ROOT_ELEMENT_NAME, type = NotInIgnoreCasePredicate.class, required = false),
66 @XmlElement(name = NotLikePredicate.Constants.ROOT_ELEMENT_NAME, type = NotLikePredicate.class, required = false),
67 @XmlElement(name = NotNullPredicate.Constants.ROOT_ELEMENT_NAME, type = NotNullPredicate.class, required = false),
68 @XmlElement(name = NullPredicate.Constants.ROOT_ELEMENT_NAME, type = NullPredicate.class, required = false),
69 @XmlElement(name = OrPredicate.Constants.ROOT_ELEMENT_NAME, type = OrPredicate.class, required = false)
70 })
71 private final Set<Predicate> predicates;
72
73
74
75
76
77 AbstractCompositePredicate() {
78 this.predicates = null;
79 }
80
81
82
83
84
85
86
87
88 AbstractCompositePredicate(final Set<Predicate> predicates) {
89 if (predicates == null) {
90 this.predicates = Collections.emptySet();
91 } else {
92 final Set<Predicate> temp = new HashSet<Predicate>();
93 for (Predicate predicate: predicates) {
94 if (predicate != null) {
95 temp.add(predicate);
96 }
97 }
98 this.predicates = Collections.unmodifiableSet(temp);
99 }
100 }
101
102 @Override
103 public Set<Predicate> getPredicates() {
104 return Collections.unmodifiableSet(predicates);
105 }
106
107
108
109
110 static class Constants {
111 final static String TYPE_NAME = "CompositePredicateType";
112 }
113
114 @Override
115 public final String toString() {
116 StringBuilder b = new StringBuilder(CriteriaSupportUtils.findDynName(this.getClass().getSimpleName()));
117 b.append("(");
118 if (!predicates.isEmpty()) {
119 for (Predicate p : predicates) {
120 b.append(LINE_SEPARATOR);
121
122 b.append(p);
123 b.append(", ");
124 }
125 b.deleteCharAt(b.lastIndexOf(", "));
126 b.append(LINE_SEPARATOR);
127 }
128 b.append(')');
129 return b.toString();
130 }
131 }