Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
chengfan | 392e8f9 | 2015-08-21 13:20:02 -0500 | [diff] [blame] | 16 | package org.onosproject.incubator.net.tunnel; |
| 17 | |
| 18 | |
Thomas Vachuska | 4c571ae | 2015-09-10 16:31:59 -0700 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
chengfan | 392e8f9 | 2015-08-21 13:20:02 -0500 | [diff] [blame] | 20 | import org.onosproject.ui.table.CellFormatter; |
| 21 | import 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 Vachuska | 4c571ae | 2015-09-10 16:31:59 -0700 | [diff] [blame] | 27 | @Beta |
chengfan | 392e8f9 | 2015-08-21 13:20:02 -0500 | [diff] [blame] | 28 | public 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 | } |