blob: c6279c1ac89470fd2f6b92aea2e2feca6005c8d3 [file] [log] [blame]
Madan Jampani64ff13b2016-09-08 11:18:50 -07001/*
2 * Copyright 2016-present 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 */
16package org.onosproject.store.service;
17
18import java.util.Optional;
19
20import com.google.common.base.MoreObjects;
21
22/**
23 * A document tree modification event.
24 *
25 * @param <V> tree node value type
26 */
27public class DocumentTreeEvent<V> {
28
29 /**
30 * Nature of document tree node change.
31 */
32 public enum Type {
33
34 /**
35 * Signifies node being created.
36 */
37 CREATED,
38
39 /**
40 * Signifies the value of an existing node being updated.
41 */
42 UPDATED,
43
44 /**
45 * Signifies an existing node being deleted.
46 */
47 DELETED
48 }
49
50 private final DocumentPath path;
51 private final Type type;
52 private final Optional<Versioned<V>> newValue;
53 private final Optional<Versioned<V>> oldValue;
54
55 /**
56 * Constructs a new {@code DocumentTreeEvent}.
57 *
58 * @param path path to the node
59 * @param type type of change
60 * @param newValue optional new value; will be empty if node was deleted
61 * @param oldValue optional old value; will be empty if node was created
62 */
63 public DocumentTreeEvent(DocumentPath path,
64 Type type,
65 Optional<Versioned<V>> newValue,
66 Optional<Versioned<V>> oldValue) {
67 this.path = path;
68 this.type = type;
69 this.newValue = newValue;
70 this.oldValue = oldValue;
71 }
72
73 /**
74 * Returns the path to the changed node.
75 *
76 * @return node path
77 */
78 public DocumentPath path() {
79 return path;
80 }
81
82 /**
83 * Returns the change type.
84 * @return change type
85 */
86 public Type type() {
87 return type;
88 }
89
90 /**
91 * Returns the new value.
92 *
93 * @return optional new value; will be empty if node was deleted
94 */
95 public Optional<Versioned<V>> newValue() {
96 return newValue;
97 }
98
99 /**
100 * Returns the old value.
101 *
102 * @return optional old value; will be empty if node was created
103 */
104 public Optional<Versioned<V>> oldValue() {
105 return oldValue;
106 }
107
108 @Override
109 public String toString() {
110 return MoreObjects.toStringHelper(getClass())
111 .add("path", path)
112 .add("type", type)
113 .add("newValue", newValue)
114 .add("oldValue", oldValue)
115 .toString();
116 }
117}