Jordan Halterman | 281dbf3 | 2018-06-15 17:46:28 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.store.flow.impl; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import org.onosproject.cluster.NodeId; |
| 21 | |
| 22 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 23 | |
| 24 | /** |
| 25 | * Identifier representing a backup of a distinct bucket to a specific node. |
| 26 | */ |
| 27 | public class BackupOperation { |
| 28 | private final NodeId nodeId; |
| 29 | private final int bucketId; |
| 30 | |
| 31 | BackupOperation(NodeId nodeId, int bucketId) { |
| 32 | this.nodeId = nodeId; |
| 33 | this.bucketId = bucketId; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Returns the node identifier. |
| 38 | * |
| 39 | * @return the node identifier |
| 40 | */ |
| 41 | public NodeId nodeId() { |
| 42 | return nodeId; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the bucket identifier. |
| 47 | * |
| 48 | * @return the bucket identifier |
| 49 | */ |
| 50 | public int bucket() { |
| 51 | return bucketId; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public int hashCode() { |
| 56 | return Objects.hash(nodeId, bucketId); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public boolean equals(Object other) { |
| 61 | if (other != null && other instanceof BackupOperation) { |
| 62 | BackupOperation that = (BackupOperation) other; |
| 63 | return this.nodeId.equals(that.nodeId) |
| 64 | && this.bucketId == that.bucketId; |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public String toString() { |
| 71 | return toStringHelper(this) |
| 72 | .add("nodeId", nodeId()) |
| 73 | .add("bucket", bucket()) |
| 74 | .toString(); |
| 75 | } |
| 76 | } |