Carmelo Cascone | 94a659f | 2017-11-21 00:06:11 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.net.pi.runtime; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import com.google.common.base.Objects; |
| 22 | import 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 |
| 29 | public final class PiActionGroupHandle extends PiHandle<PiActionGroup> { |
| 30 | |
| 31 | private PiActionGroupHandle(DeviceId deviceId, PiActionGroup group) { |
| 32 | super(deviceId, group); |
| 33 | } |
| 34 | |
| 35 | /** |
| 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); |
| 45 | } |
| 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()) && |
| 66 | Objects.equal(piEntity().id(), piEntity().id()); |
| 67 | } |
| 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 | } |