Phanendra Manda | 37b97fb | 2015-08-15 02:04:24 +0530 | [diff] [blame] | 1 | package org.onosproject.net; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | import org.onlab.packet.IpAddress; |
| 5 | import com.google.common.base.MoreObjects; |
| 6 | |
| 7 | /** |
| 8 | * Represent for a Element ID using ip address. |
| 9 | */ |
| 10 | public final class IpElementId extends ElementId { |
| 11 | |
| 12 | private final IpAddress ipAddress; |
| 13 | |
| 14 | /** |
| 15 | * Public construction is prohibited. |
| 16 | * @param ipAddress ip address |
| 17 | */ |
| 18 | private IpElementId(IpAddress ipAddress) { |
| 19 | this.ipAddress = ipAddress; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Create a IP Element ID. |
| 24 | * @param ipAddress IP address |
| 25 | * @return IpElementId |
| 26 | */ |
| 27 | public static IpElementId ipElement(IpAddress ipAddress) { |
| 28 | return new IpElementId(ipAddress); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Returns the ip address. |
| 33 | * |
| 34 | * @return ipAddress |
| 35 | */ |
| 36 | public IpAddress ipAddress() { |
| 37 | return ipAddress; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public int hashCode() { |
| 42 | return Objects.hash(ipAddress); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public boolean equals(Object obj) { |
| 47 | if (this == obj) { |
| 48 | return true; |
| 49 | } |
| 50 | if (obj instanceof IpElementId) { |
| 51 | final IpElementId other = (IpElementId) obj; |
| 52 | return Objects.equals(this.ipAddress, other.ipAddress); |
| 53 | } |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String toString() { |
| 59 | return MoreObjects.toStringHelper(getClass()).add("ipAddress", ipAddress).toString(); |
| 60 | } |
| 61 | } |