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 | |
|
22 | |
import javax.xml.bind.annotation.XmlAccessType; |
23 | |
import javax.xml.bind.annotation.XmlAccessorType; |
24 | |
import javax.xml.bind.annotation.XmlRootElement; |
25 | |
import javax.xml.bind.annotation.XmlType; |
26 | |
import javax.xml.bind.annotation.XmlValue; |
27 | |
import java.math.BigDecimal; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 3 | @XmlRootElement(name = CriteriaDecimalValue.Constants.ROOT_ELEMENT_NAME) |
37 | |
@XmlAccessorType(XmlAccessType.NONE) |
38 | |
@XmlType(name = CriteriaDecimalValue.Constants.TYPE_NAME) |
39 | |
public final class CriteriaDecimalValue implements CriteriaValue<BigDecimal> { |
40 | |
|
41 | |
@XmlValue |
42 | |
private final BigDecimal value; |
43 | |
|
44 | 26 | CriteriaDecimalValue() { |
45 | 26 | this.value = null; |
46 | 26 | } |
47 | |
|
48 | 46 | CriteriaDecimalValue(BigDecimal value) { |
49 | 46 | validateValue(value); |
50 | 46 | this.value = safeInstance(value); |
51 | 46 | } |
52 | |
|
53 | 0 | CriteriaDecimalValue(Number value) { |
54 | 0 | validateValue(value); |
55 | 0 | this.value = BigDecimal.valueOf(value.doubleValue()); |
56 | 0 | } |
57 | |
|
58 | |
private static void validateValue(Object value) { |
59 | 46 | if (value == null) { |
60 | 0 | throw new IllegalArgumentException("Value cannot be null."); |
61 | |
} |
62 | 46 | } |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
private static BigDecimal safeInstance(BigDecimal val) { |
73 | 46 | if (val.getClass() != BigDecimal.class) { |
74 | 0 | return new BigDecimal(val.toPlainString()); |
75 | |
} |
76 | 46 | return val; |
77 | |
} |
78 | |
|
79 | |
@Override |
80 | |
public BigDecimal getValue() { |
81 | 3 | return value; |
82 | |
} |
83 | |
|
84 | |
@Override |
85 | |
public int hashCode() { |
86 | 109 | return HashCodeBuilder.reflectionHashCode(this); |
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public boolean equals(Object obj) { |
91 | 26 | return EqualsBuilder.reflectionEquals(obj, this); |
92 | |
} |
93 | |
|
94 | |
@Override |
95 | |
public String toString() { |
96 | 0 | return ToStringBuilder.reflectionToString(this); |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | 0 | static class Constants { |
103 | |
final static String ROOT_ELEMENT_NAME = "decimalValue"; |
104 | |
final static String TYPE_NAME = "CriteriaDecimalValueType"; |
105 | |
} |
106 | |
|
107 | |
} |