blob: b5ecccc90706fdf68696f6c4e0356f1e2e7f174b [file] [log] [blame]
Thomas Vachuskae0f804a2014-10-27 23:40:48 -07001package org.onlab.onos.core;
toma6897792014-10-08 22:21:05 -07002
alshabib92c65ad2014-10-08 21:56:05 -07003import java.util.Objects;
4
toma6897792014-10-08 22:21:05 -07005import static com.google.common.base.MoreObjects.toStringHelper;
alshabib92c65ad2014-10-08 21:56:05 -07006
7/**
Thomas Vachuskae0f804a2014-10-27 23:40:48 -07008 * Application identifier.
alshabib92c65ad2014-10-08 21:56:05 -07009 */
10public class DefaultApplicationId implements ApplicationId {
11
alshabib92c65ad2014-10-08 21:56:05 -070012 private final short id;
13 private final String name;
14
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070015 /**
16 * Creates a new application ID.
17 *
18 * @param id application identifier
19 * @param name application name
20 */
21 public DefaultApplicationId(Short id, String name) {
alshabib92c65ad2014-10-08 21:56:05 -070022 this.id = id;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070023 this.name = name;
24 }
25
26 // Constructor for serializers.
27 private DefaultApplicationId() {
28 this.id = 0;
29 this.name = null;
alshabib92c65ad2014-10-08 21:56:05 -070030 }
31
32 @Override
33 public short id() {
34 return id;
35 }
36
37 @Override
38 public String name() {
39 return name;
40 }
41
42 @Override
43 public int hashCode() {
44 return Objects.hash(id);
45 }
46
47 @Override
48 public boolean equals(Object obj) {
49 if (this == obj) {
50 return true;
51 }
toma6897792014-10-08 22:21:05 -070052 if (obj instanceof DefaultApplicationId) {
53 DefaultApplicationId other = (DefaultApplicationId) obj;
54 return Objects.equals(this.id, other.id);
alshabib92c65ad2014-10-08 21:56:05 -070055 }
toma6897792014-10-08 22:21:05 -070056 return false;
alshabib92c65ad2014-10-08 21:56:05 -070057 }
toma6897792014-10-08 22:21:05 -070058
59 @Override
60 public String toString() {
61 return toStringHelper(this).add("id", id).add("name", name).toString();
62 }
63
alshabib92c65ad2014-10-08 21:56:05 -070064}