2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.admin;
10 import static java.util.Objects.requireNonNull;
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;
18 final class ShardIdentifier implements Identifier {
19 private static final long serialVersionUID = 1L;
21 private final @NonNull String shardName;
22 private final @NonNull DataStoreType type;
24 ShardIdentifier(final DataStoreType type, final String shardName) {
25 this.type = requireNonNull(type);
26 this.shardName = requireNonNull(shardName);
29 ShardIdentifier(final DatastoreShardId id) {
30 this(id.getDataStoreType(), id.getShardName());
33 public @NonNull String getShardName() {
37 public @NonNull DataStoreType getDataStoreType() {
42 public int hashCode() {
43 return type.hashCode() * 31 + shardName.hashCode();
47 public boolean equals(final Object obj) {
51 if (!(obj instanceof ShardIdentifier)) {
54 final ShardIdentifier other = (ShardIdentifier) obj;
55 return type.equals(other.type) && shardName.equals(other.shardName);
59 public String toString() {
60 return MoreObjects.toStringHelper(this).add("type", type).add("shardName", shardName).toString();