blob: 680795c951ba8e227b20e301e0ab099e06feacee [file] [log] [blame]
Jonathan Hartf9108232015-02-02 16:37:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hartf9108232015-02-02 16:37:35 -08003 *
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 */
Madan Jampanif4c88502016-01-21 12:35:36 -080016package org.onosproject.store.primitives.impl;
Jonathan Hartf9108232015-02-02 16:37:35 -080017
Madan Jampani3d76c942015-06-29 23:37:10 -070018import com.google.common.base.MoreObjects;
19
Jordan Halterman00e92da2018-05-22 23:05:52 -070020import static com.google.common.base.Preconditions.checkNotNull;
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 Jampani92c64eb2015-07-23 15:37:07 -070025final class UpdateEntry<K, V> {
Madan Jampani3d76c942015-06-29 23:37:10 -070026 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);
Madan Jampani483d0a22015-08-19 17:33:00 -070037 this.value = 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
Madan Jampani92c64eb2015-07-23 15:37:07 -070058 /**
59 * Returns if this entry is newer than other entry.
60 * @param other other entry
61 * @return true if this entry is newer; false otherwise
62 */
63 public boolean isNewerThan(UpdateEntry<K, V> other) {
Madan Jampani3c48de02015-08-26 13:28:15 -070064 return other == null || other.value == null || (value != null && value.isNewerThan(other.value));
Madan Jampani3d76c942015-06-29 23:37:10 -070065 }
66
67 @Override
Jonathan Hartf9108232015-02-02 16:37:35 -080068 public String toString() {
69 return MoreObjects.toStringHelper(getClass())
Brian O'Connoreeaea2c2015-03-05 16:24:34 -080070 .add("key", key())
Jonathan Hartf9108232015-02-02 16:37:35 -080071 .add("value", value)
Jonathan Hartf9108232015-02-02 16:37:35 -080072 .toString();
73 }
Madan Jampani3d76c942015-06-29 23:37:10 -070074
75 @SuppressWarnings("unused")
76 private UpdateEntry() {
77 this.key = null;
78 this.value = null;
79 }
Jonathan Hartf9108232015-02-02 16:37:35 -080080}