blob: 33cc30417daf03d7805cb9371db8ab423c2ba185 [file] [log] [blame]
Jordan Halterman281dbf32018-06-15 17:46:28 -07001/*
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 */
16package org.onosproject.store.flow.impl;
17
18import java.util.Objects;
19
20import org.onosproject.net.DeviceId;
21
22/**
23 * Represents a distinct device flow bucket.
24 */
25public class BucketId {
26 private final DeviceId deviceId;
27 private final int bucket;
28
29 BucketId(DeviceId deviceId, int bucket) {
30 this.deviceId = deviceId;
31 this.bucket = bucket;
32 }
33
34 /**
35 * Returns the bucket device identifier.
36 *
37 * @return the device identifier
38 */
39 public DeviceId deviceId() {
40 return deviceId;
41 }
42
43 /**
44 * Returns the bucket number.
45 *
46 * @return the bucket number
47 */
48 public int bucket() {
49 return bucket;
50 }
51
52 @Override
53 public int hashCode() {
54 return Objects.hash(deviceId, bucket);
55 }
56
57 @Override
58 public boolean equals(Object other) {
59 if (other instanceof BucketId) {
60 BucketId that = (BucketId) other;
61 return this.deviceId.equals(that.deviceId)
62 && this.bucket == that.bucket;
63 }
64 return false;
65 }
66
67 @Override
68 public String toString() {
69 return String.format("%s/%d", deviceId, bucket);
70 }
71}