| /* |
| * Copyright 2016-present Open Networking Laboratory |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package org.onosproject.nemo.model.object.match.item.definitions; |
| |
| import org.onosproject.nemo.model.common.MatchItemName; |
| |
| import static com.google.common.collect.ImmutableMap.builder; |
| |
| import java.util.Map; |
| |
| import com.google.common.collect.ImmutableMap.Builder; |
| |
| public interface MatchItemDefinition { |
| |
| |
| /** |
| * Returns the name of an match item. |
| * |
| * @return the match item name |
| */ |
| MatchItemName getMatchItemName(); |
| |
| /** |
| * Returns the type of a parameter value. |
| * |
| * @return the type |
| */ |
| MatchItemValueType getMatchItemValueType(); |
| |
| /** |
| * Returns the primary key of YANG type list. |
| * |
| * @return the match item definition key |
| */ |
| MatchItemDefinitionKey getKey(); |
| |
| /** |
| * Types of match item value. |
| */ |
| enum MatchItemValueType { |
| /** A string-valued match item. */ |
| STRING(0), |
| |
| /** An integer-valued match item. */ |
| INT(1), |
| |
| /** An integer-range match item. */ |
| RANGE(2); |
| |
| private static final Map<Integer, MatchItemValueType> VALUE_MAP; |
| |
| int code; |
| |
| MatchItemValueType(int value) { |
| this.code = value; |
| } |
| |
| /** |
| * Returns the code of this action definition. |
| * |
| * @return the code |
| */ |
| public int codeValue() { |
| return code; |
| } |
| |
| static { |
| Builder<Integer, MatchItemValueType> b = builder(); |
| for (MatchItemValueType enumItem : MatchItemValueType.values()) { |
| b.put(enumItem.code, enumItem); |
| } |
| VALUE_MAP = b.build(); |
| } |
| |
| /** |
| * Returns the type from the given match item code. |
| * |
| * @param code the given code |
| * @return corresponding type constant |
| * @throws IllegalArgumentException if there is no mapping |
| */ |
| public static MatchItemValueType forValue(int code) { |
| MatchItemValueType type = VALUE_MAP.get(code); |
| if (type == null) { |
| throw new IllegalArgumentException( |
| "No MatchItemType for value: " + code); |
| } |
| return type; |
| } |
| } |
| } |