blob: ff6876f54d62eb651de1885cac552746c0e576a1 [file] [log] [blame]
Jordan Halterman9bdc24f2017-04-19 23:45:12 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jordan Halterman9bdc24f2017-04-19 23:45:12 -07003 *
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.primitives.impl;
17
18import java.util.Collection;
19import java.util.Objects;
20import java.util.concurrent.CompletableFuture;
21import java.util.function.Consumer;
22
23import com.google.common.base.MoreObjects;
24import org.onosproject.core.ApplicationId;
25import org.onosproject.store.service.DistributedPrimitive;
26
27import static com.google.common.base.Preconditions.checkNotNull;
28
29/**
30 * Base class for primitive delegates.
31 */
32public abstract class DelegatingDistributedPrimitive implements DistributedPrimitive {
33 private final DistributedPrimitive primitive;
34
35 public DelegatingDistributedPrimitive(DistributedPrimitive primitive) {
36 this.primitive = checkNotNull(primitive);
37 }
38
39 @Override
40 public String name() {
41 return primitive.name();
42 }
43
44 @Override
45 public Type primitiveType() {
46 return primitive.primitiveType();
47 }
48
49 @Override
50 public ApplicationId applicationId() {
51 return primitive.applicationId();
52 }
53
54 @Override
55 public CompletableFuture<Void> destroy() {
56 return primitive.destroy();
57 }
58
59 @Override
60 public void addStatusChangeListener(Consumer<Status> listener) {
61 primitive.addStatusChangeListener(listener);
62 }
63
64 @Override
65 public void removeStatusChangeListener(Consumer<Status> listener) {
66 primitive.removeStatusChangeListener(listener);
67 }
68
69 @Override
70 public Collection<Consumer<Status>> statusChangeListeners() {
71 return primitive.statusChangeListeners();
72 }
73
74 @Override
75 public String toString() {
76 return MoreObjects.toStringHelper(getClass())
77 .add("delegate", primitive)
78 .toString();
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hash(primitive);
84 }
85
86 @Override
87 public boolean equals(Object other) {
88 return other instanceof DelegatingDistributedPrimitive
89 && primitive.equals(((DelegatingDistributedPrimitive) other).primitive);
90 }
91}