Jian Li | 40f4d6c | 2017-12-14 00:07:21 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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.incubator.protobuf.models.net.meter; |
| 17 | |
| 18 | import org.onosproject.grpc.net.meter.models.BandEnumsProto; |
| 19 | import org.onosproject.net.meter.Band; |
| 20 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; |
| 22 | |
| 23 | import java.util.Optional; |
| 24 | |
| 25 | /** |
| 26 | * gRPC message conversion related utilities for band enums. |
| 27 | */ |
| 28 | public final class BandEnumsProtoTranslator { |
| 29 | |
| 30 | private static final Logger log = LoggerFactory.getLogger(BandEnumsProtoTranslator.class); |
| 31 | |
| 32 | /** |
| 33 | * Translates gRPC enum Band Type to ONOS enum. |
| 34 | * |
| 35 | * @param bandType BandType in gRPC enum |
| 36 | * @return equivalent in ONOS enum |
| 37 | */ |
Jian Li | 1aaa64d | 2017-12-14 11:25:39 +0900 | [diff] [blame] | 38 | public static Optional<Band.Type> translate(BandEnumsProto.BandTypeProto bandType) { |
Jian Li | 40f4d6c | 2017-12-14 00:07:21 +0900 | [diff] [blame] | 39 | switch (bandType) { |
| 40 | case DROP: |
| 41 | return Optional.of(Band.Type.DROP); |
| 42 | case REMARK: |
| 43 | return Optional.of(Band.Type.REMARK); |
| 44 | case EXPERIMENTAL: |
| 45 | return Optional.of(Band.Type.EXPERIMENTAL); |
| 46 | default: |
| 47 | log.warn("Unrecognized BandType gRPC message: {}", bandType); |
| 48 | return Optional.empty(); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // Utility class not intended for instantiation. |
| 53 | private BandEnumsProtoTranslator() {} |
| 54 | } |