Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [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 | |
| 17 | package org.onosproject.net; |
| 18 | |
| 19 | public enum EncapsulationType { |
| 20 | /** |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 21 | * Indicates no encapsulation. |
| 22 | */ |
| 23 | NONE, |
| 24 | /** |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 25 | * Indicates an MPLS encapsulation. |
| 26 | */ |
| 27 | MPLS, |
| 28 | /** |
| 29 | * Indicates a VLAN encapsulation. |
| 30 | */ |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 31 | VLAN; |
Michele Santuari | 02e47a4 | 2015-11-23 16:54:51 +0100 | [diff] [blame] | 32 | |
Luca Prete | 092e895 | 2016-10-26 16:25:56 +0200 | [diff] [blame] | 33 | /** |
| 34 | * Alternative method to valueOf. It returns the encapsulation type constant |
| 35 | * corresponding to the given string. If the parameter does not match a |
| 36 | * constant name, or is null, {@link #NONE} is returned. |
| 37 | * |
| 38 | * @param encap the string representing the encapsulation type |
| 39 | * @return the EncapsulationType constant corresponding to the string given |
| 40 | */ |
| 41 | public static EncapsulationType enumFromString(String encap) { |
| 42 | // Return EncapsulationType.NONE if the value is not found, or if null |
| 43 | // or an empty string are given |
| 44 | EncapsulationType type = NONE; |
| 45 | if (encap != null && !encap.isEmpty()) { |
| 46 | for (EncapsulationType t : values()) { |
| 47 | if (encap.equalsIgnoreCase(t.toString())) { |
| 48 | type = valueOf(encap.toUpperCase()); |
| 49 | break; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | return type; |
| 54 | } |
| 55 | } |