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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 import org.apache.commons.lang.builder.EqualsBuilder;
38 import org.apache.commons.lang.builder.HashCodeBuilder;
39 import org.apache.commons.lang.builder.ToStringBuilder;
40 import org.kuali.rice.core.api.util.type.KualiDecimal;
41 import org.kuali.rice.core.api.util.type.KualiPercent;
42
43 import javax.xml.bind.annotation.XmlAccessType;
44 import javax.xml.bind.annotation.XmlAccessorType;
45 import javax.xml.bind.annotation.XmlRootElement;
46 import javax.xml.bind.annotation.XmlType;
47 import javax.xml.bind.annotation.XmlValue;
48 import java.math.BigDecimal;
49
50
51
52
53
54
55
56
57
58 @XmlRootElement(name = CriteriaKualiPercentValue.Constants.ROOT_ELEMENT_NAME)
59 @XmlAccessorType(XmlAccessType.NONE)
60 @XmlType(name = CriteriaKualiPercentValue.Constants.TYPE_NAME)
61 public final class CriteriaKualiPercentValue implements CriteriaValue<KualiPercent> {
62
63 @XmlValue
64 private final BigDecimal value;
65
66 CriteriaKualiPercentValue() {
67 this.value = null;
68 }
69
70 CriteriaKualiPercentValue(KualiPercent value) {
71 validateValue(value);
72 this.value = safeInstance(value.bigDecimalValue());
73 }
74
75 CriteriaKualiPercentValue(double value) {
76 validateValue(value);
77 this.value = new KualiPercent(value).bigDecimalValue();
78 }
79
80 CriteriaKualiPercentValue(int value) {
81 validateValue(value);
82 this.value = new KualiPercent(value).bigDecimalValue();
83 }
84
85
86 CriteriaKualiPercentValue(String value) {
87 validateValue(value);
88 this.value = new KualiPercent(value).bigDecimalValue();
89 }
90
91
92 CriteriaKualiPercentValue(BigDecimal value) {
93 validateValue(value);
94 this.value = new KualiPercent(value).bigDecimalValue();
95 }
96
97
98 private static void validateValue(Object value) {
99 if (value == null) {
100 throw new IllegalArgumentException("Value cannot be null.");
101 }
102 }
103
104
105
106
107
108
109
110
111
112 private static BigDecimal safeInstance(BigDecimal val) {
113 return new BigDecimal(val.toPlainString());
114 }
115
116 @Override
117 public KualiPercent getValue() {
118 return new KualiPercent(this.value);
119 }
120
121 @Override
122 public int hashCode() {
123 return HashCodeBuilder.reflectionHashCode(this);
124 }
125
126 @Override
127 public boolean equals(Object obj) {
128 return EqualsBuilder.reflectionEquals(obj, this);
129 }
130
131 @Override
132 public String toString() {
133 return ToStringBuilder.reflectionToString(this);
134 }
135
136
137
138
139 static class Constants {
140 final static String ROOT_ELEMENT_NAME = "kualiPercentValue";
141 final static String TYPE_NAME = "CriteriaKualiPercentValueType";
142 }
143
144 }
145