kmcpeake | 4fe18c8 | 2015-11-17 20:07:39 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014-2015 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 | */ |
| 16 | package org.onosproject.incubator.net.faultmanagement.alarm; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import java.net.URI; |
| 21 | import java.util.Objects; |
| 22 | import java.util.Set; |
| 23 | |
| 24 | /** |
| 25 | * Immutable representation of a alarm source. It is meaningful within the |
| 26 | * context of a device. |
| 27 | */ |
| 28 | public final class AlarmEntityId { |
| 29 | |
| 30 | public static final AlarmEntityId NONE = new AlarmEntityId(URI.create("none:none")); |
| 31 | public static final Set<String> SCHEMES = ImmutableSet.of("none", "port", "och", "other"); |
| 32 | |
| 33 | private final URI uri; |
| 34 | |
| 35 | private AlarmEntityId(final URI uri) { |
| 36 | this.uri = uri; |
| 37 | } |
| 38 | |
| 39 | protected AlarmEntityId() { |
| 40 | uri = NONE.uri; |
| 41 | } |
| 42 | |
| 43 | public static AlarmEntityId alarmEntityId(final String string) { |
| 44 | return alarmEntityId(URI.create(string)); |
| 45 | } |
| 46 | |
| 47 | public static AlarmEntityId alarmEntityId(final URI uri) { |
| 48 | checkArgument(SCHEMES.contains(uri.getScheme()), "Unexpected scheme"); |
| 49 | return new AlarmEntityId(uri); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public String toString() { |
| 54 | return uri.toString(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | return Objects.hash(uri); |
| 60 | |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(final Object obj) { |
| 65 | if (this == obj) { |
| 66 | return true; |
| 67 | } |
| 68 | if (obj instanceof AlarmEntityId) { |
| 69 | final AlarmEntityId other = (AlarmEntityId) obj; |
| 70 | return Objects.equals(this.uri, other.uri); |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | } |