KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > util > NumSeparators


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  * $Id
12  */

13 package com.tonbeller.jpivot.util;
14
15 import java.util.Locale JavaDoc;
16
17 /**
18  * Singleton
19  * Separators are needed for "inverse" cell formatting
20  * we assume, that the locale almost never changes
21  */

22 public class NumSeparators {
23   public int thouSep; // Thousand separator
24
public int decimalSep; // decimal separator
25
private Locale JavaDoc theLocale;
26   static private NumSeparators theInstance = null;
27
28   private NumSeparators(Locale JavaDoc locale) {
29     theLocale = locale;
30     thouSep = ',';
31     decimalSep = '.';
32     if (locale == null)
33       return;
34     if (locale.getLanguage() == "de" || locale.getCountry() == "DE") {
35       decimalSep = ',';
36       thouSep = '.';
37     } else if (locale.getLanguage() == "hu" || locale.getCountry() == "HU") {
38       decimalSep = ',';
39       thouSep = ' ';
40     }
41   }
42
43   static public NumSeparators instance(Locale JavaDoc locale) {
44     // probably it is always the same locale
45
if (theInstance == null)
46       return new NumSeparators(locale);
47     if (theInstance.theLocale == locale)
48       return theInstance;
49     if (locale != null && locale.equals(theInstance.theLocale)) { return theInstance; }
50     // this should not occur too often, as there should be only one locale
51
return new NumSeparators(locale);
52   }
53 } // NumSeparators
54
Popular Tags