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.ToStringBuilder; |
19 | |
import org.kuali.rice.core.util.EqualsAndHashCodeUtils; |
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 | |
import java.util.Calendar; |
27 | |
import java.util.Date; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 2 | @XmlRootElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME) |
37 | |
@XmlAccessorType(XmlAccessType.NONE) |
38 | |
@XmlType(name = CriteriaDateTimeValue.Constants.TYPE_NAME) |
39 | |
public final class CriteriaDateTimeValue implements CriteriaValue<Calendar> { |
40 | |
|
41 | |
@XmlValue |
42 | |
private final Calendar value; |
43 | |
|
44 | 17 | CriteriaDateTimeValue() { |
45 | 17 | this.value = null; |
46 | 17 | } |
47 | |
|
48 | 22 | CriteriaDateTimeValue(Calendar value) { |
49 | 22 | validateValue(value); |
50 | |
|
51 | 22 | this.value = (Calendar) value.clone(); |
52 | 22 | } |
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 | 29 | if (value == null) { |
63 | 0 | throw new IllegalArgumentException("Value cannot be null."); |
64 | |
} |
65 | 29 | } |
66 | |
|
67 | |
@Override |
68 | |
public Calendar getValue() { |
69 | |
|
70 | 2 | return (Calendar) value.clone(); |
71 | |
} |
72 | |
|
73 | |
@Override |
74 | |
public int hashCode() { |
75 | 72 | return EqualsAndHashCodeUtils.hashCodeForCalendars(value); |
76 | |
} |
77 | |
|
78 | |
@Override |
79 | |
public boolean equals(Object obj) { |
80 | |
|
81 | 21 | return EqualsAndHashCodeUtils.equalsUsingCompareToOnFields(this, obj, "value"); |
82 | |
} |
83 | |
|
84 | |
@Override |
85 | |
public String toString() { |
86 | 0 | return ToStringBuilder.reflectionToString(this); |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | 0 | static class Constants { |
93 | |
final static String ROOT_ELEMENT_NAME = "dateTimeValue"; |
94 | |
final static String TYPE_NAME = "CriteriaDateTimeValueType"; |
95 | |
} |
96 | |
|
97 | |
} |