Merge "BUG 1839 - HTTP delete of non existing data"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / identifiers / ShardTransactionIdentifier.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 ShardTransactionIdentifier {
14     private final String remoteTransactionId;
15
16     private ShardTransactionIdentifier(String remoteTransactionId) {
17         this.remoteTransactionId = Preconditions.checkNotNull(remoteTransactionId,
18                 "remoteTransactionId should not be null");
19     }
20
21     public static Builder builder(){
22         return new Builder();
23     }
24
25     public String getRemoteTransactionId() {
26         return remoteTransactionId;
27     }
28
29     @Override
30     public boolean equals(Object o) {
31         if (this == o) {
32             return true;
33         }
34         if (o == null || getClass() != o.getClass()) {
35             return false;
36         }
37
38         ShardTransactionIdentifier that = (ShardTransactionIdentifier) o;
39
40         if (!remoteTransactionId.equals(that.remoteTransactionId)) {
41             return false;
42         }
43
44         return true;
45     }
46
47     @Override
48     public int hashCode() {
49         return remoteTransactionId.hashCode();
50     }
51
52     @Override public String toString() {
53         final StringBuilder sb = new StringBuilder();
54         sb.append("shard-").append(remoteTransactionId);
55         return sb.toString();
56     }
57
58     public static class Builder {
59         private String remoteTransactionId;
60
61         public Builder remoteTransactionId(String remoteTransactionId){
62             this.remoteTransactionId = remoteTransactionId;
63             return this;
64         }
65
66         public ShardTransactionIdentifier build(){
67             return new ShardTransactionIdentifier(remoteTransactionId);
68         }
69
70     }
71 }