2 * Copyright 2017-present Open Networking Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package io.atomix.utils.time;
18 import com.google.common.collect.ComparisonChain;
19 import io.atomix.utils.Identifier;
21 import java.util.Objects;
23 import static com.google.common.base.MoreObjects.toStringHelper;
24 import static com.google.common.base.Preconditions.checkArgument;
27 * Vector clock timestamp.
29 public class VectorTimestamp<T extends Identifier> extends LogicalTimestamp {
30 private final T identifier;
32 public VectorTimestamp(T identifier, long value) {
34 this.identifier = identifier;
38 * Returns the timestamp identifier.
40 * @return the timestamp identifier
42 public T identifier() {
47 public int compareTo(Timestamp o) {
48 checkArgument(o instanceof VectorTimestamp, "Must be VectorTimestamp", o);
49 VectorTimestamp that = (VectorTimestamp) o;
51 return ComparisonChain.start()
52 .compare(this.identifier.id(), that.identifier.id())
53 .compare(this.value(), that.value())
58 public int hashCode() {
59 return Objects.hash(identifier(), value());
63 public boolean equals(Object obj) {
67 if (!(obj instanceof VectorTimestamp)) {
70 VectorTimestamp that = (VectorTimestamp) obj;
71 return Objects.equals(this.identifier, that.identifier)
72 && Objects.equals(this.value(), that.value());
76 public String toString() {
77 return toStringHelper(this)
78 .add("identifier", identifier())
79 .add("value", value())