blob: a4bdac7b09a73ad93efa77161e8d79dd7849b94a [file] [log] [blame]
Brian Stanke2b4f32d2016-02-03 14:22:10 -05001/*
2 * Copyright 2016 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 */
16
17package org.onosproject.incubator.net.key;
18
19import java.util.Objects;
20
21import static com.google.common.base.Preconditions.checkNotNull;
22
23/**
24 * Device key Id definition.
25 */
26public final class DeviceKeyId {
27 private final String identifier;
28
29 /**
30 * Constructor for serialization.
31 */
32 private DeviceKeyId() {
33 this.identifier = null;
34 }
35
36 /**
37 * Constructs the ID corresponding to a given string value.
38 *
39 * @param value the underlying value of this ID
40 */
41 private DeviceKeyId(String value) {
42 this.identifier = checkNotNull(value, "Device Key Id cannot be null.");
43 }
44
45 /**
46 * Static method to construct a device key identifier.
47 *
48 * @param id for the device key identifier
49 * @return device key identifier
50 */
Brian Stankeca93d9a2016-02-10 09:17:35 -050051 public static final DeviceKeyId deviceKeyId(String id) {
Brian Stanke2b4f32d2016-02-03 14:22:10 -050052 return new DeviceKeyId(id);
53 }
54
55 /**
56 * Returns the identifier of the device key identifier.
57 *
58 * @return identifier
59 */
60 public String id() {
61 return identifier;
62 }
63
64 /**
65 * Returns the hashcode of the identifier.
66 *
67 * @return hashcode
68 */
69 @Override
70 public int hashCode() {
71 return identifier.hashCode();
72 }
73
74 /**
75 * Compares two device key identifiers for equality.
76 *
77 * @param obj to compare against
78 * @return true if the objects are equal, false otherwise.
79 */
80 @Override
81 public boolean equals(Object obj) {
82 if (this == obj) {
83 return true;
84 }
85 if (obj instanceof DeviceKeyId) {
86 final DeviceKeyId that = (DeviceKeyId) obj;
87 return this.getClass() == that.getClass() &&
88 Objects.equals(this.identifier, that.identifier);
89 }
90 return false;
91 }
92
93 /**
94 * Returns a string representation of a DeviceKeyId.
95 *
96 * @return string
97 */
98 public String toString() {
99 return identifier;
100 }
101}