blob: 4c87f1f7edf09d50cdeeeccdc9c1c26d3e2d8a09 [file] [log] [blame]
Carmelo Cascone326ad2d2017-11-28 18:09:13 -08001/*
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 action group applied to a device, uniquely defined
26 * by a device ID, action profile ID and group ID.
27 */
28@Beta
29public final class PiActionGroupHandle extends PiHandle<PiActionGroup> {
30
Carmelo Casconee75b7942017-11-21 17:14:49 -080031 private PiActionGroupHandle(DeviceId deviceId, PiActionGroup group) {
32 super(deviceId, group);
33 }
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080034
Carmelo Casconee75b7942017-11-21 17:14:49 -080035 /**
36 * Creates a new handle for the given device ID and PI action group.
37 *
38 * @param deviceId device ID
39 * @param group PI action group
40 * @return PI action group handle
41 */
42 public static PiActionGroupHandle of(DeviceId deviceId,
43 PiActionGroup group) {
44 return new PiActionGroupHandle(deviceId, group);
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080045 }
46
47 @Override
48 public int hashCode() {
49 return Objects.hashCode(deviceId(),
50 piEntity().actionProfileId(),
51 piEntity().id());
52 }
53
54 @Override
55 public boolean equals(Object o) {
56 if (this == o) {
57 return true;
58 }
59 if (o == null || getClass() != o.getClass()) {
60 return false;
61 }
62 PiActionGroupHandle that = (PiActionGroupHandle) o;
63 return Objects.equal(deviceId(), that.deviceId()) &&
64 Objects.equal(piEntity().actionProfileId(),
65 that.piEntity().actionProfileId()) &&
Esin Karaman971fb7f2017-12-28 13:44:52 +000066 Objects.equal(piEntity().id(), that.piEntity().id());
Carmelo Cascone326ad2d2017-11-28 18:09:13 -080067 }
68
69 @Override
70 public String toString() {
71 return MoreObjects.toStringHelper(this)
72 .add("deviceId", deviceId())
73 .add("actionProfileId", piEntity().actionProfileId())
74 .add("groupId", piEntity().id())
75 .toString();
76 }
77}