blob: 21717b66e82863390939e96395de907b1093a56e [file] [log] [blame]
alshabib70aaa1b2015-09-25 14:30:59 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
alshabib70aaa1b2015-09-25 14:30:59 -07003 *
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 com.google.common.base.Objects;
19import org.onosproject.net.DeviceId;
20
alshabib5196e862015-09-27 10:59:50 +020021import static com.google.common.base.MoreObjects.toStringHelper;
22
alshabib70aaa1b2015-09-25 14:30:59 -070023/**
24 * A meter key represents a meter uniquely.
25 */
26public final class MeterKey {
27
28 private final DeviceId deviceId;
Wailok Shumbe900bd2021-08-05 00:55:47 +080029 private final MeterCellId id;
alshabib70aaa1b2015-09-25 14:30:59 -070030
Wailok Shumbe900bd2021-08-05 00:55:47 +080031 private MeterKey(DeviceId deviceId, MeterCellId id) {
alshabib70aaa1b2015-09-25 14:30:59 -070032 this.deviceId = deviceId;
33 this.id = id;
34 }
35
36 public DeviceId deviceId() {
37 return deviceId;
38 }
39
Wailok Shumbe900bd2021-08-05 00:55:47 +080040 /**
41 * @return a MeterId iff the id is a MeterId
42 * otherwise, return null
43 * @deprecated in onos-2.5 replaced by {@link #key(DeviceId,MeterCellId)}
44 * extends MeterKey to support both MeterId and PiMeterCellId
45 */
46 @Deprecated
alshabib70aaa1b2015-09-25 14:30:59 -070047 public MeterId meterId() {
Wailok Shumbe900bd2021-08-05 00:55:47 +080048 if (id instanceof MeterId) {
49 return (MeterId) id;
50 } else {
51 return null;
52 }
53 }
54
55 public MeterCellId meterCellId() {
alshabib70aaa1b2015-09-25 14:30:59 -070056 return id;
57 }
58
59 @Override
60 public boolean equals(Object o) {
61 if (this == o) {
62 return true;
63 }
64 if (o == null || getClass() != o.getClass()) {
65 return false;
66 }
67 MeterKey meterKey = (MeterKey) o;
68 return Objects.equal(deviceId, meterKey.deviceId) &&
69 Objects.equal(id, meterKey.id);
70 }
71
72 @Override
73 public int hashCode() {
74 return Objects.hashCode(deviceId, id);
75 }
76
alshabib5196e862015-09-27 10:59:50 +020077 @Override
78 public String toString() {
79 return toStringHelper(this)
80 .add("deviceId", deviceId)
Wailok Shumbe900bd2021-08-05 00:55:47 +080081 .add("meterCellId", id).toString();
alshabib5196e862015-09-27 10:59:50 +020082 }
83
Wailok Shumbe900bd2021-08-05 00:55:47 +080084 /**
85 * @param deviceId a DeviceId
86 * @param id a MeterId
87 * @return a MeterKey contains DeviceId and MeterId
88 * @deprecated in onos-2.5 replaced by {@link #key(DeviceId,MeterCellId)}
89 * extends MeterKey to support both MeterId and PiMeterCellId
90 */
91 @Deprecated
alshabib70aaa1b2015-09-25 14:30:59 -070092 public static MeterKey key(DeviceId deviceId, MeterId id) {
93 return new MeterKey(deviceId, id);
94 }
Wailok Shumbe900bd2021-08-05 00:55:47 +080095
96 public static MeterKey key(DeviceId deviceId, MeterCellId id) {
97 return new MeterKey(deviceId, id);
98 }
alshabib70aaa1b2015-09-25 14:30:59 -070099}