Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 1 | /* |
Thomas Vachuska | b6d3167 | 2018-07-27 17:03:46 -0700 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 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 | */ |
Thomas Vachuska | b6d3167 | 2018-07-27 17:03:46 -0700 | [diff] [blame] | 16 | package org.onosproject.store.atomix.primitives.impl; |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 17 | |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
| 19 | |
Jordan Halterman | 00e92da | 2018-05-22 23:05:52 -0700 | [diff] [blame] | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 21 | |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 22 | /** |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 23 | * Describes a single update event in an EventuallyConsistentMap. |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 24 | */ |
Madan Jampani | 92c64eb | 2015-07-23 15:37:07 -0700 | [diff] [blame] | 25 | final class UpdateEntry<K, V> { |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 26 | private final K key; |
| 27 | private final MapValue<V> value; |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 30 | * Creates a new update entry. |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 31 | * |
| 32 | * @param key key of the entry |
| 33 | * @param value value of the entry |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 34 | */ |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 35 | public UpdateEntry(K key, MapValue<V> value) { |
| 36 | this.key = checkNotNull(key); |
Madan Jampani | 483d0a2 | 2015-08-19 17:33:00 -0700 | [diff] [blame] | 37 | this.value = value; |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Returns the key. |
| 42 | * |
| 43 | * @return the key |
| 44 | */ |
| 45 | public K key() { |
| 46 | return key; |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns the value of the entry. |
| 51 | * |
| 52 | * @return the value |
| 53 | */ |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 54 | public MapValue<V> value() { |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 55 | return value; |
| 56 | } |
| 57 | |
Madan Jampani | 92c64eb | 2015-07-23 15:37:07 -0700 | [diff] [blame] | 58 | /** |
| 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 Jampani | 3c48de0 | 2015-08-26 13:28:15 -0700 | [diff] [blame] | 64 | return other == null || other.value == null || (value != null && value.isNewerThan(other.value)); |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 68 | public String toString() { |
| 69 | return MoreObjects.toStringHelper(getClass()) |
Brian O'Connor | eeaea2c | 2015-03-05 16:24:34 -0800 | [diff] [blame] | 70 | .add("key", key()) |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 71 | .add("value", value) |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 72 | .toString(); |
| 73 | } |
Madan Jampani | 3d76c94 | 2015-06-29 23:37:10 -0700 | [diff] [blame] | 74 | |
| 75 | @SuppressWarnings("unused") |
| 76 | private UpdateEntry() { |
| 77 | this.key = null; |
| 78 | this.value = null; |
| 79 | } |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 80 | } |