blob: e6f448e03f1356f14c302eb222edded93f971ba6 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.core;
toma6897792014-10-08 22:21:05 -070017
alshabib92c65ad2014-10-08 21:56:05 -070018import java.util.Objects;
19
toma6897792014-10-08 22:21:05 -070020import static com.google.common.base.MoreObjects.toStringHelper;
alshabib92c65ad2014-10-08 21:56:05 -070021
22/**
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070023 * Application identifier.
alshabib92c65ad2014-10-08 21:56:05 -070024 */
25public class DefaultApplicationId implements ApplicationId {
26
alshabib92c65ad2014-10-08 21:56:05 -070027 private final short id;
28 private final String name;
29
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070030 /**
31 * Creates a new application ID.
32 *
33 * @param id application identifier
34 * @param name application name
35 */
36 public DefaultApplicationId(Short id, String name) {
alshabib92c65ad2014-10-08 21:56:05 -070037 this.id = id;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070038 this.name = name;
39 }
40
41 // Constructor for serializers.
42 private DefaultApplicationId() {
43 this.id = 0;
44 this.name = null;
alshabib92c65ad2014-10-08 21:56:05 -070045 }
46
47 @Override
48 public short id() {
49 return id;
50 }
51
52 @Override
53 public String name() {
54 return name;
55 }
56
57 @Override
58 public int hashCode() {
59 return Objects.hash(id);
60 }
61
62 @Override
63 public boolean equals(Object obj) {
64 if (this == obj) {
65 return true;
66 }
toma6897792014-10-08 22:21:05 -070067 if (obj instanceof DefaultApplicationId) {
68 DefaultApplicationId other = (DefaultApplicationId) obj;
69 return Objects.equals(this.id, other.id);
alshabib92c65ad2014-10-08 21:56:05 -070070 }
toma6897792014-10-08 22:21:05 -070071 return false;
alshabib92c65ad2014-10-08 21:56:05 -070072 }
toma6897792014-10-08 22:21:05 -070073
74 @Override
75 public String toString() {
76 return toStringHelper(this).add("id", id).add("name", name).toString();
77 }
78
alshabib92c65ad2014-10-08 21:56:05 -070079}