blob: cd2b1024aec611e6ae8c3cf3c80a48ff4935113a [file] [log] [blame]
Jonathan Hart74c83132015-02-02 18:37:57 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.store.intent.impl;
17
18import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
22/**
23 * Identifies a partition of the intent keyspace which will be assigned to and
24 * processed by a single ONOS instance at a time.
25 */
Sho SHIMIZU26cc1802016-01-15 12:40:43 -080026final class PartitionId {
Jonathan Hartf2fda812015-02-17 15:21:03 -080027 private final int id;
Jonathan Hart74c83132015-02-02 18:37:57 -080028
29 /**
30 * Creates a new partition ID.
31 *
32 * @param id the partition ID
33 */
Jonathan Hartf2fda812015-02-17 15:21:03 -080034 PartitionId(int id) {
Jonathan Hart74c83132015-02-02 18:37:57 -080035 this.id = id;
36 }
37
Jonathan Hartf2fda812015-02-17 15:21:03 -080038 /**
39 * Returns the integer ID value.
40 *
41 * @return ID value
42 */
Sho SHIMIZU26cc1802016-01-15 12:40:43 -080043 int value() {
Jonathan Hartf2fda812015-02-17 15:21:03 -080044 return id;
45 }
46
Jonathan Hart74c83132015-02-02 18:37:57 -080047 @Override
48 public boolean equals(Object o) {
49 if (!(o instanceof PartitionId)) {
50 return false;
51 }
52
53 PartitionId that = (PartitionId) o;
54 return Objects.equals(this.id, that.id);
55 }
56
57 @Override
58 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070059 return id;
Jonathan Hart74c83132015-02-02 18:37:57 -080060 }
61
62 @Override
63 public String toString() {
64 return MoreObjects.toStringHelper(getClass())
65 .add("partition ID", id)
66 .toString();
67 }
68}