alshabib | 6553b51 | 2014-09-24 20:34:17 -0700 | [diff] [blame] | 1 | package org.onlab.onos; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | import java.util.concurrent.atomic.AtomicInteger; |
| 5 | |
| 6 | /** |
| 7 | * Application id generator class. |
| 8 | */ |
| 9 | public final class ApplicationId { |
| 10 | |
Yuta HIGUCHI | f9ce497 | 2014-10-04 22:13:47 -0700 | [diff] [blame^] | 11 | private static final AtomicInteger ID_DISPENCER = new AtomicInteger(1); |
alshabib | 6553b51 | 2014-09-24 20:34:17 -0700 | [diff] [blame] | 12 | private final Integer id; |
| 13 | |
| 14 | // Ban public construction |
| 15 | private ApplicationId(Integer id) { |
| 16 | this.id = id; |
| 17 | } |
| 18 | |
| 19 | public Integer id() { |
| 20 | return id; |
| 21 | } |
| 22 | |
| 23 | public static ApplicationId valueOf(Integer id) { |
| 24 | return new ApplicationId(id); |
| 25 | } |
| 26 | |
| 27 | @Override |
| 28 | public int hashCode() { |
| 29 | return Objects.hash(id); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public boolean equals(Object obj) { |
| 34 | if (this == obj) { |
| 35 | return true; |
| 36 | } |
| 37 | if (obj == null) { |
| 38 | return false; |
| 39 | } |
| 40 | if (!(obj instanceof ApplicationId)) { |
| 41 | return false; |
| 42 | } |
| 43 | ApplicationId other = (ApplicationId) obj; |
| 44 | return Objects.equals(this.id, other.id); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns a new application id. |
| 49 | * |
| 50 | * @return app id |
| 51 | */ |
| 52 | public static ApplicationId getAppId() { |
Yuta HIGUCHI | f9ce497 | 2014-10-04 22:13:47 -0700 | [diff] [blame^] | 53 | return new ApplicationId(ApplicationId.ID_DISPENCER.getAndIncrement()); |
alshabib | 6553b51 | 2014-09-24 20:34:17 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | } |