mohamed rahil | 8ea09d4 | 2016-04-19 20:47:21 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
mohamed rahil | 8ea09d4 | 2016-04-19 20:47:21 +0530 | [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.isis.controller; |
| 17 | |
| 18 | import java.util.EnumSet; |
| 19 | import java.util.HashMap; |
| 20 | import java.util.Map; |
| 21 | |
| 22 | /** |
| 23 | * Represents ISIS network types. |
| 24 | */ |
| 25 | public enum IsisNetworkType { |
| 26 | /** |
| 27 | * Represents point-to-point network. |
| 28 | */ |
| 29 | P2P(1), |
| 30 | /** |
| 31 | * Represents broadcast network. |
| 32 | */ |
| 33 | BROADCAST(2); |
| 34 | // Reverse lookup table |
| 35 | private static final Map<Integer, IsisNetworkType> LOOKUP = new HashMap<>(); |
| 36 | |
| 37 | // Populate the lookup table on loading time |
| 38 | static { |
| 39 | for (IsisNetworkType isisNetworkType : EnumSet.allOf(IsisNetworkType.class)) { |
| 40 | LOOKUP.put(isisNetworkType.value(), isisNetworkType); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | private int value; |
| 45 | |
mohamed rahil | 8ea09d4 | 2016-04-19 20:47:21 +0530 | [diff] [blame] | 46 | /** |
| 47 | * Creates an instance of ISIS network type. |
| 48 | * |
| 49 | * @param value represents ISIS network type |
| 50 | */ |
| 51 | private IsisNetworkType(int value) { |
| 52 | this.value = value; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Gets the enum instance from type value - reverse lookup purpose. |
| 57 | * |
| 58 | * @param isisNetworkTypeValue interface network type value |
| 59 | * @return ISIS interface network type instance |
| 60 | */ |
| 61 | public static IsisNetworkType get(int isisNetworkTypeValue) { |
| 62 | return LOOKUP.get(isisNetworkTypeValue); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Gets the value representing network type. |
| 67 | * |
| 68 | * @return value represents network type |
| 69 | */ |
| 70 | public int value() { |
| 71 | return value; |
| 72 | } |
| 73 | } |