Simon Hunt | 3ee7f74 | 2015-05-05 10:18:20 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | 3ee7f74 | 2015-05-05 10:18:20 -0700 | [diff] [blame] | 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. |
Simon Hunt | 3ee7f74 | 2015-05-05 10:18:20 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.table.cell; |
| 18 | |
| 19 | import org.onosproject.ui.table.CellFormatter; |
| 20 | |
| 21 | /** |
| 22 | * Base implementation of a {@link CellFormatter}. This class takes care of |
| 23 | * dealing with null inputs; subclasses should implement their format method |
| 24 | * knowing that the input is guaranteed to be non-null. |
| 25 | */ |
| 26 | public abstract class AbstractCellFormatter implements CellFormatter { |
| 27 | |
Simon Hunt | b058249 | 2016-09-20 18:26:38 -0700 | [diff] [blame] | 28 | protected static final String EMPTY = ""; |
| 29 | protected static final String SLASH = "/"; |
| 30 | protected static final String QUERY = "?"; |
| 31 | protected static final String UNDERSCORE = "_"; |
| 32 | protected static final String SPACE = " "; |
| 33 | protected static final String OX = "0x"; |
| 34 | |
| 35 | |
Simon Hunt | 3ee7f74 | 2015-05-05 10:18:20 -0700 | [diff] [blame] | 36 | @Override |
| 37 | public String format(Object value) { |
Simon Hunt | b058249 | 2016-09-20 18:26:38 -0700 | [diff] [blame] | 38 | return value == null ? EMPTY : nonNullFormat(value); |
Simon Hunt | 3ee7f74 | 2015-05-05 10:18:20 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Formats the specified value into a string appropriate for displaying |
| 43 | * in a table cell. Note that value is guaranteed to be non-null. |
| 44 | * |
| 45 | * @param value the value |
| 46 | * @return the formatted string |
| 47 | */ |
| 48 | protected abstract String nonNullFormat(Object value); |
| 49 | } |