blob: 76f4246606d422665b612e4ab05109b8449f2216 [file] [log] [blame]
Thomas Vachuska3ece3732015-09-22 23:58:50 -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 */
16
17package org.onosproject.ui.table.cell;
18
19import java.text.DecimalFormat;
20import java.text.NumberFormat;
21
22/**
23 * Formats number using the specified format string".
24 */
25public final class NumberFormatter extends AbstractCellFormatter {
26
27 private final NumberFormat format;
28
29 /**
30 * Creates a formatter using a default decimal format.
31 */
32 public NumberFormatter() {
33 this(new DecimalFormat("#,##0.00000"));
34 }
35
36 /**
37 * Creates a formatter using the specified format.
38 *
39 * @param format number format
40 */
41 public NumberFormatter(NumberFormat format) {
42 this.format = format;
43 }
44
45 @Override
46 protected String nonNullFormat(Object value) {
47 return format.format(value);
48 }
49
50}