blob: 5bc01b027918fd020b18c08d861d403ab24c398a [file] [log] [blame]
alshabib70aaa1b2015-09-25 14:30:59 -07001/*
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.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;
29 private final MeterId id;
30
31 private MeterKey(DeviceId deviceId, MeterId id) {
32 this.deviceId = deviceId;
33 this.id = id;
34 }
35
36 public DeviceId deviceId() {
37 return deviceId;
38 }
39
40 public MeterId meterId() {
41 return id;
42 }
43
44 @Override
45 public boolean equals(Object o) {
46 if (this == o) {
47 return true;
48 }
49 if (o == null || getClass() != o.getClass()) {
50 return false;
51 }
52 MeterKey meterKey = (MeterKey) o;
53 return Objects.equal(deviceId, meterKey.deviceId) &&
54 Objects.equal(id, meterKey.id);
55 }
56
57 @Override
58 public int hashCode() {
59 return Objects.hashCode(deviceId, id);
60 }
61
alshabib5196e862015-09-27 10:59:50 +020062 @Override
63 public String toString() {
64 return toStringHelper(this)
65 .add("deviceId", deviceId)
66 .add("meterId", id).toString();
67 }
68
alshabib70aaa1b2015-09-25 14:30:59 -070069 public static MeterKey key(DeviceId deviceId, MeterId id) {
70 return new MeterKey(deviceId, id);
71 }
72}