blob: 68d51d4f4a6f2748dacbf2f9ff503d6a5ee0542c [file] [log] [blame]
Brian O'Connoreeaea2c2015-03-05 16:24:34 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.store.ecmap;
17
Ray Milkey9b6b97d2015-04-20 15:59:21 -070018import java.util.Objects;
19
Brian O'Connoreeaea2c2015-03-05 16:24:34 -080020import org.onosproject.store.Timestamp;
21
22import static com.google.common.base.Preconditions.checkNotNull;
23
24/**
25 * Base class for events in an EventuallyConsistentMap.
26 */
27public abstract class AbstractEntry<K, V> implements Comparable<AbstractEntry<K, V>> {
28 private final K key;
29 private final Timestamp timestamp;
30
31 /**
32 * Creates a new put entry.
33 *
34 * @param key key of the entry
35 * @param timestamp timestamp of the put event
36 */
37 public AbstractEntry(K key, Timestamp timestamp) {
38 this.key = checkNotNull(key);
39 this.timestamp = checkNotNull(timestamp);
40 }
41
42 // Needed for serialization.
43 @SuppressWarnings("unused")
44 protected AbstractEntry() {
45 this.key = null;
46 this.timestamp = null;
47 }
48
49 /**
50 * Returns the key of the entry.
51 *
52 * @return the key
53 */
54 public K key() {
55 return key;
56 }
57
58 /**
59 * Returns the timestamp of the event.
60 *
61 * @return the timestamp
62 */
63 public Timestamp timestamp() {
64 return timestamp;
65 }
66
67 @Override
68 public int compareTo(AbstractEntry<K, V> o) {
69 return this.timestamp.compareTo(o.timestamp);
70 }
Ray Milkey9b6b97d2015-04-20 15:59:21 -070071
72 @Override
73 public int hashCode() {
74 return Objects.hash(timestamp);
75 }
76
77 @Override
78 public boolean equals(Object o) {
79 if (this == o) {
80 return true;
81 }
82 if (o instanceof AbstractEntry) {
83 final AbstractEntry that = (AbstractEntry) o;
84 return this.timestamp.equals(that.timestamp);
85 }
86 return false;
87 }
Brian O'Connoreeaea2c2015-03-05 16:24:34 -080088}