blob: aae1ed5477b4f51eebea0c2bd5f26e018393956f [file] [log] [blame]
Phaneendra Mandaefb38752015-12-04 00:43:38 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Phaneendra Mandaefb38752015-12-04 00:43:38 +05303 *
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 */
16package org.onosproject.net;
17
18import java.util.Objects;
19
20import com.google.common.base.MoreObjects;
21
22/*
23 * Representation of NSH Service index
24 */
25public final class NshServiceIndex {
26 private static final short MASK = 0xFF;
27 private final short serviceIndex;
28
29 /**
30 * Default constructor.
31 *
32 * @param serviceIndex nsh service index
33 */
34 private NshServiceIndex(short serviceIndex) {
35 this.serviceIndex = (short) (serviceIndex & MASK);
36 }
37
38 /**
39 * Returns the NshServiceIndex by setting its value.
40 *
41 * @param serviceIndex nsh service index
42 * @return NshServiceIndex
43 */
44 public static NshServiceIndex of(short serviceIndex) {
45 return new NshServiceIndex(serviceIndex);
46 }
47
48
49 /**
50 * Returns nsh service index value.
51 *
52 * @return the nsh service index
53 */
54 public short serviceIndex() {
55 return serviceIndex;
56 }
57
58
59 @Override
60 public int hashCode() {
61 return Objects.hash(serviceIndex);
62 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (this == obj) {
67 return true;
68 }
69 if (!(obj instanceof NshServiceIndex)) {
70 return false;
71 }
72 final NshServiceIndex other = (NshServiceIndex) obj;
73 return Objects.equals(this.serviceIndex, other.serviceIndex);
74 }
75
76 @Override
77 public String toString() {
78 return MoreObjects.toStringHelper(this)
79 .add("serviceIndex", serviceIndex)
80 .toString();
81 }
82}
83