Import atomix/{storage,utils}
[controller.git] / third-party / atomix / utils / src / main / java / io / atomix / utils / time / Timestamp.java
1 /*
2  * Copyright 2014-present Open Networking Foundation
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package io.atomix.utils.time;
17
18 import com.google.common.base.Preconditions;
19
20 /**
21  * Opaque version structure.
22  * <p>
23  * Classes implementing this interface must also implement
24  * {@link #hashCode()} and {@link #equals(Object)}.
25  */
26 public interface Timestamp extends Comparable<Timestamp> {
27
28   @Override
29   int hashCode();
30
31   @Override
32   boolean equals(Object obj);
33
34   /**
35    * Tests if this timestamp is newer than the specified timestamp.
36    *
37    * @param other timestamp to compare against
38    * @return true if this instance is newer
39    */
40   default boolean isNewerThan(Timestamp other) {
41     return this.compareTo(Preconditions.checkNotNull(other)) > 0;
42   }
43
44   /**
45    * Tests if this timestamp is older than the specified timestamp.
46    *
47    * @param other timestamp to compare against
48    * @return true if this instance is older
49    */
50   default boolean isOlderThan(Timestamp other) {
51     return this.compareTo(Preconditions.checkNotNull(other)) < 0;
52   }
53 }