Add the ability to report known connected clients
[controller.git] / opendaylight / md-sal / sal-cluster-admin-impl / src / main / java / org / opendaylight / controller / cluster / datastore / admin / ShardIdentifier.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. 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.cluster.datastore.admin;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DataStoreType;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.DatastoreShardId;
16 import org.opendaylight.yangtools.concepts.Identifier;
17
18 final class ShardIdentifier implements Identifier {
19     private static final long serialVersionUID = 1L;
20
21     private final @NonNull String shardName;
22     private final @NonNull DataStoreType type;
23
24     ShardIdentifier(final DataStoreType type, final String shardName) {
25         this.type = requireNonNull(type);
26         this.shardName = requireNonNull(shardName);
27     }
28
29     ShardIdentifier(final DatastoreShardId id) {
30         this(id.getDataStoreType(), id.getShardName());
31     }
32
33     public @NonNull String getShardName() {
34         return shardName;
35     }
36
37     public @NonNull DataStoreType getDataStoreType() {
38         return type;
39     }
40
41     @Override
42     public int hashCode() {
43         return type.hashCode() * 31 + shardName.hashCode();
44     }
45
46     @Override
47     public boolean equals(final Object obj) {
48         if (this == obj) {
49             return true;
50         }
51         if (!(obj instanceof ShardIdentifier)) {
52             return false;
53         }
54         final ShardIdentifier other = (ShardIdentifier) obj;
55         return type.equals(other.type) && shardName.equals(other.shardName);
56     }
57
58     @Override
59     public String toString() {
60         return MoreObjects.toStringHelper(this).add("type", type).add("shardName", shardName).toString();
61     }
62 }