blob: bd9f17655559d6b1f062d7323be1f53adae79057 [file] [log] [blame]
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -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
14 * limitations under the License.
15 */
16package org.onosproject.net.optical.device.port;
17
18import java.util.Optional;
19
20import org.onosproject.net.Port;
21import org.onosproject.net.optical.OchPort;
22import org.onosproject.net.optical.device.OchPortHelper;
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080023
24import com.google.common.annotations.Beta;
25
26/**
27 * {@link PortMapper} to handler {@link OchPort} translation.
28 */
29@Beta
30public class OchPortMapper extends AbstractPortMapper<OchPort> {
31
32 @Override
33 public boolean is(Port port) {
34 return port != null &&
35 port.type() == Port.Type.OCH &&
36 super.is(port);
37 }
38
39 @Override
40 public Optional<OchPort> as(Port port) {
41 if (port instanceof OchPort) {
42 return Optional.of((OchPort) port);
43 }
44 return super.as(port);
45 }
46
47 @Override
48 protected Optional<OchPort> mapPort(Port port) {
49 if (port instanceof OchPort) {
50 return Optional.of((OchPort) port);
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -080051 }
52
53 return OchPortHelper.asOchPort(port);
54 }
55}