blob: 4a87b4136780ddb5bad979878526917f5c66c8ce [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
18import org.onosproject.store.Timestamp;
19
20import static com.google.common.base.Preconditions.checkNotNull;
21
22/**
23 * Base class for events in an EventuallyConsistentMap.
24 */
25public abstract class AbstractEntry<K, V> implements Comparable<AbstractEntry<K, V>> {
26 private final K key;
27 private final Timestamp timestamp;
28
29 /**
30 * Creates a new put entry.
31 *
32 * @param key key of the entry
33 * @param timestamp timestamp of the put event
34 */
35 public AbstractEntry(K key, Timestamp timestamp) {
36 this.key = checkNotNull(key);
37 this.timestamp = checkNotNull(timestamp);
38 }
39
40 // Needed for serialization.
41 @SuppressWarnings("unused")
42 protected AbstractEntry() {
43 this.key = null;
44 this.timestamp = null;
45 }
46
47 /**
48 * Returns the key of the entry.
49 *
50 * @return the key
51 */
52 public K key() {
53 return key;
54 }
55
56 /**
57 * Returns the timestamp of the event.
58 *
59 * @return the timestamp
60 */
61 public Timestamp timestamp() {
62 return timestamp;
63 }
64
65 @Override
66 public int compareTo(AbstractEntry<K, V> o) {
67 return this.timestamp.compareTo(o.timestamp);
68 }
69}