blob: ad2af9d4784647826311bba65b0a374baf61767a [file] [log] [blame]
Frank Wangd7e3b4b2017-09-24 13:37:54 +09001/*
2 * Copyright 2017-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 */
16
17package org.onosproject.net.pi.runtime;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
22import org.onosproject.net.DeviceId;
23
24/**
25 * Global identifier of a PI meter cell configuration applied to a device, uniquely defined
26 * by a device ID and meter cell ID.
27 */
28@Beta
29public final class PiMeterHandle extends PiHandle<PiMeterCellConfig> {
30
31 private PiMeterHandle(DeviceId deviceId, PiMeterCellConfig meterCellConfig) {
32 super(deviceId, meterCellConfig);
33 }
34
35 /**
36 * Creates a new handle for the given device ID and PI meter cell configuration.
37 *
38 * @param deviceId device ID
39 * @param meterCellConfig meter config
40 * @return PI meter handle
41 */
42 public static PiMeterHandle of(DeviceId deviceId,
43 PiMeterCellConfig meterCellConfig) {
44 return new PiMeterHandle(deviceId, meterCellConfig);
45 }
46
47 @Override
48 public int hashCode() {
49 return Objects.hashCode(deviceId(),
50 piEntity().cellId());
51 }
52
53 @Override
54 public boolean equals(Object o) {
55 if (this == o) {
56 return true;
57 }
58 if (o == null || getClass() != o.getClass()) {
59 return false;
60 }
61 PiMeterHandle that = (PiMeterHandle) o;
62 return Objects.equal(deviceId(), that.deviceId()) &&
63 Objects.equal(piEntity().cellId(),
64 that.piEntity().cellId());
65 }
66
67 @Override
68 public String toString() {
69 return MoreObjects.toStringHelper(this)
70 .add("deviceId", deviceId())
71 .add("meterCellId", piEntity().cellId())
72 .toString();
73 }
74}