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 = true),
51 @XmlElement(name = EqualPredicate.Constants.ROOT_ELEMENT_NAME, type = EqualPredicate.class, required = true),
52 @XmlElement(name = GreaterThanPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanPredicate.class, required = true),
53 @XmlElement(name = GreaterThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = GreaterThanOrEqualPredicate.class, required = true),
54 @XmlElement(name = InPredicate.Constants.ROOT_ELEMENT_NAME, type = InPredicate.class, required = true),
55 @XmlElement(name = LessThanPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanPredicate.class, required = true),
56 @XmlElement(name = LessThanOrEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = LessThanOrEqualPredicate.class, required = true),
57 @XmlElement(name = LikePredicate.Constants.ROOT_ELEMENT_NAME, type = LikePredicate.class, required = true),
58 @XmlElement(name = NotEqualPredicate.Constants.ROOT_ELEMENT_NAME, type = NotEqualPredicate.class, required = true),
59 @XmlElement(name = NotInPredicate.Constants.ROOT_ELEMENT_NAME, type = NotInPredicate.class, required = true),
60 @XmlElement(name = NotLikePredicate.Constants.ROOT_ELEMENT_NAME, type = NotLikePredicate.class, required = true),
61 @XmlElement(name = NotNullPredicate.Constants.ROOT_ELEMENT_NAME, type = NotNullPredicate.class, required = true),
62 @XmlElement(name = NullPredicate.Constants.ROOT_ELEMENT_NAME, type = NullPredicate.class, required = true),
63 @XmlElement(name = OrPredicate.Constants.ROOT_ELEMENT_NAME, type = OrPredicate.class, required = true)
64 })
65 private final Set<Predicate> predicates;
66
67
68
69
70
71 AbstractCompositePredicate() {
72 this.predicates = null;
73 }
74
75
76
77
78
79
80
81
82 AbstractCompositePredicate(final Set<Predicate> predicates) {
83 if (predicates == null) {
84 this.predicates = Collections.emptySet();
85 } else {
86 final Set<Predicate> temp = new HashSet<Predicate>();
87 for (Predicate predicate: predicates) {
88 if (predicate != null) {
89 temp.add(predicate);
90 }
91 }
92 this.predicates = Collections.unmodifiableSet(temp);
93 }
94 }
95
96 @Override
97 public Set<Predicate> getPredicates() {
98 return Collections.unmodifiableSet(predicates);
99 }
100
101
102
103
104 static class Constants {
105 final static String TYPE_NAME = "CompositePredicateType";
106 }
107
108 @Override
109 public final String toString() {
110 StringBuilder b = new StringBuilder(CriteriaSupportUtils.findDynName(this.getClass().getSimpleName()));
111 b.append("(");
112 if (!predicates.isEmpty()) {
113 for (Predicate p : predicates) {
114 b.append(LINE_SEPARATOR);
115
116 b.append(p);
117 b.append(", ");
118 }
119 b.deleteCharAt(b.lastIndexOf(", "));
120 b.append(LINE_SEPARATOR);
121 }
122 b.append(')');
123 return b.toString();
124 }
125 }