blob: 9191353ea31f01bd44b1bf40487ffd3134eabc4e [file] [log] [blame]
Luca Pretedce16f82016-11-22 13:11:56 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Luca Pretedce16f82016-11-22 13:11:56 -08003 *
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
Luca Prete99f6f282016-12-05 15:33:36 -080014 * limitations under the License.
Luca Pretedce16f82016-11-22 13:11:56 -080015 */
16package org.onosproject.vpls.cli;
17
18import java.util.ArrayList;
19import java.util.Arrays;
20import java.util.List;
21import java.util.stream.Collectors;
22
23/**
24 * Enum representing the VPLS command type.
25 */
26public enum VplsCommandEnum {
27 ADD_IFACE("add-if"),
Luca Pretedce16f82016-11-22 13:11:56 -080028 CREATE("create"),
29 DELETE("delete"),
30 LIST("list"),
31 REMOVE_IFACE("rem-if"),
32 SET_ENCAP("set-encap"),
Yi Tsengf4e13e32017-03-30 15:38:39 -070033 SHOW("show"),
34 CLEAN("clean");
Luca Pretedce16f82016-11-22 13:11:56 -080035
36 private final String command;
37
38 /**
39 * Creates the enum from a string representing the command.
40 *
41 * @param command the text representing the command
42 */
Yi Tsengf4e13e32017-03-30 15:38:39 -070043 VplsCommandEnum(final String command) {
Luca Pretedce16f82016-11-22 13:11:56 -080044 this.command = command;
45 }
46
47 @Override
48 public String toString() {
49 return command;
50 }
51
52 /**
53 * Returns a list of command string values.
54 *
55 * @return the list of string values corresponding to the enums
56 */
57 public static List<String> toStringList() {
58 return Arrays.stream(values())
Yi Tsengf4e13e32017-03-30 15:38:39 -070059 .map(VplsCommandEnum::toString)
Luca Pretedce16f82016-11-22 13:11:56 -080060 .collect(Collectors.toCollection(ArrayList::new));
61 }
62
63 /**
64 * Alternative method to valueOf. It returns the command type
65 * corresponding to the given string. If the parameter does not match a
66 * constant name, or is null, null is returned.
67 *
68 * @param command the string representing the encapsulation type
69 * @return the EncapsulationType constant corresponding to the string given
70 */
71 public static VplsCommandEnum enumFromString(String command) {
72 if (command != null && !command.isEmpty()) {
73 for (VplsCommandEnum c : values()) {
Yi Tsengf4e13e32017-03-30 15:38:39 -070074 if (command.equalsIgnoreCase(c.toString())) {
Luca Pretedce16f82016-11-22 13:11:56 -080075 return c;
76 }
77 }
78 }
79 return null;
80 }
81}