blob: e0107f878278461b67d1512f34db698826f86483 [file] [log] [blame]
kmcpeake4fe18c82015-11-17 20:07:39 +00001/*
2 * Copyright 2014 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 */
16package org.onosproject.incubator.net.faultmanagement.alarm;
17
18import com.google.common.annotations.Beta;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Alarm identifier suitable as an external key.
26 * <p>
27 * This class is immutable.</p>
28 */
29@Beta
30public final class AlarmId {
31
32 private final long id;
33
34 /**
35 * Instantiates a new Alarm id.
36 *
37 * @param id the id
38 */
39 public AlarmId(final long id) {
40 this.id = id;
41 }
42
43 /**
44 * Creates an alarm identifier from the specified long representation.
45 *
46 * @param value long value
47 * @return intent identifier
48 */
49 public static AlarmId valueOf(final long value) {
50 return new AlarmId(value);
51 }
52
53 /**
54 * Returns the backing integer index.
55 *
56 * @return backing integer index
57 */
58 public long fingerprint() {
59 return id;
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hash(id);
65 }
66
67 @Override
68 public boolean equals(final Object obj) {
69 if (this == obj) {
70 return true;
71 }
72 if (obj instanceof AlarmId) {
73 final AlarmId other = (AlarmId) obj;
74 return Objects.equals(this.id, other.id);
75 }
76 return false;
77 }
78
79 @Override
80 public String toString() {
81 return toStringHelper(this).add("id", id).toString();
82 }
83
84}