blob: ddb4ae90a1e5eab843f844668ba84eeaea4f3973 [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
18import com.google.common.base.MoreObjects;
19import org.onosproject.store.Timestamp;
20
21import static com.google.common.base.Preconditions.checkNotNull;
22
23/**
24 * Describes a single put event in an EventuallyConsistentMap.
25 */
Brian O'Connoreeaea2c2015-03-05 16:24:34 -080026final class PutEntry<K, V> extends AbstractEntry<K, V> {
Jonathan Hartf9108232015-02-02 16:37:35 -080027 private final V value;
Jonathan Hartf9108232015-02-02 16:37:35 -080028
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'Connoreeaea2c2015-03-05 16:24:34 -080037 super(key, timestamp);
Jonathan Hartf9108232015-02-02 16:37:35 -080038 this.value = checkNotNull(value);
Jonathan Hartf9108232015-02-02 16:37:35 -080039 }
40
41 // Needed for serialization.
42 @SuppressWarnings("unused")
43 private PutEntry() {
Brian O'Connoreeaea2c2015-03-05 16:24:34 -080044 super();
Jonathan Hartf9108232015-02-02 16:37:35 -080045 this.value = null;
Jonathan Hartf9108232015-02-02 16:37:35 -080046 }
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 Hartf9108232015-02-02 16:37:35 -080057 @Override
58 public String toString() {
59 return MoreObjects.toStringHelper(getClass())
Brian O'Connoreeaea2c2015-03-05 16:24:34 -080060 .add("key", key())
Jonathan Hartf9108232015-02-02 16:37:35 -080061 .add("value", value)
Brian O'Connoreeaea2c2015-03-05 16:24:34 -080062 .add("timestamp", timestamp())
Jonathan Hartf9108232015-02-02 16:37:35 -080063 .toString();
64 }
65}