samuel | 8d6b0a9 | 2015-07-11 13:22:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014-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.behaviour; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import org.onosproject.net.AbstractDescription; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.SparseAnnotations; |
| 23 | |
| 24 | import com.google.common.base.MoreObjects; |
| 25 | |
| 26 | /** |
| 27 | * The default implementation of bridge. |
| 28 | */ |
| 29 | public final class DefaultBridgeDescription extends AbstractDescription |
| 30 | implements BridgeDescription { |
| 31 | |
| 32 | private final BridgeName name; |
| 33 | private final DeviceId deviceId; |
| 34 | private final DeviceId controllerId; |
| 35 | |
| 36 | public DefaultBridgeDescription(BridgeName name, DeviceId controllerId, |
| 37 | DeviceId deviceId, |
| 38 | SparseAnnotations... annotations) { |
| 39 | super(annotations); |
| 40 | this.name = name; |
| 41 | this.deviceId = deviceId; |
| 42 | this.controllerId = controllerId; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public BridgeName bridgeName() { |
| 47 | return name; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public DeviceId deviceId() { |
| 52 | return deviceId; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public DeviceId cotrollerDeviceId() { |
| 57 | return controllerId; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public int hashCode() { |
| 62 | return Objects.hash(name, deviceId, controllerId); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean equals(Object obj) { |
| 67 | if (this == obj) { |
| 68 | return true; |
| 69 | } |
| 70 | if (obj instanceof DefaultBridgeDescription) { |
| 71 | final DefaultBridgeDescription that = (DefaultBridgeDescription) obj; |
| 72 | return this.getClass() == that.getClass() |
| 73 | && Objects.equals(this.name, that.name) |
| 74 | && Objects.equals(this.deviceId, that.deviceId) |
| 75 | && Objects.equals(this.controllerId, that.controllerId); |
| 76 | } |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public String toString() { |
| 82 | return MoreObjects.toStringHelper(getClass()).add("name", name) |
| 83 | .add("deviceId", deviceId).add("controllerId", controllerId) |
| 84 | .toString(); |
| 85 | } |
| 86 | |
| 87 | } |