blob: f34560774f519d72ada9eb17f1038a915b41ca9b [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
11 private static AtomicInteger idDispenser;
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() {
53 if (ApplicationId.idDispenser == null) {
54 ApplicationId.idDispenser = new AtomicInteger(1);
55 }
56 return new ApplicationId(ApplicationId.idDispenser.getAndIncrement());
57 }
58
59}