blob: 4baa6fa19dd12eb624a884cc559276fb876e9d1c [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
Carmelo Casconee44592f2018-09-12 02:24:47 -070024import static com.google.common.base.Preconditions.checkNotNull;
25
Frank Wangd7e3b4b2017-09-24 13:37:54 +090026/**
Carmelo Casconee44592f2018-09-12 02:24:47 -070027 * Global identifier of a PI meter cell configuration applied to a device,
28 * uniquely defined by a device ID and meter cell ID.
Frank Wangd7e3b4b2017-09-24 13:37:54 +090029 */
30@Beta
31public final class PiMeterHandle extends PiHandle<PiMeterCellConfig> {
32
Carmelo Casconee44592f2018-09-12 02:24:47 -070033 private final PiMeterCellId cellId;
34
35 private PiMeterHandle(DeviceId deviceId, PiMeterCellId meterCellId) {
36 super(deviceId);
37 this.cellId = meterCellId;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090038 }
39
40 /**
Carmelo Casconee44592f2018-09-12 02:24:47 -070041 * Creates a new handle for the given device ID and PI meter cell ID.
Frank Wangd7e3b4b2017-09-24 13:37:54 +090042 *
Carmelo Casconee44592f2018-09-12 02:24:47 -070043 * @param deviceId device ID
44 * @param meterCellId meter cell ID
45 * @return PI meter handle
46 */
47 public static PiMeterHandle of(DeviceId deviceId,
48 PiMeterCellId meterCellId) {
49 return new PiMeterHandle(deviceId, meterCellId);
50 }
51
52 /**
53 * Creates a new handle for the given device ID and PI meter cell
54 * configuration.
55 *
56 * @param deviceId device ID
Frank Wangd7e3b4b2017-09-24 13:37:54 +090057 * @param meterCellConfig meter config
58 * @return PI meter handle
59 */
60 public static PiMeterHandle of(DeviceId deviceId,
61 PiMeterCellConfig meterCellConfig) {
Carmelo Casconee44592f2018-09-12 02:24:47 -070062 checkNotNull(meterCellConfig);
63 return new PiMeterHandle(deviceId, meterCellConfig.cellId());
64 }
65
66 @Override
67 public PiEntityType entityType() {
68 return PiEntityType.METER_CELL_CONFIG;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090069 }
70
71 @Override
72 public int hashCode() {
Carmelo Casconee44592f2018-09-12 02:24:47 -070073 return Objects.hashCode(deviceId(), cellId);
Frank Wangd7e3b4b2017-09-24 13:37:54 +090074 }
75
76 @Override
77 public boolean equals(Object o) {
78 if (this == o) {
79 return true;
80 }
81 if (o == null || getClass() != o.getClass()) {
82 return false;
83 }
84 PiMeterHandle that = (PiMeterHandle) o;
85 return Objects.equal(deviceId(), that.deviceId()) &&
Carmelo Casconee44592f2018-09-12 02:24:47 -070086 Objects.equal(cellId, that.cellId);
Frank Wangd7e3b4b2017-09-24 13:37:54 +090087 }
88
89 @Override
90 public String toString() {
91 return MoreObjects.toStringHelper(this)
92 .add("deviceId", deviceId())
Carmelo Casconee44592f2018-09-12 02:24:47 -070093 .add("meterCellId", cellId)
Frank Wangd7e3b4b2017-09-24 13:37:54 +090094 .toString();
95 }
Carmelo Casconee44592f2018-09-12 02:24:47 -070096}