Skip to content

Commit 32b674d

Browse files
author
jmhofer
committed
Added value class wrapping timestamped values
1 parent ff92254 commit 32b674d

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package rx.util;
2+
3+
/**
4+
* Composite class that takes a value and a timestamp and wraps them.
5+
*/
6+
public final class Timestamped<T> {
7+
private final long timestampMillis;
8+
private final T value;
9+
10+
public Timestamped(long timestampMillis, T value) {
11+
this.value = value;
12+
this.timestampMillis = timestampMillis;
13+
}
14+
15+
public long getTimestampMillis() {
16+
return timestampMillis;
17+
}
18+
19+
public T getValue() {
20+
return value;
21+
}
22+
23+
@Override
24+
public boolean equals(Object obj) {
25+
if (this == obj) {
26+
return true;
27+
}
28+
if (obj == null) {
29+
return false;
30+
}
31+
if (!(obj instanceof Timestamped)) {
32+
return false;
33+
}
34+
Timestamped<?> other = (Timestamped<?>) obj;
35+
if (timestampMillis != other.timestampMillis) {
36+
return false;
37+
}
38+
if (value == null) {
39+
if (other.value != null) {
40+
return false;
41+
}
42+
} else if (!value.equals(other.value)) {
43+
return false;
44+
}
45+
return true;
46+
}
47+
48+
@Override
49+
public int hashCode() {
50+
final int prime = 31;
51+
int result = 1;
52+
result = prime * result + (int) (timestampMillis ^ (timestampMillis));
53+
result = prime * result + ((value == null) ? 0 : value.hashCode());
54+
return result;
55+
}
56+
}

0 commit comments

Comments
 (0)