kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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 | */ |
| 16 | package org.onosproject.incubator.net.faultmanagement.alarm; |
| 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; |
| 20 | |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 21 | import static com.google.common.base.Preconditions.checkArgument; |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 22 | /** |
| 23 | * Alarm identifier suitable as an external key. |
| 24 | * <p> |
| 25 | * This class is immutable.</p> |
| 26 | */ |
| 27 | @Beta |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 28 | public final class AlarmId extends Identifier<Long> { |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 29 | |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 30 | public static final AlarmId NONE = new AlarmId(); |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Instantiates a new Alarm id. |
| 34 | * |
| 35 | * @param id the id |
| 36 | */ |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 37 | private AlarmId(long id) { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 38 | super(id); |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 39 | checkArgument(id != 0L, "id must be non-zero"); |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 40 | } |
| 41 | |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 42 | private AlarmId() { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 43 | super(0L); |
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 | /** |
| 47 | * Creates an alarm identifier from the specified long representation. |
| 48 | * |
| 49 | * @param value long value |
| 50 | * @return intent identifier |
| 51 | */ |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 52 | public static AlarmId alarmId(long value) { |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 53 | return new AlarmId(value); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the backing integer index. |
| 58 | * |
| 59 | * @return backing integer index |
| 60 | */ |
| 61 | public long fingerprint() { |
Jian Li | b6d998e | 2016-02-29 11:41:18 -0800 | [diff] [blame] | 62 | return identifier; |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 63 | } |
kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame] | 64 | } |