blob: 754a6435df069d5dfbe8ced99febc34ac8444991 [file] [log] [blame]
Pengfei Lue0c02e22015-07-07 15:41:31 +08001/*
2 * Copyright 2015 Open Networking Laboratory
3 * Originally created by Pengfei Lu, Network and Cloud Computing Laboratory, Dalian University of Technology, China
4 * Advisers: Keqiu Li and Heng Qi
5 * This work is supported by the State Key Program of National Natural Science of China(Grant No. 61432002)
6 * and Prospective Research Project on Future Networks in Jiangsu Future Networks Innovation Institute.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20package org.onos.acl;
21
22/**
23 * ACL rule identifier suitable as an external key.
24 * <p>This class is immutable.</p>
25 */
26public final class RuleId {
27 private final long value;
28
29 /**
30 * Creates an ACL rule identifier from the specified long value.
31 *
32 * @param value long value
33 * @return ACL rule identifier
34 */
35 public static RuleId valueOf(long value) {
36 return new RuleId(value);
37 }
38
39 /**
40 * Constructor for serializer.
41 */
42 RuleId() {
43 this.value = 0;
44 }
45
46 /**
47 * Constructs the ID corresponding to a given long value.
48 *
49 * @param value the underlying value of this ID
50 */
51 RuleId(long value) {
52 this.value = value;
53 }
54
55 /**
56 * Returns the backing value.
57 *
58 * @return the value
59 */
60 public long fingerprint() {
61 return value;
62 }
63
64 @Override
65 public int hashCode() {
66 return Long.hashCode(value);
67 }
68
69 @Override
70 public boolean equals(Object obj) {
71 if (obj == this) {
72 return true;
73 }
74 if (!(obj instanceof RuleId)) {
75 return false;
76 }
77 RuleId that = (RuleId) obj;
78 return this.value == that.value;
79 }
80
81 @Override
82 public String toString() {
83 return "0x" + Long.toHexString(value);
84 }
85}