Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 16 | package org.onlab.onos.core; |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 17 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 18 | import java.util.Objects; |
| 19 | |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 23 | * Application identifier. |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 24 | */ |
| 25 | public class DefaultApplicationId implements ApplicationId { |
| 26 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 27 | private final short id; |
| 28 | private final String name; |
| 29 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 30 | /** |
| 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) { |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 37 | this.id = id; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 38 | this.name = name; |
| 39 | } |
| 40 | |
| 41 | // Constructor for serializers. |
| 42 | private DefaultApplicationId() { |
| 43 | this.id = 0; |
| 44 | this.name = null; |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 45 | } |
| 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 | } |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 67 | if (obj instanceof DefaultApplicationId) { |
| 68 | DefaultApplicationId other = (DefaultApplicationId) obj; |
| 69 | return Objects.equals(this.id, other.id); |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 70 | } |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 71 | return false; |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 72 | } |
tom | a689779 | 2014-10-08 22:21:05 -0700 | [diff] [blame] | 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | return toStringHelper(this).add("id", id).add("name", name).toString(); |
| 77 | } |
| 78 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 79 | } |