1 /*
   2  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  *
  25  */
  26 
  27 package com.foo;
  28 
  29 import java.text.*;
  30 import java.text.spi.*;
  31 import java.util.*;
  32 
  33 import com.foobar.Utils;
  34 
  35 public class DecimalFormatSymbolsProviderImpl extends DecimalFormatSymbolsProvider {
  36 
  37     static Locale[] avail = {
  38         new Locale("ja", "JP", "osaka"),
  39         new Locale("ja", "JP", "kyoto"),
  40         Locale.JAPAN,
  41         new Locale("yy", "ZZ", "UUU")
  42     };
  43     static List<Locale> availList = Arrays.asList(avail);
  44 
  45     static String[] dialect = {
  46         "\u3084\u3002",
  47         "\u3069\u3059\u3002",
  48         "\u3067\u3059\u3002",
  49         "-yy-ZZ-UUU"
  50     };
  51 
  52     static HashMap<Locale, FooDecimalFormatSymbols> symbols = new HashMap<Locale, FooDecimalFormatSymbols>(4);
  53 
  54     public Locale[] getAvailableLocales() {
  55         return avail;
  56     }
  57 
  58     public DecimalFormatSymbols getInstance(Locale locale) {
  59         if (!Utils.supportsLocale(availList, locale)) {
  60             throw new IllegalArgumentException("locale is not supported: "+locale);
  61         }
  62 
  63         FooDecimalFormatSymbols fdfs = symbols.get(locale);
  64         if (fdfs == null) {
  65             for (int index = 0; index < avail.length; index ++) {
  66                 if (Utils.supportsLocale(avail[index], locale)) {
  67                     fdfs = new FooDecimalFormatSymbols(index);
  68                     symbols.put(locale, fdfs);
  69                     break;
  70                 }
  71             }
  72         }
  73         return fdfs;
  74     }
  75 
  76     class FooDecimalFormatSymbols extends DecimalFormatSymbols {
  77         String dialect = "";
  78 
  79         String infinity = null;
  80         String nan = null;
  81 
  82         public FooDecimalFormatSymbols(int index) {
  83             super(DecimalFormatSymbolsProviderImpl.this.avail[index]);
  84             dialect = DecimalFormatSymbolsProviderImpl.this.dialect[index];
  85         }
  86 
  87         // overrides methods only returns Strings
  88         public String getInfinity() {
  89             if (infinity == null) {
  90                 infinity = super.getInfinity() + dialect;
  91             }
  92             return infinity;
  93         }
  94 
  95         public void setInfinity(String infinity) {
  96             this.infinity = infinity;
  97         }
  98 
  99         public String getNaN() {
 100             if (nan == null) {
 101                 nan = super.getNaN() + dialect;
 102             }
 103             return nan;
 104         }
 105 
 106         public void setNaN(String nan) {
 107             this.nan = nan;
 108         }
 109     }
 110 }