blob: dc76fee9bf62b66aeb0fd450b177ec94989709e0 [file] [log] [blame]
Wailok Shumf013a782021-07-26 16:51:01 +08001/*
2 * Copyright 2021-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.net.meter;
17
18import org.onosproject.net.DeviceId;
19
20import java.util.Objects;
21
22/**
23 * MeterTableKey is used to represent a single meter table in each device uniquely.
24 */
25public final class MeterTableKey {
26 private final DeviceId deviceId;
27 private final MeterScope scope;
28
29 private MeterTableKey(DeviceId deviceId, MeterScope scope) {
30 this.deviceId = deviceId;
31 this.scope = scope;
32 }
33
34 public static MeterTableKey key(DeviceId did, MeterScope scope) {
35 return new MeterTableKey(did, scope);
36 }
37
38 @Override
39 public boolean equals(Object obj) {
40 if (this == obj) {
41 return true;
42 }
43 if (obj == null || getClass() != obj.getClass()) {
44 return false;
45 }
46 MeterTableKey mtk = (MeterTableKey) obj;
47 return Objects.equals(deviceId, mtk.deviceId()) && Objects.equals(scope, mtk.scope());
48 }
49
50 @Override
51 public int hashCode() {
52 return Objects.hash(deviceId, scope);
53 }
54
55 @Override
56 public String toString() {
57 return "mtk@" + deviceId.toString() + " scope:" + scope.toString();
58 }
59
60 public DeviceId deviceId() {
61 return deviceId;
62 }
63
64 public MeterScope scope() {
65 return scope;
66 }
67}