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.util.Calendar; |
19 | |
import java.util.Date; |
20 | |
|
21 | |
import javax.xml.bind.annotation.XmlAccessType; |
22 | |
import javax.xml.bind.annotation.XmlAccessorType; |
23 | |
import javax.xml.bind.annotation.XmlRootElement; |
24 | |
import javax.xml.bind.annotation.XmlType; |
25 | |
import javax.xml.bind.annotation.XmlValue; |
26 | |
|
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 | 2 | @XmlRootElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME) |
38 | |
@XmlAccessorType(XmlAccessType.NONE) |
39 | |
@XmlType(name = CriteriaDateTimeValue.Constants.TYPE_NAME) |
40 | |
public final class CriteriaDateTimeValue implements CriteriaValue<Calendar> { |
41 | |
|
42 | |
@XmlValue |
43 | |
private final Calendar value; |
44 | |
|
45 | 16 | CriteriaDateTimeValue() { |
46 | 16 | this.value = null; |
47 | 16 | } |
48 | |
|
49 | 21 | CriteriaDateTimeValue(Calendar value) { |
50 | 21 | validateValue(value); |
51 | 21 | this.value = value; |
52 | 21 | } |
53 | |
|
54 | 7 | CriteriaDateTimeValue(Date value) { |
55 | 7 | validateValue(value); |
56 | 7 | Calendar calendar = Calendar.getInstance(); |
57 | 7 | calendar.setTimeInMillis(value.getTime()); |
58 | 7 | this.value = calendar; |
59 | 7 | } |
60 | |
|
61 | |
private static void validateValue(Object value) { |
62 | 28 | if (value == null) { |
63 | 0 | throw new IllegalArgumentException("Value cannot be null."); |
64 | |
} |
65 | 28 | } |
66 | |
|
67 | |
@Override |
68 | |
public Calendar getValue() { |
69 | 2 | return value; |
70 | |
} |
71 | |
|
72 | |
@Override |
73 | |
public int hashCode() { |
74 | 0 | return HashCodeBuilder.reflectionHashCode(this); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
@Override |
83 | |
public boolean equals(Object obj) { |
84 | 18 | if (obj instanceof CriteriaDateTimeValue) { |
85 | 18 | return value.getTimeInMillis() == ((CriteriaDateTimeValue)obj).value.getTimeInMillis(); |
86 | |
} |
87 | 0 | return false; |
88 | |
} |
89 | |
|
90 | |
@Override |
91 | |
public String toString() { |
92 | 0 | return ToStringBuilder.reflectionToString(this); |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | 0 | static class Constants { |
99 | |
final static String ROOT_ELEMENT_NAME = "dateTimeValue"; |
100 | |
final static String TYPE_NAME = "CriteriaDateTimeValueType"; |
101 | |
} |
102 | |
|
103 | |
} |