blob: 433265e9c327e9c379cf0b1bb3918f44f826e053 [file] [log] [blame]
alshabib6553b512014-09-24 20:34:17 -07001package org.onlab.onos;
2
3import java.util.Objects;
4import java.util.concurrent.atomic.AtomicInteger;
5
6/**
7 * Application id generator class.
8 */
9public final class ApplicationId {
10
Yuta HIGUCHIf9ce4972014-10-04 22:13:47 -070011 private static final AtomicInteger ID_DISPENCER = new AtomicInteger(1);
alshabib6553b512014-09-24 20:34:17 -070012 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 HIGUCHIf9ce4972014-10-04 22:13:47 -070053 return new ApplicationId(ApplicationId.ID_DISPENCER.getAndIncrement());
alshabib6553b512014-09-24 20:34:17 -070054 }
55
56}