blob: 41eb3a23c173bef5f586019d938ea4473682dbd3 [file] [log] [blame]
Jonathan Hartf9108232015-02-02 16:37:35 -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 */
Jonathan Hart77bdd262015-02-03 09:07:48 -080016package org.onosproject.store.ecmap;
Jonathan Hartf9108232015-02-02 16:37:35 -080017
Jonathan Hartf9108232015-02-02 16:37:35 -080018import static com.google.common.base.Preconditions.checkNotNull;
19
Madan Jampani3d76c942015-06-29 23:37:10 -070020import com.google.common.base.MoreObjects;
21
Jonathan Hartf9108232015-02-02 16:37:35 -080022/**
Madan Jampani3d76c942015-06-29 23:37:10 -070023 * Describes a single update event in an EventuallyConsistentMap.
Jonathan Hartf9108232015-02-02 16:37:35 -080024 */
Madan Jampani3d76c942015-06-29 23:37:10 -070025final class UpdateEntry<K, V> implements Comparable<UpdateEntry<K, V>> {
26 private final K key;
27 private final MapValue<V> value;
Jonathan Hartf9108232015-02-02 16:37:35 -080028
29 /**
Madan Jampani3d76c942015-06-29 23:37:10 -070030 * Creates a new update entry.
Jonathan Hartf9108232015-02-02 16:37:35 -080031 *
32 * @param key key of the entry
33 * @param value value of the entry
Jonathan Hartf9108232015-02-02 16:37:35 -080034 */
Madan Jampani3d76c942015-06-29 23:37:10 -070035 public UpdateEntry(K key, MapValue<V> value) {
36 this.key = checkNotNull(key);
Jonathan Hartf9108232015-02-02 16:37:35 -080037 this.value = checkNotNull(value);
Jonathan Hartf9108232015-02-02 16:37:35 -080038 }
39
Madan Jampani3d76c942015-06-29 23:37:10 -070040 /**
41 * Returns the key.
42 *
43 * @return the key
44 */
45 public K key() {
46 return key;
Jonathan Hartf9108232015-02-02 16:37:35 -080047 }
48
49 /**
50 * Returns the value of the entry.
51 *
52 * @return the value
53 */
Madan Jampani3d76c942015-06-29 23:37:10 -070054 public MapValue<V> value() {
Jonathan Hartf9108232015-02-02 16:37:35 -080055 return value;
56 }
57
Jonathan Hartf9108232015-02-02 16:37:35 -080058 @Override
Madan Jampani3d76c942015-06-29 23:37:10 -070059 public int compareTo(UpdateEntry<K, V> o) {
60 return this.value.timestamp().compareTo(o.value.timestamp());
61 }
62
63 @Override
Jonathan Hartf9108232015-02-02 16:37:35 -080064 public String toString() {
65 return MoreObjects.toStringHelper(getClass())
Brian O'Connoreeaea2c2015-03-05 16:24:34 -080066 .add("key", key())
Jonathan Hartf9108232015-02-02 16:37:35 -080067 .add("value", value)
Jonathan Hartf9108232015-02-02 16:37:35 -080068 .toString();
69 }
Madan Jampani3d76c942015-06-29 23:37:10 -070070
71 @SuppressWarnings("unused")
72 private UpdateEntry() {
73 this.key = null;
74 this.value = null;
75 }
Jonathan Hartf9108232015-02-02 16:37:35 -080076}