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.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.CoreConstants;
20 import org.w3c.dom.Element;
21
22 import javax.xml.bind.annotation.XmlAccessType;
23 import javax.xml.bind.annotation.XmlAccessorType;
24 import javax.xml.bind.annotation.XmlAnyElement;
25 import javax.xml.bind.annotation.XmlAttribute;
26 import javax.xml.bind.annotation.XmlElement;
27 import javax.xml.bind.annotation.XmlElements;
28 import javax.xml.bind.annotation.XmlRootElement;
29 import javax.xml.bind.annotation.XmlType;
30 import java.util.Collection;
31 import java.util.Collections;
32 import java.util.HashSet;
33 import java.util.Set;
34
35
36
37
38
39
40
41
42
43 @XmlRootElement(name = InPredicate.Constants.ROOT_ELEMENT_NAME)
44 @XmlAccessorType(XmlAccessType.NONE)
45 @XmlType(name = InPredicate.Constants.TYPE_NAME, propOrder = {
46 CriteriaSupportUtils.PropertyConstants.VALUES,
47 CoreConstants.CommonElements.FUTURE_ELEMENTS
48 })
49 public final class InPredicate extends AbstractPredicate implements MultiValuedPredicate {
50
51 private static final long serialVersionUID = -1888858317314153374L;
52
53 @XmlAttribute(name = CriteriaSupportUtils.PropertyConstants.PROPERTY_PATH)
54 private final String propertyPath;
55
56 @XmlElements(value = {
57 @XmlElement(name = CriteriaStringValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaStringValue.class, required = true),
58 @XmlElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaDateTimeValue.class, required = true),
59 @XmlElement(name = CriteriaIntegerValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaIntegerValue.class, required = true),
60 @XmlElement(name = CriteriaKualiDecimalValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaKualiDecimalValue.class, required = true),
61 @XmlElement(name = CriteriaKualiPercentValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaKualiPercentValue.class, required = true),
62 @XmlElement(name = CriteriaKualiIntegerValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaKualiIntegerValue.class, required = true),
63 @XmlElement(name = CriteriaDecimalValue.Constants.ROOT_ELEMENT_NAME, type = CriteriaDecimalValue.class, required = true)
64 })
65 private final Set<? extends CriteriaValue<?>> values;
66
67 @SuppressWarnings("unused")
68 @XmlAnyElement
69 private final Collection<Element> _futureElements = null;
70
71
72
73
74 @SuppressWarnings("unused")
75 private InPredicate() {
76 this.propertyPath = null;
77 this.values = null;
78 }
79
80
81
82
83
84
85
86
87
88
89
90 InPredicate(String propertyPath, Set<? extends CriteriaValue<?>> values) {
91 if (StringUtils.isBlank(propertyPath)) {
92 throw new IllegalArgumentException("Property path cannot be null or blank.");
93 }
94 CriteriaSupportUtils.validateValuesForMultiValuedPredicate(values);
95 this.propertyPath = propertyPath;
96
97 if (values == null) {
98 this.values = Collections.emptySet();
99 } else {
100 final Set<CriteriaValue<?>> temp = new HashSet<CriteriaValue<?>>();
101 for (CriteriaValue<?> value: values) {
102 if (value != null) {
103 temp.add(value);
104 }
105 }
106 this.values = Collections.unmodifiableSet(temp);
107 }
108 }
109
110 @Override
111 public String getPropertyPath() {
112 return propertyPath;
113 }
114
115 @Override
116 public Set<CriteriaValue<?>> getValues() {
117 return Collections.unmodifiableSet(values);
118 }
119
120
121
122
123 static class Constants {
124 final static String ROOT_ELEMENT_NAME = "in";
125 final static String TYPE_NAME = "InType";
126 }
127
128 @Override
129 public String toString() {
130 return CriteriaSupportUtils.toString(this);
131 }
132
133 }