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