blob: 18b73e364a290a52cc07da32dfed30854f428fda [file] [log] [blame]
Jonathan Hart612651f2019-11-25 09:21:43 -08001/*
2 * Copyright 2020-present Open Networking Foundation
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.opencord.aaa.impl;
18
19import java.util.Objects;
20
Matteo Scandolobbc1ffb2020-10-16 15:56:20 -070021import static com.google.common.base.MoreObjects.toStringHelper;
22
Jonathan Hart612651f2019-11-25 09:21:43 -080023/**
24 * An identifier for an authentication request.
25 */
26public final class RequestIdentifier {
27
28 private byte identifier;
29
30 /**
31 * Creates a new request identifier.
32 *
33 * @param identifier id number
34 */
Matteo Scandolobbc1ffb2020-10-16 15:56:20 -070035 public RequestIdentifier(byte identifier) {
Jonathan Hart612651f2019-11-25 09:21:43 -080036 this.identifier = identifier;
37 }
38
39 /**
40 * Returns the id number.
41 *
42 * @return id
43 */
44 public byte identifier() {
45 return this.identifier;
46 }
47
48 /**
Matteo Scandolo105210b2020-12-10 10:32:39 -080049 * Get the identifier in a readable format.
50 *
51 * @return identifier
52 */
53 public int getReadableIdentifier() {
54 return this.identifier & 0xff;
55 }
56
57 /**
Jonathan Hart612651f2019-11-25 09:21:43 -080058 * Creates a new request identifier.
59 *
60 * @param identifier id number
61 * @return identifier
62 */
63 public static RequestIdentifier of(byte identifier) {
64 return new RequestIdentifier(identifier);
65 }
66
Matteo Scandolobbc1ffb2020-10-16 15:56:20 -070067 @Override
Jonathan Hart612651f2019-11-25 09:21:43 -080068 public boolean equals(Object other) {
69 if (!(other instanceof RequestIdentifier)) {
70 return false;
71 }
72
73 RequestIdentifier that = (RequestIdentifier) other;
74
75 return identifier == that.identifier;
76 }
77
Matteo Scandolobbc1ffb2020-10-16 15:56:20 -070078 @Override
Jonathan Hart612651f2019-11-25 09:21:43 -080079 public int hashCode() {
80 return Objects.hashCode(identifier);
81 }
Matteo Scandolobbc1ffb2020-10-16 15:56:20 -070082
83 @Override
84 public String toString() {
85 return toStringHelper(getClass())
86 .add("identifier", Byte.toString(identifier))
87 .toString();
88 }
Jonathan Hart612651f2019-11-25 09:21:43 -080089}