Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [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 | */ |
| 16 | package org.onosproject.store.service; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | |
| 22 | /** |
| 23 | * Representation of a AtomicValue update notification. |
| 24 | * |
| 25 | * @param <V> atomic value type |
| 26 | */ |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 27 | public final class AtomicValueEvent<V> { |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * AtomicValueEvent type. |
| 31 | */ |
| 32 | public enum Type { |
| 33 | |
| 34 | /** |
| 35 | * Value was updated. |
| 36 | */ |
| 37 | UPDATE, |
| 38 | } |
| 39 | |
| 40 | private final String name; |
| 41 | private final Type type; |
| 42 | private final V value; |
| 43 | |
| 44 | /** |
| 45 | * Creates a new event object. |
| 46 | * |
| 47 | * @param name AtomicValue name |
| 48 | * @param type the type of the event |
| 49 | * @param value the new value |
| 50 | */ |
| 51 | public AtomicValueEvent(String name, Type type, V value) { |
| 52 | this.name = name; |
| 53 | this.type = type; |
| 54 | this.value = value; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns the AtomicValue name. |
| 59 | * |
| 60 | * @return name of atomic value |
| 61 | */ |
| 62 | public String name() { |
| 63 | return name; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns the type of the event. |
| 68 | * |
| 69 | * @return the type of the event |
| 70 | */ |
| 71 | public Type type() { |
| 72 | return type; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Returns the new updated value. |
| 77 | * |
| 78 | * @return the value |
| 79 | */ |
| 80 | public V value() { |
| 81 | return value; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object o) { |
| 86 | if (!(o instanceof AtomicValueEvent)) { |
| 87 | return false; |
| 88 | } |
| 89 | |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 90 | AtomicValueEvent that = (AtomicValueEvent) o; |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 91 | return Objects.equals(this.name, that.name) && |
| 92 | Objects.equals(this.type, that.type) && |
| 93 | Objects.equals(this.value, that.value); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public int hashCode() { |
| 98 | return Objects.hash(name, type, value); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public String toString() { |
| 103 | return MoreObjects.toStringHelper(getClass()) |
| 104 | .add("name", name) |
| 105 | .add("type", type) |
| 106 | .add("value", value) |
| 107 | .toString(); |
| 108 | } |
Ray Milkey | 67d53cc | 2015-07-23 16:32:36 -0700 | [diff] [blame] | 109 | } |