blob: 6e78523fbef7aa51ad6a1cd0e409928400e4a0d2 [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
19import org.onosproject.ui.table.CellFormatter;
20import org.onosproject.ui.table.cell.AbstractCellFormatter;
21
22/**
23 * Formats a optical tunnel endpoint as "(type)/(element-id)/(port)".
24 * Formats a ip tunnel endpoint as "ip".
25 */
26public final class TunnelEndPointFormatter extends AbstractCellFormatter {
27 //non-instantiable
28 private TunnelEndPointFormatter() {
29 }
30
31 @Override
32 protected String nonNullFormat(Object value) {
33
34 if (value instanceof DefaultOpticalTunnelEndPoint) {
35 DefaultOpticalTunnelEndPoint cp = (DefaultOpticalTunnelEndPoint) value;
36 return cp.type() + "/" + cp.elementId().get() + "/" + cp.portNumber().get();
37 } else if (value instanceof IpTunnelEndPoint) {
38 IpTunnelEndPoint cp = (IpTunnelEndPoint) value;
39 return cp.ip().toString();
40 }
41 return "";
42 }
43
44 /**
45 * An instance of this class.
46 */
47 public static final CellFormatter INSTANCE = new TunnelEndPointFormatter();
48}