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