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 | */ |
Brian O'Connor | eeaea2c | 2015-03-05 16:24:34 -0800 | [diff] [blame] | 26 | final class PutEntry<K, V> extends AbstractEntry<K, V> { |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 27 | private final V value; |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Creates a new put entry. |
| 31 | * |
| 32 | * @param key key of the entry |
| 33 | * @param value value of the entry |
| 34 | * @param timestamp timestamp of the put event |
| 35 | */ |
| 36 | public PutEntry(K key, V value, Timestamp timestamp) { |
Brian O'Connor | eeaea2c | 2015-03-05 16:24:34 -0800 | [diff] [blame] | 37 | super(key, timestamp); |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 38 | this.value = checkNotNull(value); |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | // Needed for serialization. |
| 42 | @SuppressWarnings("unused") |
| 43 | private PutEntry() { |
Brian O'Connor | eeaea2c | 2015-03-05 16:24:34 -0800 | [diff] [blame] | 44 | super(); |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 45 | this.value = null; |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns the value of the entry. |
| 50 | * |
| 51 | * @return the value |
| 52 | */ |
| 53 | public V value() { |
| 54 | return value; |
| 55 | } |
| 56 | |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 57 | @Override |
| 58 | public String toString() { |
| 59 | return MoreObjects.toStringHelper(getClass()) |
Brian O'Connor | eeaea2c | 2015-03-05 16:24:34 -0800 | [diff] [blame] | 60 | .add("key", key()) |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 61 | .add("value", value) |
Brian O'Connor | eeaea2c | 2015-03-05 16:24:34 -0800 | [diff] [blame] | 62 | .add("timestamp", timestamp()) |
Jonathan Hart | f910823 | 2015-02-02 16:37:35 -0800 | [diff] [blame] | 63 | .toString(); |
| 64 | } |
| 65 | } |