blob: 57af670c8b4792b487fa7c8cf4c7201a1857ab4a [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
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
23/**
24 * Formats a optical tunnel endpoint as "(type)/(element-id)/(port)".
25 * Formats a ip tunnel endpoint as "ip".
26 */
Thomas Vachuska4c571ae2015-09-10 16:31:59 -070027@Beta
chengfan392e8f92015-08-21 13:20:02 -050028public final class TunnelEndPointFormatter extends AbstractCellFormatter {
29 //non-instantiable
30 private TunnelEndPointFormatter() {
31 }
32
33 @Override
34 protected String nonNullFormat(Object value) {
35
36 if (value instanceof DefaultOpticalTunnelEndPoint) {
37 DefaultOpticalTunnelEndPoint cp = (DefaultOpticalTunnelEndPoint) value;
38 return cp.type() + "/" + cp.elementId().get() + "/" + cp.portNumber().get();
39 } else if (value instanceof IpTunnelEndPoint) {
40 IpTunnelEndPoint cp = (IpTunnelEndPoint) value;
41 return cp.ip().toString();
42 }
43 return "";
44 }
45
46 /**
47 * An instance of this class.
48 */
49 public static final CellFormatter INSTANCE = new TunnelEndPointFormatter();
50}