alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 1 | package org.onlab.onos.impl; |
| 2 | |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 3 | import org.onlab.onos.ApplicationId; |
| 4 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 5 | import java.util.Objects; |
| 6 | |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 7 | import static com.google.common.base.MoreObjects.toStringHelper; |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * Application id generator class. |
| 11 | */ |
| 12 | public class DefaultApplicationId implements ApplicationId { |
| 13 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 14 | private final short id; |
| 15 | private final String name; |
| 16 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 17 | // Ban public construction |
| 18 | protected DefaultApplicationId(Short id, String identifier) { |
| 19 | this.id = id; |
| 20 | this.name = identifier; |
| 21 | } |
| 22 | |
| 23 | @Override |
| 24 | public short id() { |
| 25 | return id; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public String name() { |
| 30 | return name; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public int hashCode() { |
| 35 | return Objects.hash(id); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public boolean equals(Object obj) { |
| 40 | if (this == obj) { |
| 41 | return true; |
| 42 | } |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 43 | if (obj instanceof DefaultApplicationId) { |
| 44 | DefaultApplicationId other = (DefaultApplicationId) obj; |
| 45 | return Objects.equals(this.id, other.id); |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 46 | } |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 47 | return false; |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 48 | } |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 49 | |
| 50 | @Override |
| 51 | public String toString() { |
| 52 | return toStringHelper(this).add("id", id).add("name", name).toString(); |
| 53 | } |
| 54 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 55 | } |