blob: 65de9817db742cd5001b1bed35d5db1e972f66e6 [file] [log] [blame]
Madan Jampanif2f086c2016-01-13 16:15:39 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Madan Jampanif2f086c2016-01-13 16:15:39 -08003 *
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 */
16package org.onosproject.event;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20
21/**
22 * Generic representation of an update.
23 *
24 * @param <T> type of value that was updated
25 */
26public class Change<T> {
27
28 private final T oldValue;
29 private final T newValue;
30
31 public Change(T oldValue, T newValue) {
32 this.oldValue = oldValue;
33 this.newValue = newValue;
34 }
35
36 /**
37 * Returns previous value.
38 * @return previous value.
39 */
40 public T oldValue() {
41 return oldValue;
42 }
43
44 /**
45 * Returns new or current value.
46 * @return new value.
47 */
48 public T newValue() {
49 return newValue;
50 }
51
52 @Override
53 public boolean equals(Object other) {
54 if (other == null || !(other instanceof Change)) {
55 return false;
56 }
57 Change<T> that = (Change<T>) other;
58 return Objects.equal(this.oldValue, that.oldValue) &&
59 Objects.equal(this.newValue, that.newValue);
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hashCode(oldValue, newValue);
65 }
66
67 @Override
68 public String toString() {
69 return MoreObjects.toStringHelper(getClass())
70 .add("oldValue", oldValue)
71 .add("newValue", newValue)
72 .toString();
73 }
74}