Fixup checkstyle
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / AbstractRoutingTable.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.remote.rpc.registry;
9
10 import static java.util.Objects.requireNonNull;
11
12 import akka.actor.ActorRef;
13 import com.google.common.annotations.VisibleForTesting;
14 import com.google.common.base.MoreObjects;
15 import com.google.common.collect.ImmutableSet;
16 import java.io.Serializable;
17 import java.util.Collection;
18 import java.util.Optional;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.opendaylight.controller.remote.rpc.registry.gossip.BucketData;
21
22 /**
23  * Common class for routing tables.
24  *
25  * @param <T> Table type
26  * @param <I> Item type
27  */
28 public abstract class AbstractRoutingTable<T extends AbstractRoutingTable<T, I>, I> implements BucketData<T>,
29         Serializable {
30     private static final long serialVersionUID = 1L;
31
32     private final @NonNull ActorRef invoker;
33     private final @NonNull ImmutableSet<I> items;
34
35     AbstractRoutingTable(final ActorRef invoker, final Collection<I> items) {
36         this.invoker = requireNonNull(invoker);
37         this.items = ImmutableSet.copyOf(items);
38     }
39
40     @Override
41     public final Optional<ActorRef> getWatchActor() {
42         return Optional.of(invoker);
43     }
44
45     public final @NonNull ImmutableSet<I> getItems() {
46         return items;
47     }
48
49     final @NonNull ActorRef getInvoker() {
50         return invoker;
51     }
52
53     @VisibleForTesting
54     public final boolean contains(final I routeId) {
55         return items.contains(routeId);
56     }
57
58     @VisibleForTesting
59     public final int size() {
60         return items.size();
61     }
62
63     abstract Object writeReplace();
64
65     @Override
66     public final String toString() {
67         return MoreObjects.toStringHelper(this).add("invoker", invoker).add("items", items).toString();
68     }
69 }