alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | package org.onosproject.net.meter; |
| 17 | |
| 18 | import com.google.common.base.Objects; |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | |
alshabib | 5196e86 | 2015-09-27 10:59:50 +0200 | [diff] [blame] | 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 23 | /** |
| 24 | * A meter key represents a meter uniquely. |
| 25 | */ |
| 26 | public final class MeterKey { |
| 27 | |
| 28 | private final DeviceId deviceId; |
| 29 | private final MeterId id; |
| 30 | |
| 31 | private MeterKey(DeviceId deviceId, MeterId id) { |
| 32 | this.deviceId = deviceId; |
| 33 | this.id = id; |
| 34 | } |
| 35 | |
| 36 | public DeviceId deviceId() { |
| 37 | return deviceId; |
| 38 | } |
| 39 | |
| 40 | public MeterId meterId() { |
| 41 | return id; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public boolean equals(Object o) { |
| 46 | if (this == o) { |
| 47 | return true; |
| 48 | } |
| 49 | if (o == null || getClass() != o.getClass()) { |
| 50 | return false; |
| 51 | } |
| 52 | MeterKey meterKey = (MeterKey) o; |
| 53 | return Objects.equal(deviceId, meterKey.deviceId) && |
| 54 | Objects.equal(id, meterKey.id); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | return Objects.hashCode(deviceId, id); |
| 60 | } |
| 61 | |
alshabib | 5196e86 | 2015-09-27 10:59:50 +0200 | [diff] [blame] | 62 | @Override |
| 63 | public String toString() { |
| 64 | return toStringHelper(this) |
| 65 | .add("deviceId", deviceId) |
| 66 | .add("meterId", id).toString(); |
| 67 | } |
| 68 | |
alshabib | 70aaa1b | 2015-09-25 14:30:59 -0700 | [diff] [blame] | 69 | public static MeterKey key(DeviceId deviceId, MeterId id) { |
| 70 | return new MeterKey(deviceId, id); |
| 71 | } |
| 72 | } |