blob: 5ae8b4f44dd7321beabe7194e426d3fa7d73b978 [file] [log] [blame]
Madan Jampani3e033bd2015-04-08 13:03:49 -07001package org.onosproject.store.impl;
2
3import static com.google.common.base.Preconditions.checkArgument;
4
5import java.util.Objects;
6
7import org.onosproject.store.Timestamp;
8
9import com.google.common.base.MoreObjects;
10import com.google.common.collect.ComparisonChain;
11
12/**
13 * Timestamp based on logical sequence value.
14 * <p>
15 * LogicalTimestamps are ordered by their sequence values.
16 */
17public class LogicalTimestamp implements Timestamp {
18
19 private final long value;
20
21 public LogicalTimestamp(long value) {
22 this.value = value;
23 }
24
25 @Override
26 public int compareTo(Timestamp o) {
27 checkArgument(o instanceof LogicalTimestamp,
28 "Must be LogicalTimestamp", o);
29 LogicalTimestamp that = (LogicalTimestamp) o;
30
31 return ComparisonChain.start()
32 .compare(this.value, that.value)
33 .result();
34 }
35
36 @Override
37 public int hashCode() {
38 return Objects.hash(value);
39 }
40
41 @Override
42 public boolean equals(Object obj) {
43 if (this == obj) {
44 return true;
45 }
46 if (!(obj instanceof LogicalTimestamp)) {
47 return false;
48 }
49 LogicalTimestamp that = (LogicalTimestamp) obj;
50 return Objects.equals(this.value, that.value);
51 }
52
53 @Override
54 public String toString() {
55 return MoreObjects.toStringHelper(getClass())
56 .add("value", value)
57 .toString();
58 }
59
60 /**
61 * Returns the sequence value.
62 *
63 * @return sequence value
64 */
65 public long value() {
66 return this.value;
67 }
68}