--- old/make/java/java/Makefile Wed Nov 25 14:18:28 2009 +++ new/make/java/java/Makefile Wed Nov 25 14:18:27 2009 @@ -390,7 +390,7 @@ LOCALES_GEN_SH = localelist.sh $(GENSRCDIR)/sun/util/CoreResourceBundleControl.java: \ - $(SHARE_SRC)/classes/sun/util/CoreResourceBundleControl-XLocales.java $(LOCALES_GEN_SH) + $(SHARE_SRC)/classes/sun/util/CoreResourceBundleControl-XLocales.java.template $(LOCALES_GEN_SH) @$(prep-target) NAWK="$(NAWK)" SED="$(SED)" $(SH) $(LOCALES_GEN_SH) "$(JRE_NONEXIST_LOCALES)" \ $< $@ --- old/make/java/java/genlocales.gmk Wed Nov 25 14:18:28 2009 +++ new/make/java/java/genlocales.gmk Wed Nov 25 14:18:28 2009 @@ -68,7 +68,7 @@ FILES_java := $(FILES_java_orig) FILES_compiled_properties := $(FILES_compiled_properties_orig) -LocaleDataMetaInfo_Src=$(SHARE_SRC)/classes/sun/util/LocaleDataMetaInfo-XLocales.java +LocaleDataMetaInfo_Src=$(SHARE_SRC)/classes/sun/util/LocaleDataMetaInfo-XLocales.java.template LocaleDataMetaInfo_Dest=$(GENSRCDIR)/sun/util/LocaleDataMetaInfo.java LOCALEGEN_SH=localegen.sh RESOURCE_NAMES="FormatData CollationData TimeZoneNames LocaleNames CurrencyNames CalendarData" --- old/make/java/java/localegen.sh Wed Nov 25 14:18:29 2009 +++ new/make/java/java/localegen.sh Wed Nov 25 14:18:29 2009 @@ -27,7 +27,7 @@ # # This script is to generate the supported locale list string and replace the -# LocaleDataMetaInfo-XLocales.java in /src/share/classes/sun/util +# LocaleDataMetaInfo-XLocales.java.template in /src/share/classes/sun/util # # SORT, NAWK & SED is passed in as environment variables. # --- old/make/java/nio/Makefile Wed Nov 25 14:18:30 2009 +++ new/make/java/nio/Makefile Wed Nov 25 14:18:30 2009 @@ -834,7 +834,7 @@ GENCSSRC = $(BUILDDIR)/tools/CharsetMapping CHARSETMAPPING_JARFILE = $(BUILDTOOLJARDIR)/charsetmapping.jar -$(FILES_gensbcs_out): $(GENCSSRC)/SingleByte-X.java $(GENCSSRC)/sbcs +$(FILES_gensbcs_out): $(GENCSSRC)/SingleByte-X.java.template $(GENCSSRC)/sbcs @$(prep-target) $(BOOT_JAVA_CMD) -jar $(CHARSETMAPPING_JARFILE) $(GENCSSRC) $(SCS_GEN) sbcs --- old/make/netbeans/README Wed Nov 25 14:18:31 2009 +++ new/make/netbeans/README Wed Nov 25 14:18:30 2009 @@ -411,7 +411,7 @@ java/util/regex/,\ java/util/spi/,\ java/util/zip/,\ - **/*-XLocales.java + **/*-XLocales.java.template jtreg.tests=\ java/util/**/*Collection/ \ java/util/**/*Map/ \ --- old/make/sun/nio/Makefile Wed Nov 25 14:18:31 2009 +++ new/make/sun/nio/Makefile Wed Nov 25 14:18:31 2009 @@ -82,7 +82,9 @@ $(FILES_MAP) $(FILES_DAT) sjis0213 -$(FILES_genout_extcs): $(GENCSDATASRC)/SingleByte-X.java $(GENCSDATASRC)/DoubleByte-X.java \ +$(FILES_genout_extcs): \ + $(GENCSDATASRC)/SingleByte-X.java.template \ + $(GENCSDATASRC)/DoubleByte-X.java.template \ $(GENCSDATASRC)/extsbcs $(GENCSDATASRC)/dbcs @$(prep-target) $(RM) -r $(GENCSEXT) --- old/make/tools/src/build/tools/charsetmapping/GenerateDBCS.java Wed Nov 25 14:18:32 2009 +++ new/make/tools/src/build/tools/charsetmapping/GenerateDBCS.java Wed Nov 25 14:18:32 2009 @@ -63,7 +63,7 @@ int b2Min = toInteger(fields[8]); int b2Max = toInteger(fields[9]); System.out.printf("%s,%s,%s,%b,%s%n", clzName, csName, hisName, isASCII, pkgName); - genClass(args[0], args[1], "DoubleByte-X.java", + genClass(args[0], args[1], "DoubleByte-X.java.template", clzName, csName, hisName, pkgName, isASCII, type, b1Min, b1Max, b2Min, b2Max); --- old/make/tools/src/build/tools/charsetmapping/GenerateSBCS.java Wed Nov 25 14:18:33 2009 +++ new/make/tools/src/build/tools/charsetmapping/GenerateSBCS.java Wed Nov 25 14:18:33 2009 @@ -55,7 +55,7 @@ String pkgName = fields[4]; System.out.printf("%s,%s,%s,%b,%s%n", clzName, csName, hisName, isASCII, pkgName); - genClass(args[0], args[1], "SingleByte-X.java", + genClass(args[0], args[1], "SingleByte-X.java.template", clzName, csName, hisName, pkgName, isASCII); } } --- old/test/java/util/Formatter/genBasic.sh Wed Nov 25 14:18:34 2009 +++ new/test/java/util/Formatter/genBasic.sh Wed Nov 25 14:18:33 2009 @@ -27,10 +27,10 @@ gen() { # if [ $3 = "true" ] -# then $SPP -K$1 -Dtype=$1 -DType=$2 -KprimBasic$2.java -# else $SPP -K$1 -Dtype=$1 -DType=$2 -K$3 Basic$2.java +# then $SPP -K$1 -Dtype=$1 -DType=$2 -KprimBasic$2.java +# else $SPP -K$1 -Dtype=$1 -DType=$2 -K$3 Basic$2.java # fi - java build.tools.spp.Spp -K$1 -Dtype=$1 -DType=$2 -K$3 -K$4 -K$5 -K$6 Basic$2.java + java build.tools.spp.Spp -K$1 -Dtype=$1 -DType=$2 -K$3 -K$4 -K$5 -K$6 Basic$2.java } gen boolean Boolean prim "" "" "" --- old/make/tools/CharsetMapping/DoubleByte-X.java Wed Nov 25 14:18:34 2009 +++ /dev/null Wed Nov 25 14:18:34 2009 @@ -1,100 +0,0 @@ -/* - * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -// -- This file was mechanically generated: Do not edit! -- // - -package $PACKAGE$; - -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; -import java.util.Arrays; -import sun.nio.cs.HistoricallyNamedCharset; -import sun.nio.cs.ext.DoubleByte; - -public class $NAME_CLZ$ extends Charset - $IMPLEMENTS$ -{ - public $NAME_CLZ$() { - super("$NAME_CS$", $NAME_ALIASES$); - } - - $HISTORICALNAME$ - - public boolean contains(Charset cs) { - $CONTAINS$ - } - - public CharsetDecoder newDecoder() { - initb2c(); - return new DoubleByte.Decoder$DECTYPE$(this, b2c, b2cSB, $B2MIN$, $B2MAX$); - } - - public CharsetEncoder newEncoder() { - initc2b(); - return new DoubleByte.Encoder$ENCTYPE$(this, c2b, c2bIndex); - } - - $B2C$ - static char[][] b2c = new char[b2cStr.length][]; - static char[] b2cSB; - private static volatile boolean b2cInitialized = false; - - static void initb2c() { - if (b2cInitialized) - return; - synchronized (b2c) { - if (b2cInitialized) - return; - for (int i = 0; i < b2cStr.length; i++) { - if (b2cStr[i] == null) - b2c[i] = DoubleByte.B2C_UNMAPPABLE; - else - b2c[i] = b2cStr[i].toCharArray(); - } - b2cSB = b2cSBStr.toCharArray(); - b2cInitialized = true; - } - } - - static char[] c2b = new char[$C2BLENGTH$]; - static char[] c2bIndex = new char[0x100]; - private static volatile boolean c2bInitialized = false; - - static void initc2b() { - if (c2bInitialized) - return; - synchronized (c2b) { - if (c2bInitialized) - return; - $NONROUNDTRIP_B2C$ - $NONROUNDTRIP_C2B$ - DoubleByte.Encoder.initC2B(b2cStr, b2cSBStr, b2cNR, c2bNR, - $B2MIN$, $B2MAX$, - c2b, c2bIndex); - c2bInitialized = true; - } - } -} --- /dev/null Wed Nov 25 14:18:34 2009 +++ new/make/tools/CharsetMapping/DoubleByte-X.java.template Wed Nov 25 14:18:34 2009 @@ -0,0 +1,100 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +// -- This file was mechanically generated: Do not edit! -- // + +package $PACKAGE$; + +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import java.util.Arrays; +import sun.nio.cs.HistoricallyNamedCharset; +import sun.nio.cs.ext.DoubleByte; + +public class $NAME_CLZ$ extends Charset + $IMPLEMENTS$ +{ + public $NAME_CLZ$() { + super("$NAME_CS$", $NAME_ALIASES$); + } + + $HISTORICALNAME$ + + public boolean contains(Charset cs) { + $CONTAINS$ + } + + public CharsetDecoder newDecoder() { + initb2c(); + return new DoubleByte.Decoder$DECTYPE$(this, b2c, b2cSB, $B2MIN$, $B2MAX$); + } + + public CharsetEncoder newEncoder() { + initc2b(); + return new DoubleByte.Encoder$ENCTYPE$(this, c2b, c2bIndex); + } + + $B2C$ + static char[][] b2c = new char[b2cStr.length][]; + static char[] b2cSB; + private static volatile boolean b2cInitialized = false; + + static void initb2c() { + if (b2cInitialized) + return; + synchronized (b2c) { + if (b2cInitialized) + return; + for (int i = 0; i < b2cStr.length; i++) { + if (b2cStr[i] == null) + b2c[i] = DoubleByte.B2C_UNMAPPABLE; + else + b2c[i] = b2cStr[i].toCharArray(); + } + b2cSB = b2cSBStr.toCharArray(); + b2cInitialized = true; + } + } + + static char[] c2b = new char[$C2BLENGTH$]; + static char[] c2bIndex = new char[0x100]; + private static volatile boolean c2bInitialized = false; + + static void initc2b() { + if (c2bInitialized) + return; + synchronized (c2b) { + if (c2bInitialized) + return; + $NONROUNDTRIP_B2C$ + $NONROUNDTRIP_C2B$ + DoubleByte.Encoder.initC2B(b2cStr, b2cSBStr, b2cNR, c2bNR, + $B2MIN$, $B2MAX$, + c2b, c2bIndex); + c2bInitialized = true; + } + } +} --- old/make/tools/CharsetMapping/SingleByte-X.java Wed Nov 25 14:18:35 2009 +++ /dev/null Wed Nov 25 14:18:35 2009 @@ -1,83 +0,0 @@ -/* - * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -package $PACKAGE$; - -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CharsetEncoder; -import sun.nio.cs.StandardCharsets; -import sun.nio.cs.SingleByte; -import sun.nio.cs.HistoricallyNamedCharset; -import static sun.nio.cs.CharsetMapping.*; - -public class $NAME_CLZ$ extends Charset implements HistoricallyNamedCharset -{ - public $NAME_CLZ$() { - super("$NAME_CS$", $NAME_ALIASES$); - } - - public String historicalName() { - return "$NAME_HIS$"; - } - - public boolean contains(Charset cs) { - $CONTAINS$; - } - - public CharsetDecoder newDecoder() { - return new SingleByte.Decoder(this, b2c); - } - - public CharsetEncoder newEncoder() { - return new SingleByte.Encoder(this, c2b, c2bIndex); - } - - public String getDecoderSingleByteMappings() { - return b2cTable; - } - - public char[] getEncoderIndex2() { - return c2b; - } - - public char[] getEncoderIndex1() { - return c2bIndex; - } - - private final static String b2cTable = $B2CTABLE$ - - private final static char[] b2c = b2cTable.toCharArray(); - private final static char[] c2b = new char[$C2BLENGTH$]; - private final static char[] c2bIndex = new char[0x100]; - - static { - char[] b2cMap = b2c; - char[] c2bNR = null; - $NONROUNDTRIP_B2C$ - $NONROUNDTRIP_C2B$ - SingleByte.initC2B(b2cMap, c2bNR, c2b, c2bIndex); - } -} --- /dev/null Wed Nov 25 14:18:35 2009 +++ new/make/tools/CharsetMapping/SingleByte-X.java.template Wed Nov 25 14:18:35 2009 @@ -0,0 +1,83 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package $PACKAGE$; + +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import sun.nio.cs.StandardCharsets; +import sun.nio.cs.SingleByte; +import sun.nio.cs.HistoricallyNamedCharset; +import static sun.nio.cs.CharsetMapping.*; + +public class $NAME_CLZ$ extends Charset implements HistoricallyNamedCharset +{ + public $NAME_CLZ$() { + super("$NAME_CS$", $NAME_ALIASES$); + } + + public String historicalName() { + return "$NAME_HIS$"; + } + + public boolean contains(Charset cs) { + $CONTAINS$; + } + + public CharsetDecoder newDecoder() { + return new SingleByte.Decoder(this, b2c); + } + + public CharsetEncoder newEncoder() { + return new SingleByte.Encoder(this, c2b, c2bIndex); + } + + public String getDecoderSingleByteMappings() { + return b2cTable; + } + + public char[] getEncoderIndex2() { + return c2b; + } + + public char[] getEncoderIndex1() { + return c2bIndex; + } + + private final static String b2cTable = $B2CTABLE$ + + private final static char[] b2c = b2cTable.toCharArray(); + private final static char[] c2b = new char[$C2BLENGTH$]; + private final static char[] c2bIndex = new char[0x100]; + + static { + char[] b2cMap = b2c; + char[] c2bNR = null; + $NONROUNDTRIP_B2C$ + $NONROUNDTRIP_C2B$ + SingleByte.initC2B(b2cMap, c2bNR, c2b, c2bIndex); + } +} --- old/src/share/classes/sun/util/CoreResourceBundleControl-XLocales.java Wed Nov 25 14:18:35 2009 +++ /dev/null Wed Nov 25 14:18:35 2009 @@ -1,114 +0,0 @@ -/* - * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -#warn This file is preprocessed before being compiled - -package sun.util; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.ResourceBundle; -import java.util.ResourceBundle.Control; - -/** - * This is a convenient class for loading some of internal resources faster - * if they are built with Resources.gmk defined in J2SE workspace. Also, - * they have to be in class file format. - * - * "LOCALE_LIST" will be replaced at built time by a list of locales we - * defined in Defs.gmk. We want to exclude these locales from search to - * gain better performance. For example, since we know if the resource - * is built with Resources.gmk, they are not going to provide basename_en.class - * & basename_en_US.class resources, in that case, continuing searching them - * is expensive. By excluding them from the candidate locale list, these - * resources won't be searched. - * - * @since 1.6. - */ -public class CoreResourceBundleControl extends ResourceBundle.Control { - /* the candidate locale list to search */ - private final Collection excludedJDKLocales; - /* singlton instance of the resource bundle control. */ - private static CoreResourceBundleControl resourceBundleControlInstance = - new CoreResourceBundleControl(); - - protected CoreResourceBundleControl() { - excludedJDKLocales = Arrays.asList(#LOCALE_LIST#); - } - - /** - * This method is to provide a customized ResourceBundle.Control to speed - * up the search of resources in JDK. - * - * @return the instance of resource bundle control. - */ - public static CoreResourceBundleControl getRBControlInstance() { - return resourceBundleControlInstance; - } - - /** - * This method is to provide a customized ResourceBundle.Control to speed - * up the search of resources in JDK, with the bundle's package name check. - * - * @param bundleName bundle name to check - * @return the instance of resource bundle control if the bundle is JDK's, - * otherwise returns null. - */ - public static CoreResourceBundleControl getRBControlInstance(String bundleName) { - if (bundleName.startsWith("com.sun.") || - bundleName.startsWith("java.") || - bundleName.startsWith("javax.") || - bundleName.startsWith("sun.")) { - return resourceBundleControlInstance; - } else { - return null; - } - } - - /** - * @returns a list of candidate locales to search from. - * @exception NullPointerException if baseName or locale is null. - */ - @Override - public List getCandidateLocales(String baseName, Locale locale) { - List candidates = super.getCandidateLocales(baseName, locale); - candidates.removeAll(excludedJDKLocales); - return candidates; - } - - /** - * @ returns TTL_DONT_CACHE so that ResourceBundle instance won't be cached. - * User of this CoreResourceBundleControl should probably maintain a hard reference - * to the ResourceBundle object themselves. - */ - @Override - public long getTimeToLive(String baseName, Locale locale) { - return ResourceBundle.Control.TTL_DONT_CACHE; - } -} --- /dev/null Wed Nov 25 14:18:35 2009 +++ new/src/share/classes/sun/util/CoreResourceBundleControl-XLocales.java.template Wed Nov 25 14:18:35 2009 @@ -0,0 +1,114 @@ +/* + * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +#warn This file is preprocessed before being compiled + +package sun.util; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.ResourceBundle.Control; + +/** + * This is a convenient class for loading some of internal resources faster + * if they are built with Resources.gmk defined in J2SE workspace. Also, + * they have to be in class file format. + * + * "LOCALE_LIST" will be replaced at built time by a list of locales we + * defined in Defs.gmk. We want to exclude these locales from search to + * gain better performance. For example, since we know if the resource + * is built with Resources.gmk, they are not going to provide basename_en.class + * & basename_en_US.class resources, in that case, continuing searching them + * is expensive. By excluding them from the candidate locale list, these + * resources won't be searched. + * + * @since 1.6. + */ +public class CoreResourceBundleControl extends ResourceBundle.Control { + /* the candidate locale list to search */ + private final Collection excludedJDKLocales; + /* singlton instance of the resource bundle control. */ + private static CoreResourceBundleControl resourceBundleControlInstance = + new CoreResourceBundleControl(); + + protected CoreResourceBundleControl() { + excludedJDKLocales = Arrays.asList(#LOCALE_LIST#); + } + + /** + * This method is to provide a customized ResourceBundle.Control to speed + * up the search of resources in JDK. + * + * @return the instance of resource bundle control. + */ + public static CoreResourceBundleControl getRBControlInstance() { + return resourceBundleControlInstance; + } + + /** + * This method is to provide a customized ResourceBundle.Control to speed + * up the search of resources in JDK, with the bundle's package name check. + * + * @param bundleName bundle name to check + * @return the instance of resource bundle control if the bundle is JDK's, + * otherwise returns null. + */ + public static CoreResourceBundleControl getRBControlInstance(String bundleName) { + if (bundleName.startsWith("com.sun.") || + bundleName.startsWith("java.") || + bundleName.startsWith("javax.") || + bundleName.startsWith("sun.")) { + return resourceBundleControlInstance; + } else { + return null; + } + } + + /** + * @returns a list of candidate locales to search from. + * @exception NullPointerException if baseName or locale is null. + */ + @Override + public List getCandidateLocales(String baseName, Locale locale) { + List candidates = super.getCandidateLocales(baseName, locale); + candidates.removeAll(excludedJDKLocales); + return candidates; + } + + /** + * @ returns TTL_DONT_CACHE so that ResourceBundle instance won't be cached. + * User of this CoreResourceBundleControl should probably maintain a hard reference + * to the ResourceBundle object themselves. + */ + @Override + public long getTimeToLive(String baseName, Locale locale) { + return ResourceBundle.Control.TTL_DONT_CACHE; + } +} --- old/src/share/classes/sun/util/LocaleDataMetaInfo-XLocales.java Wed Nov 25 14:18:36 2009 +++ /dev/null Wed Nov 25 14:18:36 2009 @@ -1,82 +0,0 @@ -/* - * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -#warn This file is preprocessed before being compiled - -/* - * This class contains a map which records the locale list string for - * each resource in sun.util.resources & sun.text.resources. - * It is used to avoid loading non-existent localized resources so that - * jar files won't be opened unnecessary to look up them. - * - * @since 1.6 - */ -package sun.util; - -import java.util.HashMap; - - -public class LocaleDataMetaInfo { - - private static final HashMap resourceNameToLocales = - new HashMap(6); - - - static { - /* During JDK build time, #XXX_YYY# will be replaced by a string contain all the locales - supported by the resource. - - Don't remove the space character between " and #. That is put there purposely so that - look up locale string such as "en" could be based on if it contains " en ". - */ - resourceNameToLocales.put("sun.text.resources.FormatData", - " #FormatData_EuroLocales# | #FormatData_NonEuroLocales# "); - - resourceNameToLocales.put("sun.text.resources.CollationData", - " #CollationData_EuroLocales# | #CollationData_NonEuroLocales# "); - - resourceNameToLocales.put("sun.util.resources.TimeZoneNames", - " #TimeZoneNames_EuroLocales# | #TimeZoneNames_NonEuroLocales# "); - - resourceNameToLocales.put("sun.util.resources.LocaleNames", - " #LocaleNames_EuroLocales# | #LocaleNames_NonEuroLocales# "); - - resourceNameToLocales.put("sun.util.resources.CurrencyNames", - " #CurrencyNames_EuroLocales# | #CurrencyNames_NonEuroLocales# "); - - resourceNameToLocales.put("sun.util.resources.CalendarData", - " #CalendarData_EuroLocales# | #CalendarData_NonEuroLocales# "); - } - - /* - * @param resourceName the resource name - * @return the supported locale string for the passed in resource. - */ - public static String getSupportedLocaleString(String resourceName) { - - return resourceNameToLocales.get(resourceName); - } - -} --- /dev/null Wed Nov 25 14:18:36 2009 +++ new/src/share/classes/sun/util/LocaleDataMetaInfo-XLocales.java.template Wed Nov 25 14:18:36 2009 @@ -0,0 +1,82 @@ +/* + * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +#warn This file is preprocessed before being compiled + +/* + * This class contains a map which records the locale list string for + * each resource in sun.util.resources & sun.text.resources. + * It is used to avoid loading non-existent localized resources so that + * jar files won't be opened unnecessary to look up them. + * + * @since 1.6 + */ +package sun.util; + +import java.util.HashMap; + + +public class LocaleDataMetaInfo { + + private static final HashMap resourceNameToLocales = + new HashMap(6); + + + static { + /* During JDK build time, #XXX_YYY# will be replaced by a string contain all the locales + supported by the resource. + + Don't remove the space character between " and #. That is put there purposely so that + look up locale string such as "en" could be based on if it contains " en ". + */ + resourceNameToLocales.put("sun.text.resources.FormatData", + " #FormatData_EuroLocales# | #FormatData_NonEuroLocales# "); + + resourceNameToLocales.put("sun.text.resources.CollationData", + " #CollationData_EuroLocales# | #CollationData_NonEuroLocales# "); + + resourceNameToLocales.put("sun.util.resources.TimeZoneNames", + " #TimeZoneNames_EuroLocales# | #TimeZoneNames_NonEuroLocales# "); + + resourceNameToLocales.put("sun.util.resources.LocaleNames", + " #LocaleNames_EuroLocales# | #LocaleNames_NonEuroLocales# "); + + resourceNameToLocales.put("sun.util.resources.CurrencyNames", + " #CurrencyNames_EuroLocales# | #CurrencyNames_NonEuroLocales# "); + + resourceNameToLocales.put("sun.util.resources.CalendarData", + " #CalendarData_EuroLocales# | #CalendarData_NonEuroLocales# "); + } + + /* + * @param resourceName the resource name + * @return the supported locale string for the passed in resource. + */ + public static String getSupportedLocaleString(String resourceName) { + + return resourceNameToLocales.get(resourceName); + } + +} --- old/test/java/util/Formatter/Basic-X.java Wed Nov 25 14:18:36 2009 +++ /dev/null Wed Nov 25 14:18:36 2009 @@ -1,1712 +0,0 @@ -/* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - */ - -/* Type-specific source code for unit test - * - * Regenerate the BasicX classes via genBasic.sh whenever this file changes. - * We check in the generated source files so that the test tree can be used - * independently of the rest of the source tree. - */ - -#warn This file is preprocessed before being compiled - -import java.io.*; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.text.DateFormatSymbols; -import java.util.*; -#if[double] -import sun.misc.FpUtils; -import sun.misc.DoubleConsts; -#end[double] - -import static java.util.Calendar.*; -#if[datetime] -import static java.util.SimpleTimeZone.*; -import java.util.regex.Pattern; -#end[datetime] - -public class Basic$Type$ extends Basic { - - private static void test(String fs, String exp, Object ... args) { - Formatter f = new Formatter(new StringBuilder(), Locale.US); - f.format(fs, args); - ck(fs, exp, f.toString()); - } - - private static void test(Locale l, String fs, String exp, Object ... args) - { - Formatter f = new Formatter(new StringBuilder(), l); - f.format(fs, args); - ck(fs, exp, f.toString()); - } - - private static void test(String fs, Object ... args) { - Formatter f = new Formatter(new StringBuilder(), Locale.US); - f.format(fs, args); - ck(fs, "fail", f.toString()); - } - - private static void test(String fs) { - Formatter f = new Formatter(new StringBuilder(), Locale.US); - f.format(fs, "fail"); - ck(fs, "fail", f.toString()); - } - - private static void testSysOut(String fs, String exp, Object ... args) { - FileOutputStream fos = null; - FileInputStream fis = null; - try { - PrintStream saveOut = System.out; - fos = new FileOutputStream("testSysOut"); - System.setOut(new PrintStream(fos)); - System.out.format(Locale.US, fs, args); - fos.close(); - - fis = new FileInputStream("testSysOut"); - byte [] ba = new byte[exp.length()]; - int len = fis.read(ba); - String got = new String(ba); - if (len != ba.length) - fail(fs, exp, got); - ck(fs, exp, got); - - System.setOut(saveOut); - } catch (FileNotFoundException ex) { - fail(fs, ex.getClass()); - } catch (IOException ex) { - fail(fs, ex.getClass()); - } finally { - try { - if (fos != null) - fos.close(); - if (fis != null) - fis.close(); - } catch (IOException ex) { - fail(fs, ex.getClass()); - } - } - } - - private static void tryCatch(String fs, Class ex) { - boolean caught = false; - try { - test(fs); - } catch (Throwable x) { - if (ex.isAssignableFrom(x.getClass())) - caught = true; - } - if (!caught) - fail(fs, ex); - else - pass(); - } - - private static void tryCatch(String fs, Class ex, Object ... args) { - boolean caught = false; - try { - test(fs, args); - } catch (Throwable x) { - if (ex.isAssignableFrom(x.getClass())) - caught = true; - } - if (!caught) - fail(fs, ex); - else - pass(); - } - -#if[datetime] - private static void testDateTime(String fs, String exp, Calendar c) { - testDateTime(fs, exp, c, true); - } - - private static void testDateTime(String fs, String exp, Calendar c, boolean upper) { - //--------------------------------------------------------------------- - // Date/Time conversions applicable to Calendar, Date, and long. - //--------------------------------------------------------------------- - - // Calendar - test(fs, exp, c); - test((Locale)null, fs, exp, c); - test(Locale.US, fs, exp, c); - - // Date/long do not have timezone information so they will always use - // the default timezone. - String nexp = (fs.equals("%tZ") || fs.equals("%TZ") - || fs.equals("%tc") || fs.equals("%Tc") - ? exp.replace("PST", "GMT-08:00") - : exp); - - // Date (implemented via conversion to Calendar) - Date d = c.getTime(); - test(fs, nexp, d); - test((Locale)null, fs, nexp, d); - test(Locale.US, fs, nexp, d); - - // long (implemented via conversion to Calendar) - long l = c.getTimeInMillis(); - test(fs, nexp, l); - test((Locale)null, fs, nexp, l); - test(Locale.US, fs, nexp, l); - - if (upper) - // repeat all tests for upper case variant (%T) - testDateTime(Pattern.compile("t").matcher(fs).replaceFirst("T"), - exp.toUpperCase(), c, false); - } - - private static void testHours() { - for (int i = 0; i < 24; i++) { - // GregorianCalendar(int year, int month, int dayOfMonth, - // int hourOfDay, int minute, int second); - Calendar c = new GregorianCalendar(1995, MAY, 23, i, 48, 34); - - //----------------------------------------------------------------- - // DateTime.HOUR_OF_DAY - 'k' (0 - 23) -- like H - //----------------------------------------------------------------- - String exp = Integer.toString(i); - testDateTime("%tk", exp, c); - - //----------------------------------------------------------------- - // DateTime.HOUR - 'l' (1 - 12) -- like I - //----------------------------------------------------------------- - int v = i % 12; - v = (v == 0 ? 12 : v); - String exp2 = Integer.toString(v); - testDateTime("%tl", exp2, c); - - //----------------------------------------------------------------- - // DateTime.HOUR_OF_DAY_0 - 'H' (00 - 23) [zero padded] - //----------------------------------------------------------------- - if (exp.length() < 2) exp = "0" + exp; - testDateTime("%tH", exp, c); - - //----------------------------------------------------------------- - // DateTime.HOUR_0 - 'I' (01 - 12) - //----------------------------------------------------------------- - if (exp2.length() < 2) exp2 = "0" + exp2; - testDateTime("%tI", exp2, c); - - //----------------------------------------------------------------- - // DateTime.AM_PM - (am or pm) - //----------------------------------------------------------------- - testDateTime("%tp", (i <12 ? "am" : "pm"), c); - } - } -#end[datetime] - -#if[dec] -#if[prim] - private static $type$ negate($type$ v) { - return ($type$) -v; - } -#end[prim] -#end[dec] -#if[Byte] - private static $type$ negate($type$ v) { - return new $type$((byte) -v.byteValue()); - } -#end[Byte] -#if[Short] - private static $type$ negate($type$ v) { - return new $type$((short) -v.shortValue()); - } -#end[Short] -#if[Integer] - private static $type$ negate($type$ v) { - return new $type$(-v.intValue()); - } -#end[Integer] -#if[Long] - private static $type$ negate($type$ v) { - return new $type$(-v.longValue()); - } -#end[Long] - -#if[BigDecimal] - private static $type$ create(double v) { - return new $type$(v); - } - - private static $type$ negate($type$ v) { - return v.negate(); - } - - private static $type$ mult($type$ v, double mul) { - return v.multiply(new $type$(mul)); - } - - private static $type$ recip($type$ v) { - return BigDecimal.ONE.divide(v); - } -#end[BigDecimal] -#if[float] - private static $type$ create(double v) { - return ($type$) v; - } - - private static $type$ negate(double v) { - return ($type$) -v; - } - - private static $type$ mult($type$ v, double mul) { - return v * ($type$) mul; - } - - private static $type$ recip($type$ v) { - return 1.0f / v; - } -#end[float] -#if[Float] - private static $type$ create(double v) { - return new $type$(v); - } - - private static $type$ negate($type$ v) { - return new $type$(-v.floatValue()); - } - - private static $type$ mult($type$ v, double mul) { - return new $type$(v.floatValue() * (float) mul); - } - - private static $type$ recip($type$ v) { - return new $type$(1.0f / v.floatValue()); - } -#end[Float] -#if[double] - private static $type$ create(double v) { - return ($type$) v; - } - - - private static $type$ negate(double v) { - return -v; - } - - private static $type$ mult($type$ v, double mul) { - return v * mul; - } - - private static $type$ recip($type$ v) { - return 1.0 / v; - } -#end[double] -#if[Double] - private static $type$ create(double v) { - return new $type$(v); - } - - private static $type$ negate($type$ v) { - return new $type$(-v.doubleValue()); - } - - private static $type$ mult($type$ v, double mul) { - return new $type$(v.doubleValue() * mul); - } - - private static $type$ recip($type$ v) { - return new $type$(1.0 / v.doubleValue()); - } -#end[Double] - - public static void test() { - TimeZone.setDefault(TimeZone.getTimeZone("GMT-0800")); - - // Any characters not explicitly defined as conversions, date/time - // conversion suffixes, or flags are illegal and are reserved for - // future extensions. Use of such a character in a format string will - // cause an UnknownFormatConversionException or - // UnknownFormatFlagsException to be thrown. - tryCatch("%q", UnknownFormatConversionException.class); - tryCatch("%t&", UnknownFormatConversionException.class); - tryCatch("%&d", UnknownFormatConversionException.class); - tryCatch("%^b", UnknownFormatConversionException.class); - - //--------------------------------------------------------------------- - // Formatter.java class javadoc examples - //--------------------------------------------------------------------- - test(Locale.FRANCE, "e = %+10.4f", "e = +2,7183", Math.E); - test("%4$2s %3$2s %2$2s %1$2s", " d c b a", "a", "b", "c", "d"); - test("Amount gained or lost since last statement: $ %,(.2f", - "Amount gained or lost since last statement: $ (6,217.58)", - (new BigDecimal("-6217.58"))); - Calendar c = new GregorianCalendar(1969, JULY, 20, 16, 17, 0); - testSysOut("Local time: %tT", "Local time: 16:17:00", c); - - test("Unable to open file '%1$s': %2$s", - "Unable to open file 'food': No such file or directory", - "food", "No such file or directory"); - Calendar duke = new GregorianCalendar(1995, MAY, 23, 19, 48, 34); - duke.set(Calendar.MILLISECOND, 584); - test("Duke's Birthday: %1$tB %1$te, %1$tY", - "Duke's Birthday: May 23, 1995", - duke); - test("Duke's Birthday: %1$tB %1$te, %1$tY", - "Duke's Birthday: May 23, 1995", - duke.getTime()); - test("Duke's Birthday: %1$tB %1$te, %1$tY", - "Duke's Birthday: May 23, 1995", - duke.getTimeInMillis()); - - test("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s", - "d c b a d c b a", "a", "b", "c", "d"); - test("%s %s % ex) { + boolean caught = false; + try { + test(fs); + } catch (Throwable x) { + if (ex.isAssignableFrom(x.getClass())) + caught = true; + } + if (!caught) + fail(fs, ex); + else + pass(); + } + + private static void tryCatch(String fs, Class ex, Object ... args) { + boolean caught = false; + try { + test(fs, args); + } catch (Throwable x) { + if (ex.isAssignableFrom(x.getClass())) + caught = true; + } + if (!caught) + fail(fs, ex); + else + pass(); + } + +#if[datetime] + private static void testDateTime(String fs, String exp, Calendar c) { + testDateTime(fs, exp, c, true); + } + + private static void testDateTime(String fs, String exp, Calendar c, boolean upper) { + //--------------------------------------------------------------------- + // Date/Time conversions applicable to Calendar, Date, and long. + //--------------------------------------------------------------------- + + // Calendar + test(fs, exp, c); + test((Locale)null, fs, exp, c); + test(Locale.US, fs, exp, c); + + // Date/long do not have timezone information so they will always use + // the default timezone. + String nexp = (fs.equals("%tZ") || fs.equals("%TZ") + || fs.equals("%tc") || fs.equals("%Tc") + ? exp.replace("PST", "GMT-08:00") + : exp); + + // Date (implemented via conversion to Calendar) + Date d = c.getTime(); + test(fs, nexp, d); + test((Locale)null, fs, nexp, d); + test(Locale.US, fs, nexp, d); + + // long (implemented via conversion to Calendar) + long l = c.getTimeInMillis(); + test(fs, nexp, l); + test((Locale)null, fs, nexp, l); + test(Locale.US, fs, nexp, l); + + if (upper) + // repeat all tests for upper case variant (%T) + testDateTime(Pattern.compile("t").matcher(fs).replaceFirst("T"), + exp.toUpperCase(), c, false); + } + + private static void testHours() { + for (int i = 0; i < 24; i++) { + // GregorianCalendar(int year, int month, int dayOfMonth, + // int hourOfDay, int minute, int second); + Calendar c = new GregorianCalendar(1995, MAY, 23, i, 48, 34); + + //----------------------------------------------------------------- + // DateTime.HOUR_OF_DAY - 'k' (0 - 23) -- like H + //----------------------------------------------------------------- + String exp = Integer.toString(i); + testDateTime("%tk", exp, c); + + //----------------------------------------------------------------- + // DateTime.HOUR - 'l' (1 - 12) -- like I + //----------------------------------------------------------------- + int v = i % 12; + v = (v == 0 ? 12 : v); + String exp2 = Integer.toString(v); + testDateTime("%tl", exp2, c); + + //----------------------------------------------------------------- + // DateTime.HOUR_OF_DAY_0 - 'H' (00 - 23) [zero padded] + //----------------------------------------------------------------- + if (exp.length() < 2) exp = "0" + exp; + testDateTime("%tH", exp, c); + + //----------------------------------------------------------------- + // DateTime.HOUR_0 - 'I' (01 - 12) + //----------------------------------------------------------------- + if (exp2.length() < 2) exp2 = "0" + exp2; + testDateTime("%tI", exp2, c); + + //----------------------------------------------------------------- + // DateTime.AM_PM - (am or pm) + //----------------------------------------------------------------- + testDateTime("%tp", (i <12 ? "am" : "pm"), c); + } + } +#end[datetime] + +#if[dec] +#if[prim] + private static $type$ negate($type$ v) { + return ($type$) -v; + } +#end[prim] +#end[dec] +#if[Byte] + private static $type$ negate($type$ v) { + return new $type$((byte) -v.byteValue()); + } +#end[Byte] +#if[Short] + private static $type$ negate($type$ v) { + return new $type$((short) -v.shortValue()); + } +#end[Short] +#if[Integer] + private static $type$ negate($type$ v) { + return new $type$(-v.intValue()); + } +#end[Integer] +#if[Long] + private static $type$ negate($type$ v) { + return new $type$(-v.longValue()); + } +#end[Long] + +#if[BigDecimal] + private static $type$ create(double v) { + return new $type$(v); + } + + private static $type$ negate($type$ v) { + return v.negate(); + } + + private static $type$ mult($type$ v, double mul) { + return v.multiply(new $type$(mul)); + } + + private static $type$ recip($type$ v) { + return BigDecimal.ONE.divide(v); + } +#end[BigDecimal] +#if[float] + private static $type$ create(double v) { + return ($type$) v; + } + + private static $type$ negate(double v) { + return ($type$) -v; + } + + private static $type$ mult($type$ v, double mul) { + return v * ($type$) mul; + } + + private static $type$ recip($type$ v) { + return 1.0f / v; + } +#end[float] +#if[Float] + private static $type$ create(double v) { + return new $type$(v); + } + + private static $type$ negate($type$ v) { + return new $type$(-v.floatValue()); + } + + private static $type$ mult($type$ v, double mul) { + return new $type$(v.floatValue() * (float) mul); + } + + private static $type$ recip($type$ v) { + return new $type$(1.0f / v.floatValue()); + } +#end[Float] +#if[double] + private static $type$ create(double v) { + return ($type$) v; + } + + + private static $type$ negate(double v) { + return -v; + } + + private static $type$ mult($type$ v, double mul) { + return v * mul; + } + + private static $type$ recip($type$ v) { + return 1.0 / v; + } +#end[double] +#if[Double] + private static $type$ create(double v) { + return new $type$(v); + } + + private static $type$ negate($type$ v) { + return new $type$(-v.doubleValue()); + } + + private static $type$ mult($type$ v, double mul) { + return new $type$(v.doubleValue() * mul); + } + + private static $type$ recip($type$ v) { + return new $type$(1.0 / v.doubleValue()); + } +#end[Double] + + public static void test() { + TimeZone.setDefault(TimeZone.getTimeZone("GMT-0800")); + + // Any characters not explicitly defined as conversions, date/time + // conversion suffixes, or flags are illegal and are reserved for + // future extensions. Use of such a character in a format string will + // cause an UnknownFormatConversionException or + // UnknownFormatFlagsException to be thrown. + tryCatch("%q", UnknownFormatConversionException.class); + tryCatch("%t&", UnknownFormatConversionException.class); + tryCatch("%&d", UnknownFormatConversionException.class); + tryCatch("%^b", UnknownFormatConversionException.class); + + //--------------------------------------------------------------------- + // Formatter.java class javadoc examples + //--------------------------------------------------------------------- + test(Locale.FRANCE, "e = %+10.4f", "e = +2,7183", Math.E); + test("%4$2s %3$2s %2$2s %1$2s", " d c b a", "a", "b", "c", "d"); + test("Amount gained or lost since last statement: $ %,(.2f", + "Amount gained or lost since last statement: $ (6,217.58)", + (new BigDecimal("-6217.58"))); + Calendar c = new GregorianCalendar(1969, JULY, 20, 16, 17, 0); + testSysOut("Local time: %tT", "Local time: 16:17:00", c); + + test("Unable to open file '%1$s': %2$s", + "Unable to open file 'food': No such file or directory", + "food", "No such file or directory"); + Calendar duke = new GregorianCalendar(1995, MAY, 23, 19, 48, 34); + duke.set(Calendar.MILLISECOND, 584); + test("Duke's Birthday: %1$tB %1$te, %1$tY", + "Duke's Birthday: May 23, 1995", + duke); + test("Duke's Birthday: %1$tB %1$te, %1$tY", + "Duke's Birthday: May 23, 1995", + duke.getTime()); + test("Duke's Birthday: %1$tB %1$te, %1$tY", + "Duke's Birthday: May 23, 1995", + duke.getTimeInMillis()); + + test("%4$s %3$s %2$s %1$s %4$s %3$s %2$s %1$s", + "d c b a d c b a", "a", "b", "c", "d"); + test("%s %s %