Merge "Bug #1532 Neutron Port bindings missing Security Group List"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / identifiers / ShardIdentifier.java
1 /*
2  * Copyright (c) 2014 Cisco 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
9 package org.opendaylight.controller.cluster.datastore.identifiers;
10
11 import com.google.common.base.Preconditions;
12
13 public class ShardIdentifier {
14     private final String shardName;
15     private final String memberName;
16     private final String type;
17
18
19     public ShardIdentifier(String shardName, String memberName, String type) {
20
21         Preconditions.checkNotNull(shardName, "shardName should not be null");
22         Preconditions.checkNotNull(memberName, "memberName should not be null");
23         Preconditions.checkNotNull(type, "type should not be null");
24
25         this.shardName = shardName;
26         this.memberName = memberName;
27         this.type = type;
28     }
29
30     @Override
31     public boolean equals(Object o) {
32         if (this == o) {
33             return true;
34         }
35         if (o == null || getClass() != o.getClass()) {
36             return false;
37         }
38
39         ShardIdentifier that = (ShardIdentifier) o;
40
41         if (!memberName.equals(that.memberName)) {
42             return false;
43         }
44         if (!shardName.equals(that.shardName)) {
45             return false;
46         }
47         if (!type.equals(that.type)) {
48             return false;
49         }
50
51         return true;
52     }
53
54     @Override
55     public int hashCode() {
56         int result = shardName.hashCode();
57         result = 31 * result + memberName.hashCode();
58         result = 31 * result + type.hashCode();
59         return result;
60     }
61
62     @Override public String toString() {
63         StringBuilder builder = new StringBuilder();
64         builder.append(memberName).append("-shard-").append(shardName).append("-").append(type);
65         return builder.toString();
66     }
67
68     public static Builder builder(){
69         return new Builder();
70     }
71
72     public static class Builder {
73         private String shardName;
74         private String memberName;
75         private String type;
76
77         public ShardIdentifier build(){
78             return new ShardIdentifier(shardName, memberName, type);
79         }
80
81         public Builder shardName(String shardName){
82             this.shardName = shardName;
83             return this;
84         }
85
86         public Builder memberName(String memberName){
87             this.memberName = memberName;
88             return this;
89         }
90
91         public Builder type(String type){
92             this.type = type;
93             return this;
94         }
95
96     }
97 }