mohamed rahil | 8ea09d4 | 2016-04-19 20:47:21 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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.isis.controller; |
| 17 | |
| 18 | import java.util.EnumSet; |
| 19 | import java.util.HashMap; |
| 20 | import java.util.Map; |
| 21 | |
| 22 | /** |
| 23 | * Enum represents ISIS Interface state. |
| 24 | */ |
| 25 | public enum IsisInterfaceState { |
| 26 | /** |
| 27 | * Represents interface is in "up" state. |
| 28 | */ |
| 29 | UP(0), |
| 30 | /** |
| 31 | * Represents interface is in "initial" state. |
| 32 | */ |
| 33 | INITIAL(1), |
| 34 | /** |
| 35 | * Represents interface is in "down" state. |
| 36 | */ |
| 37 | DOWN(2); |
| 38 | |
| 39 | // Reverse lookup table |
| 40 | private static final Map<Integer, IsisInterfaceState> LOOKUP = new HashMap<>(); |
| 41 | |
| 42 | // Populate the lookup table on loading time |
| 43 | static { |
| 44 | for (IsisInterfaceState isisInterfaceState : EnumSet.allOf(IsisInterfaceState.class)) { |
| 45 | LOOKUP.put(isisInterfaceState.value(), isisInterfaceState); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | private int value; |
| 50 | |
| 51 | /** |
| 52 | * Creates an instance of ISIS interface type. |
| 53 | * |
| 54 | * @param value represents ISIS interface type |
| 55 | */ |
| 56 | private IsisInterfaceState(int value) { |
| 57 | this.value = value; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Gets the enum instance from type value - reverse lookup purpose. |
| 62 | * |
| 63 | * @param interfaceStateTypeValue interface state type value |
| 64 | * @return ISIS interface state type instance |
| 65 | */ |
| 66 | public static IsisInterfaceState get(int interfaceStateTypeValue) { |
| 67 | return LOOKUP.get(interfaceStateTypeValue); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Gets the value representing interface state type. |
| 72 | * |
| 73 | * @return value represents interface state type |
| 74 | */ |
| 75 | public int value() { |
| 76 | return value; |
| 77 | } |
| 78 | } |