blob: 8ee4fe551ea8b8c56e26257f5dd047b1cabb234c [file] [log] [blame]
shivani vaidya9632b5f2017-06-27 11:00:04 -07001/*
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 */
16package org.onosproject.incubator.protobuf.models.net;
17
18import org.onosproject.grpc.net.models.ProviderIdProtoOuterClass;
19import org.onosproject.net.provider.ProviderId;
20
21/**
22 * gRPC ProviderId message to org.onosproject.net.provider.ProviderId conversion related utilities.
23 */
24public final class ProviderIdProtoTranslator {
25
26 /**
27 * Translates gRPC ProviderId message to {@link org.onosproject.net.provider.ProviderId}.
28 *
29 * @param providerId gRPC ProviderId message
30 * @return {@link org.onosproject.net.provider.ProviderId} or null if providerId is a default instance
31 */
32 public static ProviderId translate(ProviderIdProtoOuterClass.ProviderIdProto providerId) {
33 if (providerId.equals(ProviderIdProtoOuterClass.ProviderIdProto.getDefaultInstance())) {
34 return null;
35 }
36 return new ProviderId(providerId.getScheme(), providerId.getId(), providerId.getAncillary());
37 }
38
39 /**
40 * Translates {@link org.onosproject.net.provider.ProviderId} to gRPC ProviderId message.
41 *
42 * @param providerId {@link org.onosproject.net.provider.ProviderId}
43 * @return gRPC ProviderId message
44 */
45 public static ProviderIdProtoOuterClass.ProviderIdProto translate(ProviderId providerId) {
46 if (providerId == null) {
47 return ProviderIdProtoOuterClass.ProviderIdProto.getDefaultInstance();
48 }
49 return ProviderIdProtoOuterClass.ProviderIdProto.newBuilder()
50 .setScheme(providerId.scheme())
51 .setId(providerId.id())
52 .setAncillary(providerId.isAncillary())
53 .build();
54 }
55
56
57 // Utility class not intended for instantiation.
58 private ProviderIdProtoTranslator() {}
59
60}
61