From: Leif Åstrand Date: Wed, 23 Jul 2014 10:02:04 +0000 (+0300) Subject: Use NumberFormat instead of DecimalFormat for NumberRenderer (#13334) X-Git-Tag: 7.4.0.beta1~9^2~189^2~54^2~48 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4f17b069a7db5213901d1f99291d8d56da96ddad;p=vaadin-framework.git Use NumberFormat instead of DecimalFormat for NumberRenderer (#13334) Change-Id: I3f3b2b7d036fc53fd3466a9fe5e8b8fe03cf4204 --- diff --git a/server/src/com/vaadin/ui/components/grid/renderers/NumberRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/NumberRenderer.java index 0d1c98d6dc..12fcfc890a 100644 --- a/server/src/com/vaadin/ui/components/grid/renderers/NumberRenderer.java +++ b/server/src/com/vaadin/ui/components/grid/renderers/NumberRenderer.java @@ -15,7 +15,7 @@ */ package com.vaadin.ui.components.grid.renderers; -import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.Locale; import com.vaadin.ui.components.grid.AbstractRenderer; @@ -28,7 +28,7 @@ import com.vaadin.ui.components.grid.AbstractRenderer; */ public class NumberRenderer extends AbstractRenderer { private final Locale locale; - private final DecimalFormat decimalFormat; + private final NumberFormat numberFormat; private final String formatString; /** @@ -45,23 +45,23 @@ public class NumberRenderer extends AbstractRenderer { * Creates a new number renderer. *

* The renderer is configured to render the number as defined with the given - * decimal format. + * number format. * - * @param decimalFormat - * the decimal format with which to display numbers + * @param numberFormat + * the number format with which to display numbers * @throws IllegalArgumentException - * if {@code decimalFormat} is {@code null} + * if {@code numberFormat} is {@code null} */ - public NumberRenderer(DecimalFormat decimalFormat) + public NumberRenderer(NumberFormat numberFormat) throws IllegalArgumentException { super(Number.class); - if (decimalFormat == null) { - throw new IllegalArgumentException("Decimal format may not be null"); + if (numberFormat == null) { + throw new IllegalArgumentException("Number format may not be null"); } locale = null; - this.decimalFormat = decimalFormat; + this.numberFormat = numberFormat; formatString = null; } @@ -126,7 +126,7 @@ public class NumberRenderer extends AbstractRenderer { } this.locale = locale; - decimalFormat = null; + numberFormat = null; this.formatString = formatString; } @@ -134,13 +134,13 @@ public class NumberRenderer extends AbstractRenderer { public String encode(Number value) { if (formatString != null && locale != null) { return String.format(locale, formatString, value); - } else if (decimalFormat != null) { - return decimalFormat.format(value); + } else if (numberFormat != null) { + return numberFormat.format(value); } else { throw new IllegalStateException(String.format("Internal bug: " + "%s is in an illegal state: " - + "[locale: %s, decimalFormat: %s, formatString: %s]", - getClass().getSimpleName(), locale, decimalFormat, + + "[locale: %s, numberFormat: %s, formatString: %s]", + getClass().getSimpleName(), locale, numberFormat, formatString)); } } @@ -148,8 +148,8 @@ public class NumberRenderer extends AbstractRenderer { @Override public String toString() { final String fieldInfo; - if (decimalFormat != null) { - fieldInfo = "decimalFormat: " + decimalFormat.toString(); + if (numberFormat != null) { + fieldInfo = "numberFormat: " + numberFormat.toString(); } else { fieldInfo = "locale: " + locale + ", formatString: " + formatString; }