1
|
package eu.dnetlib.clients.index.model.impl;
|
2
|
|
3
|
import java.io.Serializable;
|
4
|
import java.util.Date;
|
5
|
|
6
|
/**
|
7
|
* Pair of a Date and optionally the original string from which it was parsed. Used to ensure that Date or Timestamp
|
8
|
* Values parsed from JSON or BON string values are reproduced in exactly the same form when converted to a string
|
9
|
* again.
|
10
|
*/
|
11
|
public final class DateValue implements Serializable {
|
12
|
|
13
|
/**
|
14
|
* serializable.
|
15
|
*/
|
16
|
private static final long serialVersionUID = 1L;
|
17
|
|
18
|
/**
|
19
|
* the actual date or timestamp value.
|
20
|
*/
|
21
|
private final Date _date;
|
22
|
|
23
|
/**
|
24
|
* the original string, if the date/timestamp value is parsed from a string and not created immediately in Java.
|
25
|
*/
|
26
|
private final String _originalString;
|
27
|
|
28
|
/**
|
29
|
* create immediately from a java date.
|
30
|
*/
|
31
|
DateValue(final Date date) {
|
32
|
this(date, null);
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* create a pair of a date and the string it was parsed from.
|
37
|
*/
|
38
|
public DateValue(final Date date, final String originalString) {
|
39
|
super();
|
40
|
_date = date;
|
41
|
_originalString = originalString;
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* @return the date.
|
46
|
*/
|
47
|
public Date getDate() {
|
48
|
return _date;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* @return {@link Date#getTime()} of the contained date.
|
53
|
*/
|
54
|
public long getTime() {
|
55
|
return _date.getTime();
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* @return the original string, if the date was parsed.
|
60
|
*/
|
61
|
public String getOriginalString() {
|
62
|
return _originalString;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* @return true if an original string is stored.
|
67
|
*/
|
68
|
public boolean hasOriginalString() {
|
69
|
return _originalString != null;
|
70
|
}
|
71
|
|
72
|
/**
|
73
|
* @return true if the other object is a {@link DateValue}, too, and contains an equals date object. The original
|
74
|
* string is not relevant for the comparison.
|
75
|
*/
|
76
|
@Override
|
77
|
public boolean equals(final Object obj) {
|
78
|
if (obj != null && obj instanceof DateValue) {
|
79
|
return _date.equals(((DateValue) obj)._date);
|
80
|
}
|
81
|
return false;
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* @return hashCode of the contained date object.
|
86
|
*/
|
87
|
@Override
|
88
|
public int hashCode() {
|
89
|
return _date.hashCode();
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* @return toString of contained date object.
|
94
|
*/
|
95
|
@Override
|
96
|
public String toString() {
|
97
|
return _date.toString();
|
98
|
}
|
99
|
|
100
|
}
|