Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.topology; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 18 | import org.onosproject.net.DeviceId; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | /** |
| 23 | * Implementation of the topology vertex backed by a device id. |
| 24 | */ |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 25 | public class DefaultTopologyVertex implements TopologyVertex { |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 26 | |
| 27 | private final DeviceId deviceId; |
| 28 | |
| 29 | /** |
| 30 | * Creates a new topology vertex. |
| 31 | * |
| 32 | * @param deviceId backing infrastructure device identifier |
| 33 | */ |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 34 | public DefaultTopologyVertex(DeviceId deviceId) { |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 35 | this.deviceId = deviceId; |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public DeviceId deviceId() { |
| 40 | return deviceId; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public int hashCode() { |
| 45 | return Objects.hash(deviceId); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 50 | if (this == obj) { |
| 51 | return true; |
| 52 | } |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 53 | if (obj instanceof DefaultTopologyVertex) { |
| 54 | final DefaultTopologyVertex other = (DefaultTopologyVertex) obj; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 55 | return Objects.equals(this.deviceId, other.deviceId); |
| 56 | } |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String toString() { |
| 62 | return deviceId.toString(); |
| 63 | } |
| 64 | |
| 65 | } |
| 66 | |