anjiaqi1234567 | 6e05f9c | 2016-10-31 20:58:40 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 23c7e32 | 2017-08-03 18:48:27 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Foundation |
anjiaqi1234567 | 6e05f9c | 2016-10-31 20:58:40 +0800 | [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.nemo.model.operation.condition.parameter.definitions; |
| 17 | |
| 18 | import static com.google.common.collect.ImmutableMap.builder; |
| 19 | |
| 20 | import java.util.Map; |
| 21 | |
| 22 | import org.onosproject.nemo.model.common.ParameterName; |
| 23 | import org.onosproject.nemo.model.operation.condition.parameter.definitions.condition.parameter.definition.ParameterMatchPatterns; |
| 24 | |
| 25 | import com.google.common.collect.ImmutableMap.Builder; |
| 26 | |
| 27 | /** |
| 28 | * The definition of a condition parameter. |
| 29 | */ |
| 30 | public interface ConditionParameterDefinition { |
| 31 | |
| 32 | /** |
| 33 | * Returns the name of an parameter definition. |
| 34 | * |
| 35 | * @return the parameter name |
| 36 | */ |
| 37 | ParameterName getParameterName(); |
| 38 | |
| 39 | /** |
| 40 | * Returns the type of a parameter value. |
| 41 | * |
| 42 | * @return the type |
| 43 | */ |
| 44 | ParameterValueType getParameterValueType(); |
| 45 | |
| 46 | /** |
| 47 | * Returns the parameter match patterns. |
| 48 | * |
| 49 | * @return the patterns |
| 50 | */ |
| 51 | ParameterMatchPatterns getParameterMatchPatterns(); |
| 52 | |
| 53 | /** |
| 54 | * Returns the primary key of YANG type list. |
| 55 | * |
| 56 | * @return the action definition key |
| 57 | */ |
| 58 | ConditionParameterDefinitionKey getKey(); |
| 59 | |
| 60 | /** |
| 61 | * Types of parameter value. |
| 62 | */ |
| 63 | enum ParameterValueType { |
| 64 | /** A string-valued parameter. */ |
| 65 | STRING(0), |
| 66 | |
| 67 | /** An integer-valued parameter. */ |
| 68 | INT(1), |
| 69 | |
| 70 | /** An integer-range parameter. */ |
| 71 | RANGE(2); |
| 72 | |
| 73 | private static final Map<Integer, ParameterValueType> VALUE_MAP; |
| 74 | |
| 75 | int value; |
| 76 | |
| 77 | ParameterValueType(int value) { |
| 78 | this.value = value; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Returns the value of this definition. |
| 83 | * |
| 84 | * @return the value |
| 85 | */ |
| 86 | public int getIntValue() { |
| 87 | return value; |
| 88 | } |
| 89 | |
| 90 | static { |
| 91 | Builder<Integer, ParameterValueType> b = builder(); |
| 92 | for (ParameterValueType enumItem : ParameterValueType.values()) { |
| 93 | b.put(enumItem.value, enumItem); |
| 94 | } |
| 95 | VALUE_MAP = b.build(); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Returns the type from the given value. |
| 100 | * |
| 101 | * @param value the given value |
| 102 | * @return corresponding type constant |
| 103 | * @throws IllegalArgumentException if there is no mapping |
| 104 | */ |
| 105 | public static ParameterValueType forValue(int value) { |
| 106 | ParameterValueType type = VALUE_MAP.get(value); |
| 107 | if (type == null) { |
| 108 | throw new IllegalArgumentException(); |
| 109 | } |
| 110 | return type; |
| 111 | } |
| 112 | } |
| 113 | } |