blob: cc68876ef23d5c7199d92028b9dc7d4d0cb8d528 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska58de4162015-09-10 16:15:33 -07003 *
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 */
chengfan392e8f92015-08-21 13:20:02 -050016package org.onosproject.incubator.net.tunnel;
17
18
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070019import com.google.common.annotations.Beta;
chengfan392e8f92015-08-21 13:20:02 -050020import org.onosproject.ui.table.CellFormatter;
21import org.onosproject.ui.table.cell.AbstractCellFormatter;
22
Simon Huntb0582492016-09-20 18:26:38 -070023import java.util.Optional;
24
chengfan392e8f92015-08-21 13:20:02 -050025/**
Simon Huntb0582492016-09-20 18:26:38 -070026 * Formats an optical tunnel endpoint as "(type)/(element-id)/(port)".
27 * Formats an IP tunnel endpoint as "ip".
chengfan392e8f92015-08-21 13:20:02 -050028 */
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070029@Beta
chengfan392e8f92015-08-21 13:20:02 -050030public final class TunnelEndPointFormatter extends AbstractCellFormatter {
31 //non-instantiable
32 private TunnelEndPointFormatter() {
33 }
34
Simon Huntb0582492016-09-20 18:26:38 -070035 private String safeOptional(Optional<?> optional) {
36 return optional.isPresent() ? optional.get().toString() : QUERY;
37 }
38
chengfan392e8f92015-08-21 13:20:02 -050039 @Override
40 protected String nonNullFormat(Object value) {
41
42 if (value instanceof DefaultOpticalTunnelEndPoint) {
Simon Huntb0582492016-09-20 18:26:38 -070043 DefaultOpticalTunnelEndPoint ep =
44 (DefaultOpticalTunnelEndPoint) value;
45
46 String e = safeOptional(ep.elementId());
47 String p = safeOptional(ep.portNumber());
48 return ep.type() + SLASH + e + SLASH + p;
49
chengfan392e8f92015-08-21 13:20:02 -050050 } else if (value instanceof IpTunnelEndPoint) {
51 IpTunnelEndPoint cp = (IpTunnelEndPoint) value;
52 return cp.ip().toString();
53 }
Simon Huntb0582492016-09-20 18:26:38 -070054 return EMPTY;
chengfan392e8f92015-08-21 13:20:02 -050055 }
56
57 /**
58 * An instance of this class.
59 */
60 public static final CellFormatter INSTANCE = new TunnelEndPointFormatter();
61}