Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 1 | /* |
| 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 Hart | 77bdd26 | 2015-02-03 09:07:48 -0800 | [diff] [blame^] | 16 | package org.onosproject.store.ecmap; |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onosproject.store.Timestamp; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | /** |
| 24 | * Describes a single put event in an EventuallyConsistentMap. |
| 25 | */ |
| 26 | final class PutEntry<K, V> { |
| 27 | private final K key; |
| 28 | private final V value; |
| 29 | private final Timestamp timestamp; |
| 30 | |
| 31 | /** |
| 32 | * Creates a new put entry. |
| 33 | * |
| 34 | * @param key key of the entry |
| 35 | * @param value value of the entry |
| 36 | * @param timestamp timestamp of the put event |
| 37 | */ |
| 38 | public PutEntry(K key, V value, Timestamp timestamp) { |
| 39 | this.key = checkNotNull(key); |
| 40 | this.value = checkNotNull(value); |
| 41 | this.timestamp = checkNotNull(timestamp); |
| 42 | } |
| 43 | |
| 44 | // Needed for serialization. |
| 45 | @SuppressWarnings("unused") |
| 46 | private PutEntry() { |
| 47 | this.key = null; |
| 48 | this.value = null; |
| 49 | this.timestamp = null; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Returns the key of the entry. |
| 54 | * |
| 55 | * @return the key |
| 56 | */ |
| 57 | public K key() { |
| 58 | return key; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the value of the entry. |
| 63 | * |
| 64 | * @return the value |
| 65 | */ |
| 66 | public V value() { |
| 67 | return value; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns the timestamp of the event. |
| 72 | * |
| 73 | * @return the timestamp |
| 74 | */ |
| 75 | public Timestamp timestamp() { |
| 76 | return timestamp; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public String toString() { |
| 81 | return MoreObjects.toStringHelper(getClass()) |
| 82 | .add("key", key) |
| 83 | .add("value", value) |
| 84 | .add("timestamp", timestamp) |
| 85 | .toString(); |
| 86 | } |
| 87 | } |