Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.opencord.aaa.impl; |
| 18 | |
| 19 | import java.util.Objects; |
| 20 | |
Matteo Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame] | 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 23 | /** |
| 24 | * An identifier for an authentication request. |
| 25 | */ |
| 26 | public final class RequestIdentifier { |
| 27 | |
| 28 | private byte identifier; |
| 29 | |
| 30 | /** |
| 31 | * Creates a new request identifier. |
| 32 | * |
| 33 | * @param identifier id number |
| 34 | */ |
Matteo Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame] | 35 | public RequestIdentifier(byte identifier) { |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 36 | 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 Scandolo | 105210b | 2020-12-10 10:32:39 -0800 | [diff] [blame^] | 49 | * 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 Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 58 | * 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 Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame] | 67 | @Override |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 68 | 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 Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame] | 78 | @Override |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 79 | public int hashCode() { |
| 80 | return Objects.hashCode(identifier); |
| 81 | } |
Matteo Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame] | 82 | |
| 83 | @Override |
| 84 | public String toString() { |
| 85 | return toStringHelper(getClass()) |
| 86 | .add("identifier", Byte.toString(identifier)) |
| 87 | .toString(); |
| 88 | } |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 89 | } |