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.joda.time.DateTime; |
22 | |
import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter; |
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 javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
30 | |
import java.util.Calendar; |
31 | |
import java.util.Date; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 2 | @XmlRootElement(name = CriteriaDateTimeValue.Constants.ROOT_ELEMENT_NAME) |
40 | |
@XmlAccessorType(XmlAccessType.NONE) |
41 | |
@XmlType(name = CriteriaDateTimeValue.Constants.TYPE_NAME) |
42 | |
public final class CriteriaDateTimeValue implements CriteriaValue<DateTime> { |
43 | |
|
44 | |
@XmlValue |
45 | |
@XmlJavaTypeAdapter(DateTimeAdapter.class) |
46 | |
private final DateTime value; |
47 | |
|
48 | 17 | CriteriaDateTimeValue() { |
49 | 17 | this.value = null; |
50 | 17 | } |
51 | |
|
52 | 2 | CriteriaDateTimeValue(DateTime value) { |
53 | 2 | validateValue(value); |
54 | 2 | this.value = value; |
55 | 2 | } |
56 | |
|
57 | 20 | CriteriaDateTimeValue(Calendar value) { |
58 | 20 | validateValue(value); |
59 | 20 | this.value = new DateTime(value.getTimeInMillis()); |
60 | 20 | } |
61 | |
|
62 | 7 | CriteriaDateTimeValue(Date value) { |
63 | 7 | validateValue(value); |
64 | 7 | this.value = new DateTime(value.getTime()); |
65 | 7 | } |
66 | |
|
67 | |
private static void validateValue(Object value) { |
68 | 29 | if (value == null) { |
69 | 0 | throw new IllegalArgumentException("Value cannot be null."); |
70 | |
} |
71 | 29 | } |
72 | |
|
73 | |
@Override |
74 | |
public DateTime getValue() { |
75 | |
|
76 | 2 | return value; |
77 | |
} |
78 | |
|
79 | |
@Override |
80 | |
public int hashCode() { |
81 | 51 | return HashCodeBuilder.reflectionHashCode(this); |
82 | |
} |
83 | |
|
84 | |
@Override |
85 | |
public boolean equals(Object obj) { |
86 | 20 | return EqualsBuilder.reflectionEquals(obj, this); |
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public String toString() { |
91 | 0 | return ToStringBuilder.reflectionToString(this); |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | 0 | static class Constants { |
98 | |
final static String ROOT_ELEMENT_NAME = "dateTimeValue"; |
99 | |
final static String TYPE_NAME = "CriteriaDateTimeValueType"; |
100 | |
} |
101 | |
|
102 | |
} |