kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 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 | */ |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame] | 16 | package org.onosproject.alarm; |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 17 | |
| 18 | import com.google.common.annotations.Beta; |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 19 | import org.onlab.util.Identifier; |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 20 | import org.onosproject.net.DeviceId; |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 21 | |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 22 | import static com.google.common.base.Preconditions.checkArgument; |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 25 | /** |
| 26 | * Alarm identifier suitable as an external key. |
| 27 | * <p> |
| 28 | * This class is immutable.</p> |
| 29 | */ |
| 30 | @Beta |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 31 | public final class AlarmId extends Identifier<String> { |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Instantiates a new Alarm id. |
| 35 | * |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 36 | * @param id the device id |
| 37 | * @param uniqueIdentifier the unique identifier of the Alarm on that device |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 38 | */ |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 39 | 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"); |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 44 | } |
| 45 | |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 46 | /** |
Ray Milkey | c108a6b | 2017-08-23 15:23:50 -0700 | [diff] [blame] | 47 | * Instantiates a new Alarm id, primarily meant for lookup. |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 48 | * |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 49 | * @param globallyUniqueIdentifier the globally unique identifier of the Alarm, |
| 50 | * device Id + local unique identifier on the device |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 51 | */ |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 52 | private AlarmId(String globallyUniqueIdentifier) { |
| 53 | super(globallyUniqueIdentifier); |
| 54 | checkArgument(!globallyUniqueIdentifier.isEmpty(), "unique identifier must not be empty"); |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /** |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 58 | * Creates an alarm identifier from the specified device id and |
| 59 | * unique identifier provided representation. |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 60 | * |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 61 | * @param id device id |
| 62 | * @param uniqueIdentifier per device unique identifier of the alarm |
| 63 | * @return alarm identifier |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 64 | */ |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 65 | public static AlarmId alarmId(DeviceId id, String uniqueIdentifier) { |
| 66 | return new AlarmId(id, uniqueIdentifier); |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 67 | } |
Andrea Campanella | 65f9eb9 | 2017-05-02 11:36:14 -0700 | [diff] [blame] | 68 | |
| 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 | |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 80 | } |