blob: 4e65009397cfe72fe7910f507537483f05fe0894 [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;
kmcpeake4fe18c82015-11-17 20:07:39 +000019import java.util.Objects;
kmcpeake4fe18c82015-11-17 20:07:39 +000020import static com.google.common.base.MoreObjects.toStringHelper;
kmcpeakeb172d5f2015-12-10 11:30:43 +000021import static com.google.common.base.Preconditions.checkArgument;
kmcpeake4fe18c82015-11-17 20:07:39 +000022/**
23 * Alarm identifier suitable as an external key.
24 * <p>
25 * This class is immutable.</p>
26 */
27@Beta
28public final class AlarmId {
29
30 private final long id;
kmcpeakeb172d5f2015-12-10 11:30:43 +000031 public static final AlarmId NONE = new AlarmId();
kmcpeake4fe18c82015-11-17 20:07:39 +000032
33 /**
34 * Instantiates a new Alarm id.
35 *
36 * @param id the id
37 */
kmcpeakeb172d5f2015-12-10 11:30:43 +000038 private AlarmId(long id) {
39 checkArgument(id != 0L, "id must be non-zero");
kmcpeake4fe18c82015-11-17 20:07:39 +000040 this.id = id;
41 }
42
kmcpeakeb172d5f2015-12-10 11:30:43 +000043 private AlarmId() {
44 this.id = 0L;
45 }
46
kmcpeake4fe18c82015-11-17 20:07:39 +000047 /**
48 * Creates an alarm identifier from the specified long representation.
49 *
50 * @param value long value
51 * @return intent identifier
52 */
kmcpeakeb172d5f2015-12-10 11:30:43 +000053 public static AlarmId alarmId(long value) {
kmcpeake4fe18c82015-11-17 20:07:39 +000054 return new AlarmId(value);
55 }
56
57 /**
58 * Returns the backing integer index.
59 *
60 * @return backing integer index
61 */
62 public long fingerprint() {
63 return id;
64 }
65
66 @Override
67 public int hashCode() {
68 return Objects.hash(id);
69 }
70
71 @Override
kmcpeakeb172d5f2015-12-10 11:30:43 +000072 public boolean equals(Object obj) {
kmcpeake4fe18c82015-11-17 20:07:39 +000073 if (this == obj) {
74 return true;
75 }
76 if (obj instanceof AlarmId) {
kmcpeakeb172d5f2015-12-10 11:30:43 +000077 AlarmId other = (AlarmId) obj;
kmcpeake4fe18c82015-11-17 20:07:39 +000078 return Objects.equals(this.id, other.id);
79 }
80 return false;
81 }
82
83 @Override
84 public String toString() {
85 return toStringHelper(this).add("id", id).toString();
86 }
87
88}