blob: 39cd5b6dbdbe2d01b04effe3c4bbca5b198b92fc [file] [log] [blame]
kmcpeake4fe18c82015-11-17 20:07:39 +00001/*
Thomas Vachuska52f2cd12018-11-08 21:20:04 -08002 * Copyright 2018-present Open Networking Foundation
kmcpeake4fe18c82015-11-17 20:07:39 +00003 *
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 */
Thomas Vachuska52f2cd12018-11-08 21:20:04 -080016package org.onosproject.alarm;
kmcpeake4fe18c82015-11-17 20:07:39 +000017
18import com.google.common.annotations.Beta;
Jian Lib6d998e2016-02-29 11:41:18 -080019import org.onlab.util.Identifier;
Andrea Campanella65f9eb92017-05-02 11:36:14 -070020import org.onosproject.net.DeviceId;
Jian Lib6d998e2016-02-29 11:41:18 -080021
kmcpeakeb172d5f2015-12-10 11:30:43 +000022import static com.google.common.base.Preconditions.checkArgument;
Andrea Campanella65f9eb92017-05-02 11:36:14 -070023import static com.google.common.base.Preconditions.checkNotNull;
24
kmcpeake4fe18c82015-11-17 20:07:39 +000025/**
26 * Alarm identifier suitable as an external key.
27 * <p>
28 * This class is immutable.</p>
29 */
30@Beta
Andrea Campanella65f9eb92017-05-02 11:36:14 -070031public final class AlarmId extends Identifier<String> {
kmcpeake4fe18c82015-11-17 20:07:39 +000032
33 /**
34 * Instantiates a new Alarm id.
35 *
Andrea Campanella65f9eb92017-05-02 11:36:14 -070036 * @param id the device id
37 * @param uniqueIdentifier the unique identifier of the Alarm on that device
kmcpeake4fe18c82015-11-17 20:07:39 +000038 */
Andrea Campanella65f9eb92017-05-02 11:36:14 -070039 private AlarmId(DeviceId id, String uniqueIdentifier) {
40 super(id.toString() + ":" + uniqueIdentifier);
41 checkNotNull(id, "device id must not be null");
42 checkNotNull(uniqueIdentifier, "unique identifier must not be null");
43 checkArgument(!uniqueIdentifier.isEmpty(), "unique identifier must not be empty");
kmcpeakeb172d5f2015-12-10 11:30:43 +000044 }
45
kmcpeake4fe18c82015-11-17 20:07:39 +000046 /**
Ray Milkeyc108a6b2017-08-23 15:23:50 -070047 * Instantiates a new Alarm id, primarily meant for lookup.
kmcpeake4fe18c82015-11-17 20:07:39 +000048 *
Andrea Campanella65f9eb92017-05-02 11:36:14 -070049 * @param globallyUniqueIdentifier the globally unique identifier of the Alarm,
50 * device Id + local unique identifier on the device
kmcpeake4fe18c82015-11-17 20:07:39 +000051 */
Andrea Campanella65f9eb92017-05-02 11:36:14 -070052 private AlarmId(String globallyUniqueIdentifier) {
53 super(globallyUniqueIdentifier);
54 checkArgument(!globallyUniqueIdentifier.isEmpty(), "unique identifier must not be empty");
kmcpeake4fe18c82015-11-17 20:07:39 +000055 }
56
57 /**
Andrea Campanella65f9eb92017-05-02 11:36:14 -070058 * Creates an alarm identifier from the specified device id and
59 * unique identifier provided representation.
kmcpeake4fe18c82015-11-17 20:07:39 +000060 *
Andrea Campanella65f9eb92017-05-02 11:36:14 -070061 * @param id device id
62 * @param uniqueIdentifier per device unique identifier of the alarm
63 * @return alarm identifier
kmcpeake4fe18c82015-11-17 20:07:39 +000064 */
Andrea Campanella65f9eb92017-05-02 11:36:14 -070065 public static AlarmId alarmId(DeviceId id, String uniqueIdentifier) {
66 return new AlarmId(id, uniqueIdentifier);
kmcpeake4fe18c82015-11-17 20:07:39 +000067 }
Andrea Campanella65f9eb92017-05-02 11:36:14 -070068
69 /**
70 * Creates an alarm identifier from the specified globally unique identifier.
71 *
72 * @param globallyUniqueIdentifier the globally unique identifier of the Alarm,
73 * device Id + local unique identifier on the device
74 * @return alarm identifier
75 */
76 public static AlarmId alarmId(String globallyUniqueIdentifier) {
77 return new AlarmId(globallyUniqueIdentifier);
78 }
79
kmcpeake4fe18c82015-11-17 20:07:39 +000080}