Esin Karaman | 971fb7f | 2017-12-28 13:44:52 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-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 | |
| 18 | package org.onosproject.drivers.bmv2.api.runtime; |
| 19 | |
| 20 | |
| 21 | import com.google.common.base.MoreObjects; |
| 22 | import com.google.common.base.Objects; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | |
| 25 | /** |
| 26 | * Global identifier of a BMv2 PRE group applied to a device, uniquely defined |
| 27 | * by a device ID and group ID. |
| 28 | */ |
| 29 | public final class Bmv2PreGroupHandle extends Bmv2Handle<Bmv2PreGroup> { |
| 30 | |
| 31 | private Bmv2PreGroupHandle(DeviceId deviceId, Bmv2PreGroup group) { |
| 32 | super(deviceId, group); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Creates a new handle for the given device ID and BMv2 PRE group. |
| 37 | * |
| 38 | * @param deviceId device ID |
| 39 | * @param group BMv2 PRE group |
| 40 | * @return BMv2 PRE group handle |
| 41 | */ |
| 42 | public static Bmv2PreGroupHandle of(DeviceId deviceId, |
| 43 | Bmv2PreGroup group) { |
| 44 | return new Bmv2PreGroupHandle(deviceId, group); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public int hashCode() { |
| 49 | return Objects.hashCode(deviceId(), |
| 50 | bmv2Entity().groupId()); |
| 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 | Bmv2PreGroupHandle that = (Bmv2PreGroupHandle) o; |
| 62 | return Objects.equal(deviceId(), that.deviceId()) && |
| 63 | Objects.equal(bmv2Entity().groupId(), that.bmv2Entity().groupId()); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public String toString() { |
| 68 | return MoreObjects.toStringHelper(this) |
| 69 | .add("deviceId", deviceId()) |
| 70 | .add("groupId", bmv2Entity().groupId()) |
| 71 | .toString(); |
| 72 | } |
| 73 | } |