tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.topology; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 2 | |
| 3 | import org.onlab.onos.net.DeviceId; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 4 | |
| 5 | import java.util.Objects; |
| 6 | |
| 7 | /** |
| 8 | * Implementation of the topology vertex backed by a device id. |
| 9 | */ |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 10 | public class DefaultTopologyVertex implements TopologyVertex { |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 11 | |
| 12 | private final DeviceId deviceId; |
| 13 | |
| 14 | /** |
| 15 | * Creates a new topology vertex. |
| 16 | * |
| 17 | * @param deviceId backing infrastructure device identifier |
| 18 | */ |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 19 | public DefaultTopologyVertex(DeviceId deviceId) { |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 20 | this.deviceId = deviceId; |
| 21 | } |
| 22 | |
| 23 | @Override |
| 24 | public DeviceId deviceId() { |
| 25 | return deviceId; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public int hashCode() { |
| 30 | return Objects.hash(deviceId); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public boolean equals(Object obj) { |
tom | fc9a4ff | 2014-09-22 18:22:47 -0700 | [diff] [blame] | 35 | if (this == obj) { |
| 36 | return true; |
| 37 | } |
tom | 9793755 | 2014-09-11 10:48:42 -0700 | [diff] [blame] | 38 | if (obj instanceof DefaultTopologyVertex) { |
| 39 | final DefaultTopologyVertex other = (DefaultTopologyVertex) obj; |
tom | 2d33141 | 2014-09-10 21:31:20 -0700 | [diff] [blame] | 40 | return Objects.equals(this.deviceId, other.deviceId); |
| 41 | } |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public String toString() { |
| 47 | return deviceId.toString(); |
| 48 | } |
| 49 | |
| 50 | } |
| 51 | |