0001: //##header
0002: /*
0003: *******************************************************************************
0004: * Copyright (C) 1996-2006, International Business Machines Corporation and *
0005: * others. All Rights Reserved. *
0006: *******************************************************************************
0007: *
0008: */
0009:
0010: package com.ibm.icu.dev.test.serializable;
0011:
0012: import java.util.Date;
0013: import java.util.Locale;
0014: import java.util.HashMap;
0015:
0016: import com.ibm.icu.text.ChineseDateFormat;
0017: import com.ibm.icu.text.ChineseDateFormatSymbols;
0018: import com.ibm.icu.text.DateFormat;
0019: import com.ibm.icu.text.DateFormatSymbols;
0020: import com.ibm.icu.text.DecimalFormat;
0021: import com.ibm.icu.text.DecimalFormatSymbols;
0022: import com.ibm.icu.text.MessageFormat;
0023: import com.ibm.icu.text.NumberFormat;
0024: import com.ibm.icu.text.RuleBasedNumberFormat;
0025: import com.ibm.icu.text.SimpleDateFormat;
0026: import com.ibm.icu.util.GregorianCalendar;
0027: import com.ibm.icu.util.ULocale;
0028:
0029: /**
0030: * @author emader
0031: *
0032: * TODO To change the template for this generated type comment go to
0033: * Window - Preferences - Java - Code Style - Code Templates
0034: */
0035: public class FormatTests {
0036:
0037: public static class NumberFormatHandler implements
0038: SerializableTest.Handler {
0039: public Object[] getTestObjects() {
0040: NumberFormat formats[] = {
0041: NumberFormat.getInstance(Locale.US),
0042: NumberFormat.getCurrencyInstance(Locale.US),
0043: NumberFormat.getPercentInstance(Locale.US),
0044: NumberFormat.getScientificInstance(Locale.US)
0045:
0046: };
0047:
0048: return formats;
0049: }
0050:
0051: public boolean hasSameBehavior(Object a, Object b) {
0052: NumberFormat format_a = (NumberFormat) a;
0053: NumberFormat format_b = (NumberFormat) b;
0054: double number = 1234.56;
0055:
0056: return format_a.format(number).equals(
0057: format_b.format(number));
0058: }
0059: }
0060:
0061: public static class DecimalFormatHandler extends
0062: NumberFormatHandler {
0063: public Object[] getTestObjects() {
0064: Locale locales[] = SerializableTest.getLocales();
0065: DecimalFormat formats[] = new DecimalFormat[locales.length];
0066:
0067: for (int i = 0; i < locales.length; i += 1) {
0068: formats[i] = new DecimalFormat("#,##0.###",
0069: new DecimalFormatSymbols(locales[i]));
0070: }
0071:
0072: return formats;
0073: }
0074: }
0075:
0076: public static class RuleBasedNumberFormatHandler extends
0077: NumberFormatHandler {
0078: // default rules, from root.txt
0079: String xx_SpelloutRules = "=#,##0.######=;\n";
0080: String xx_OrdinalRules = "=#,##0=;\n";
0081: String xx_DurationRules = "=#,##0=;\n";
0082:
0083: String ja_spelloutRules = "%financial:\n"
0084: + "\u96f6; \u58f1; \u5f10; \u53c2; \u56db; \u4f0d; \u516d; \u4e03; \u516b; \u4e5d;\n"
0085: + "\u62fe[>>];\n"
0086: + "20: <<\u62fe[>>];\n"
0087: + "100: <<\u767e[>>];\n"
0088: + "1000: <<\u5343[>>];\n"
0089: + "10,000: <<\u4e07[>>];\n"
0090: + "100,000,000: <<\u5104[>>];\n"
0091: + "1,000,000,000,000: <<\u5146[>>];\n"
0092: + "10,000,000,000,000,000: =#,##0=;\n"
0093: +
0094:
0095: "%traditional:\n"
0096: + "\u96f6; \u4e00; \u4e8c; \u4e09; \u56db; \u4e94; \u516d; \u4e03; \u516b; \u4e5d;\n"
0097: + "\u5341[>>];\n" + "20: <<\u5341[>>];\n"
0098: + "100: <<\u767e[>>];\n" + "1000: <<\u5343[>>];\n"
0099: + "10,000: <<\u4e07[>>];\n"
0100: + "100,000,000: <<\u5104[>>];\n"
0101: + "1,000,000,000,000: <<\u5146[>>];\n"
0102: + "10,000,000,000,000,000: =#,##0=;";
0103:
0104: String en_SpelloutRules =
0105: // This rule set shows the normal simple formatting rules for English
0106: "%simplified:\n"
0107: +
0108: // negative number rule. This rule is used to format negative
0109: // numbers. The result of formatting the number's absolute
0110: // value is placed where the >> is.
0111: "-x: minus >>;\n"
0112: +
0113: // faction rule. This rule is used for formatting numbers
0114: // with fractional parts. The result of formatting the
0115: // number's integral part is substituted for the <<, and
0116: // the result of formatting the number's fractional part
0117: // (one digit at a time, e.g., 0.123 is "zero point one two
0118: // three") replaces the >>.
0119: "x.x: << point >>;\n"
0120: +
0121: // the rules for the values from 0 to 19 are simply the
0122: // words for those numbers
0123: "zero; one; two; three; four; five; six; seven; eight; nine;\n"
0124: + "ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n"
0125: + "seventeen; eighteen; nineteen;\n"
0126: +
0127: // beginning at 20, we use the >> to mark the position where
0128: // the result of formatting the number's ones digit. Thus,
0129: // we only need a new rule at every multiple of 10. Text in
0130: // backets is omitted if the value being formatted is an
0131: // even multiple of 10.
0132: "20: twenty[->>];\n"
0133: + "30: thirty[->>];\n"
0134: + "40: forty[->>];\n"
0135: + "50: fifty[->>];\n"
0136: + "60: sixty[->>];\n"
0137: + "70: seventy[->>];\n"
0138: + "80: eighty[->>];\n"
0139: + "90: ninety[->>];\n"
0140: +
0141: // beginning at 100, we can use << to mark the position where
0142: // the result of formatting the multiple of 100 is to be
0143: // inserted. Notice also that the meaning of >> has shifted:
0144: // here, it refers to both the ones place and the tens place.
0145: // The meanings of the << and >> tokens depend on the base value
0146: // of the rule. A rule's divisor is (usually) the highest
0147: // power of 10 that is less than or equal to the rule's base
0148: // value. The value being formatted is divided by the rule's
0149: // divisor, and the integral quotient is used to get the text
0150: // for <<, while the remainder is used to produce the text
0151: // for >>. Again, text in brackets is omitted if the value
0152: // being formatted is an even multiple of the rule's divisor
0153: // (in this case, an even multiple of 100)
0154: "100: << hundred[ >>];\n"
0155: +
0156: // The rules for the higher numbers work the same way as the
0157: // rule for 100: Again, the << and >> tokens depend on the
0158: // rule's divisor, which for all these rules is also the rule's
0159: // base value. To group by thousand, we simply don't have any
0160: // rules between 1,000 and 1,000,000.
0161: "1000: << thousand[ >>];\n"
0162: + "1,000,000: << million[ >>];\n"
0163: + "1,000,000,000: << billion[ >>];\n"
0164: + "1,000,000,000,000: << trillion[ >>];\n"
0165: +
0166: // overflow rule. This rule specifies that values of a
0167: // quadrillion or more are shown in numerals rather than words.
0168: // The == token means to format (with new rules) the value
0169: // being formatted by this rule and place the result where
0170: // the == is. The #,##0 inside the == signs is a
0171: // DecimalFormat pattern. It specifies that the value should
0172: // be formatted with a DecimalFormat object, and that it
0173: // should be formatted with no decimal places, at least one
0174: // digit, and a thousands separator.
0175: "1,000,000,000,000,000: =#,##0=;\n"
0176: +
0177:
0178: // %default is a more elaborate form of %simplified; It is basically
0179: // the same, except that it introduces "and" before the ones digit
0180: // when appropriate (basically, between the tens and ones digits) and
0181: // separates the thousands groups with commas in values over 100,000.
0182: "%default:\n"
0183: +
0184: // negative-number and fraction rules. These are the same
0185: // as those for %simplified, but have to be stated here too
0186: // because this is an entry point
0187: "-x: minus >>;\n"
0188: + "x.x: << point >>;\n"
0189: +
0190: // just use %simplified for values below 100
0191: "=%simplified=;\n"
0192: +
0193: // for values from 100 to 9,999 use %%and to decide whether or
0194: // not to interpose the "and"
0195: "100: << hundred[ >%%and>];\n"
0196: + "1000: << thousand[ >%%and>];\n"
0197: +
0198: // for values of 100,000 and up, use %%commas to interpose the
0199: // commas in the right places (and also to interpose the "and")
0200: "100,000>>: << thousand[>%%commas>];\n"
0201: + "1,000,000: << million[>%%commas>];\n"
0202: + "1,000,000,000: << billion[>%%commas>];\n"
0203: + "1,000,000,000,000: << trillion[>%%commas>];\n"
0204: + "1,000,000,000,000,000: =#,##0=;\n"
0205: +
0206: // if the value passed to this rule set is greater than 100, don't
0207: // add the "and"; if it's less than 100, add "and" before the last
0208: // digits
0209: "%%and:\n" + "and =%default=;\n" + "100: =%default=;\n"
0210: +
0211: // this rule set is used to place the commas
0212: "%%commas:\n" +
0213: // for values below 100, add "and" (the apostrophe at the
0214: // beginning is ignored, but causes the space that follows it
0215: // to be significant: this is necessary because the rules
0216: // calling %%commas don't put a space before it)
0217: "' and =%default=;\n" +
0218: // put a comma after the thousands (or whatever preceded the
0219: // hundreds)
0220: "100: , =%default=;\n" +
0221: // put a comma after the millions (or whatever precedes the
0222: // thousands)
0223: "1000: , <%default< thousand, >%default>;\n" +
0224: // and so on...
0225: "1,000,000: , =%default=;" +
0226: // %%lenient-parse isn't really a set of number formatting rules;
0227: // it's a set of collation rules. Lenient-parse mode uses a Collator
0228: // object to compare fragments of the text being parsed to the text
0229: // in the rules, allowing more leeway in the matching text. This set
0230: // of rules tells the formatter to ignore commas when parsing (it
0231: // already ignores spaces, which is why we refer to the space; it also
0232: // ignores hyphens, making "twenty one" and "twenty-one" parse
0233: // identically)
0234: "%%lenient-parse:\n" +
0235: // "& ' ' , ',' ;\n" +
0236: " &\u0000 << ' ' << ',' << '-'; \n";
0237:
0238: String en_GB_SpelloutRules = "%simplified:\n"
0239: + "-x: minus >>;\n"
0240: + "x.x: << point >>;\n"
0241: + "zero; one; two; three; four; five; six; seven; eight; nine;\n"
0242: + "ten; eleven; twelve; thirteen; fourteen; fifteen; sixteen;\n"
0243: + " seventeen; eighteen; nineteen;\n"
0244: + "20: twenty[->>];\n" + "30: thirty[->>];\n"
0245: + "40: forty[->>];\n" + "50: fifty[->>];\n"
0246: + "60: sixty[->>];\n" + "70: seventy[->>];\n"
0247: + "80: eighty[->>];\n" + "90: ninety[->>];\n"
0248: + "100: << hundred[ >>];\n"
0249: + "1000: << thousand[ >>];\n"
0250: + "1,000,000: << million[ >>];\n"
0251: + "1,000,000,000,000: << billion[ >>];\n"
0252: + "1,000,000,000,000,000: =#,##0=;\n" + "%default:\n"
0253: + "-x: minus >>;\n" + "x.x: << point >>;\n"
0254: + "=%simplified=;\n" + "100: << hundred[ >%%and>];\n"
0255: + "1000: << thousand[ >%%and>];\n"
0256: + "100,000>>: << thousand[>%%commas>];\n"
0257: + "1,000,000: << million[>%%commas>];\n"
0258: + "1,000,000,000,000: << billion[>%%commas>];\n"
0259: + "1,000,000,000,000,000: =#,##0=;\n" + "%%and:\n"
0260: + "and =%default=;\n" + "100: =%default=;\n"
0261: + "%%commas:\n" + "' and =%default=;\n"
0262: + "100: , =%default=;\n"
0263: + "1000: , <%default< thousand, >%default>;\n"
0264: + "1,000,000: , =%default=;" + "%%lenient-parse:\n"
0265: + "& ' ' , ',' ;\n";
0266:
0267: String fr_SpelloutRules =
0268: // the main rule set
0269: "%main:\n"
0270: + "-x: moins >>;\n"
0271: + "x.x: << virgule >>;\n"
0272: +
0273: // words for numbers from 0 to 10
0274: "z\u00e9ro; un; deux; trois; quatre; cinq; six; sept; huit; neuf;\n"
0275: + "dix; onze; douze; treize; quatorze; quinze; seize;\n"
0276: + " dix-sept; dix-huit; dix-neuf;\n"
0277: +
0278: // ords for the multiples of 10: %%alt-ones inserts "et"
0279: // when needed
0280: "20: vingt[->%%alt-ones>];\n"
0281: + "30: trente[->%%alt-ones>];\n"
0282: + "40: quarante[->%%alt-ones>];\n"
0283: + "50: cinquante[->%%alt-ones>];\n"
0284: +
0285: // rule for 60. The /20 causes this rule's multiplier to be
0286: // 20 rather than 10, allowinhg us to recurse for all values
0287: // from 60 to 79...
0288: "60/20: soixante[->%%alt-ones>];\n"
0289: +
0290: // ...except for 71, which must be special-cased
0291: "71: soixante et onze;\n"
0292: +
0293: // at 72, we have to repeat the rule for 60 to get us to 79
0294: "72/20: soixante->%%alt-ones>;\n"
0295: +
0296: // at 80, we state a new rule with the phrase for 80. Since
0297: // it changes form when there's a ones digit, we need a second
0298: // rule at 81. This rule also includes "/20," allowing it to
0299: // be used correctly for all values up to 99
0300: "80: quatre-vingts; 81/20: quatre-vingt->>;\n"
0301: +
0302: // "cent" becomes plural when preceded by a multiplier, and
0303: // the multiplier is omitted from the singular form
0304: "100: cent[ >>];\n"
0305: + "200: << cents[ >>];\n"
0306: + "1000: mille[ >>];\n"
0307: +
0308: // values from 1,100 to 1,199 are rendered as "onze cents..."
0309: // instead of "mille cent..." The > after "1000" decreases
0310: // the rule's exponent, causing its multiplier to be 100 instead
0311: // of 1,000. This prevents us from getting "onze cents cent
0312: // vingt-deux" ("eleven hundred one hundred twenty-two").
0313: "1100>: onze cents[ >>];\n"
0314: +
0315: // at 1,200, we go back to formating in thousands, so we
0316: // repeat the rule for 1,000
0317: "1200: mille >>;\n"
0318: +
0319: // at 2,000, the multiplier is added
0320: "2000: << mille[ >>];\n"
0321: + "1,000,000: << million[ >>];\n"
0322: + "1,000,000,000: << milliard[ >>];\n"
0323: + "1,000,000,000,000: << billion[ >>];\n"
0324: + "1,000,000,000,000,000: =#,##0=;\n"
0325: +
0326: // %%alt-ones is used to insert "et" when the ones digit is 1
0327: "%%alt-ones:\n" + "; et-un; =%main=;\n"
0328: + "%%lenient-parse:\n"
0329: + "&\u0000 << ' ' << ',' << '-';\n";
0330:
0331: String de_SpelloutRules =
0332: // 1 is "eins" when by itself, but turns into "ein" in most
0333: // combinations
0334: "%alt-ones:\n"
0335: + "-x: minus >>;\n"
0336: + "x.x: << komma >>;\n"
0337: + "null; eins; =%%main=;\n"
0338: + "%%main:\n"
0339: +
0340: // words for numbers from 0 to 12. Notice that the values
0341: // from 13 to 19 can derived algorithmically, unlike in most
0342: // other languages
0343: "null; ein; zwei; drei; vier; f\u00fcnf; sechs; sieben; acht; neun;\n"
0344: + "zehn; elf; zw\u00f6lf; >>zehn;\n"
0345: +
0346: // rules for the multiples of 10. Notice that the ones digit
0347: // goes on the front
0348: "20: [>>und]zwanzig;\n" + "30: [>>und]drei\u00dfig;\n"
0349: + "40: [>>und]vierzig;\n"
0350: + "50: [>>und]f\u00fcnfzig;\n"
0351: + "60: [>>und]sechzig;\n" + "70: [>>und]siebzig;\n"
0352: + "80: [>>und]achtzig;\n" + "90: [>>und]neunzig;\n"
0353: + "100: hundert[>%alt-ones>];\n"
0354: + "200: <<hundert[>%alt-ones>];\n"
0355: + "1000: tausend[>%alt-ones>];\n"
0356: + "2000: <<tausend[>%alt-ones>];\n"
0357: + "1,000,000: eine Million[ >%alt-ones>];\n"
0358: + "2,000,000: << Millionen[ >%alt-ones>];\n"
0359: + "1,000,000,000: eine Milliarde[ >%alt-ones>];\n"
0360: + "2,000,000,000: << Milliarden[ >%alt-ones>];\n"
0361: + "1,000,000,000,000: eine Billion[ >%alt-ones>];\n"
0362: + "2,000,000,000,000: << Billionen[ >%alt-ones>];\n"
0363: + "1,000,000,000,000,000: =#,##0=;"
0364: + "%%lenient-parse:\n" + "&\u0000 << ' ' << '-'\n"
0365: + "& ae , \u00e4 & ae , \u00c4\n"
0366: + "& oe , \u00f6 & oe , \u00d6\n"
0367: + "& ue , \u00fc & ue , \u00dc\n";
0368:
0369: String it_SpelloutRules =
0370: // main rule set. Follows the patterns of the preceding rule sets,
0371: // except that the final vowel is omitted from words ending in
0372: // vowels when they are followed by another word; instead, we have
0373: // separate rule sets that are identical to this one, except that
0374: // all the words that don't begin with a vowel have a vowel tacked
0375: // onto them at the front. A word ending in a vowel calls a
0376: // substitution that will supply that vowel, unless that vowel is to
0377: // be elided.
0378: "%main:\n"
0379: + "-x: meno >>;\n"
0380: + "x.x: << virgola >>;\n"
0381: + "zero; uno; due; tre; quattro; cinque; sei; sette; otto; nove;\n"
0382: + "dieci; undici; dodici; tredici; quattordici; quindici; sedici;\n"
0383: + " diciasette; diciotto; diciannove;\n"
0384: + "20: venti; vent>%%with-i>;\n"
0385: + "30: trenta; trent>%%with-i>;\n"
0386: + "40: quaranta; quarant>%%with-a>;\n"
0387: + "50: cinquanta; cinquant>%%with-a>;\n"
0388: + "60: sessanta; sessant>%%with-a>;\n"
0389: + "70: settanta; settant>%%with-a>;\n"
0390: + "80: ottanta; ottant>%%with-a>;\n"
0391: + "90: novanta; novant>%%with-a>;\n"
0392: + "100: cento; cent[>%%with-o>];\n"
0393: + "200: <<cento; <<cent[>%%with-o>];\n"
0394: + "1000: mille; mill[>%%with-i>];\n"
0395: + "2000: <<mila; <<mil[>%%with-a>];\n"
0396: + "100,000>>: <<mila[ >>];\n"
0397: + "1,000,000: =#,##0= (incomplete data);\n"
0398: + "%%with-a:\n"
0399: + "azero; uno; adue; atre; aquattro; acinque; asei; asette; otto; anove;\n"
0400: + "adieci; undici; adodici; atredici; aquattordici; aquindici; asedici;\n"
0401: + " adiciasette; adiciotto; adiciannove;\n"
0402: + "20: aventi; avent>%%with-i>;\n"
0403: + "30: atrenta; atrent>%%with-i>;\n"
0404: + "40: aquaranta; aquarant>%%with-a>;\n"
0405: + "50: acinquanta; acinquant>%%with-a>;\n"
0406: + "60: asessanta; asessant>%%with-a>;\n"
0407: + "70: asettanta; asettant>%%with-a>;\n"
0408: + "80: ottanta; ottant>%%with-a>;\n"
0409: + "90: anovanta; anovant>%%with-a>;\n"
0410: + "100: acento; acent[>%%with-o>];\n"
0411: + "200: <%%with-a<cento; <%%with-a<cent[>%%with-o>];\n"
0412: + "1000: amille; amill[>%%with-i>];\n"
0413: + "2000: <%%with-a<mila; <%%with-a<mil[>%%with-a>];\n"
0414: + "100,000: =%main=;\n"
0415: + "%%with-i:\n"
0416: + "izero; uno; idue; itre; iquattro; icinque; isei; isette; otto; inove;\n"
0417: + "idieci; undici; idodici; itredici; iquattordici; iquindici; isedici;\n"
0418: + " idiciasette; idiciotto; idiciannove;\n"
0419: + "20: iventi; ivent>%%with-i>;\n"
0420: + "30: itrenta; itrent>%%with-i>;\n"
0421: + "40: iquaranta; iquarant>%%with-a>;\n"
0422: + "50: icinquanta; icinquant>%%with-a>;\n"
0423: + "60: isessanta; isessant>%%with-a>;\n"
0424: + "70: isettanta; isettant>%%with-a>;\n"
0425: + "80: ottanta; ottant>%%with-a>;\n"
0426: + "90: inovanta; inovant>%%with-a>;\n"
0427: + "100: icento; icent[>%%with-o>];\n"
0428: + "200: <%%with-i<cento; <%%with-i<cent[>%%with-o>];\n"
0429: + "1000: imille; imill[>%%with-i>];\n"
0430: + "2000: <%%with-i<mila; <%%with-i<mil[>%%with-a>];\n"
0431: + "100,000: =%main=;\n"
0432: + "%%with-o:\n"
0433: + "ozero; uno; odue; otre; oquattro; ocinque; osei; osette; otto; onove;\n"
0434: + "odieci; undici; ododici; otredici; oquattordici; oquindici; osedici;\n"
0435: + " odiciasette; odiciotto; odiciannove;\n"
0436: + "20: oventi; ovent>%%with-i>;\n"
0437: + "30: otrenta; otrent>%%with-i>;\n"
0438: + "40: oquaranta; oquarant>%%with-a>;\n"
0439: + "50: ocinquanta; ocinquant>%%with-a>;\n"
0440: + "60: osessanta; osessant>%%with-a>;\n"
0441: + "70: osettanta; osettant>%%with-a>;\n"
0442: + "80: ottanta; ottant>%%with-a>;\n"
0443: + "90: onovanta; onovant>%%with-a>;\n"
0444: + "100: ocento; ocent[>%%with-o>];\n"
0445: + "200: <%%with-o<cento; <%%with-o<cent[>%%with-o>];\n"
0446: + "1000: omille; omill[>%%with-i>];\n"
0447: + "2000: <%%with-o<mila; <%%with-o<mil[>%%with-a>];\n"
0448: + "100,000: =%main=;\n";
0449:
0450: String en_OrdinalRules =
0451: // this rule set formats the numeral and calls %%abbrev to
0452: // supply the abbreviation
0453: "%main:\n" + "=#,##0==%%abbrev=;\n" +
0454: // this rule set supplies the abbreviation
0455: "%%abbrev:\n" +
0456: // the abbreviations. Everything from 4 to 19 ends in "th"
0457: "th; st; nd; rd; th;\n" +
0458: // at 20, we begin repeating the cycle every 10 (13 is "13th",
0459: // but 23 and 33 are "23rd" and "33rd") We do this by
0460: // ignoring all bug the ones digit in selecting the abbreviation
0461: "20: >>;\n" +
0462: // at 100, we repeat the whole cycle by considering only the
0463: // tens and ones digits in picking an abbreviation
0464: "100: >>;\n";
0465:
0466: String en_DurationRules =
0467: // main rule set for formatting with words
0468: "%with-words:\n"
0469: +
0470: // take care of singular and plural forms of "second"
0471: "0 seconds; 1 second; =0= seconds;\n"
0472: +
0473: // use %%min to format values greater than 60 seconds
0474: "60/60: <%%min<[, >>];\n"
0475: +
0476: // use %%hr to format values greater than 3,600 seconds
0477: // (the ">>>" below causes us to see the number of minutes
0478: // when when there are zero minutes)
0479: "3600/60: <%%hr<[, >>>];\n"
0480: +
0481: // this rule set takes care of the singular and plural forms
0482: // of "minute"
0483: "%%min:\n"
0484: + "0 minutes; 1 minute; =0= minutes;\n"
0485: +
0486: // this rule set takes care of the singular and plural forms
0487: // of "hour"
0488: "%%hr:\n"
0489: + "0 hours; 1 hour; =0= hours;\n"
0490: +
0491:
0492: // main rule set for formatting in numerals
0493: "%in-numerals:\n"
0494: +
0495: // values below 60 seconds are shown with "sec."
0496: "=0= sec.;\n"
0497: +
0498: // higher values are shown with colons: %%min-sec is used for
0499: // values below 3,600 seconds...
0500: "60: =%%min-sec=;\n"
0501: +
0502: // ...and %%hr-min-sec is used for values of 3,600 seconds
0503: // and above
0504: "3600: =%%hr-min-sec=;\n"
0505: +
0506: // this rule causes values of less than 10 minutes to show without
0507: // a leading zero
0508: "%%min-sec:\n" + "0: :=00=;\n"
0509: + "60/60: <0<>>;\n"
0510: +
0511: // this rule set is used for values of 3,600 or more. Minutes are always
0512: // shown, and always shown with two digits
0513: "%%hr-min-sec:\n" + "0: :=00=;\n" + "60/60: <00<>>;\n"
0514: + "3600/60: <#,##0<:>>>;\n" +
0515: // the lenient-parse rules allow several different characters to be used
0516: // as delimiters between hours, minutes, and seconds
0517: "%%lenient-parse:\n" + "& ':' = '.' = ' ' = '-';\n";
0518:
0519: HashMap cannedData = new HashMap();
0520:
0521: {
0522: cannedData.put("en_CA/SpelloutRules", en_SpelloutRules);
0523: cannedData.put("en_CA/OrdinalRules", en_OrdinalRules);
0524: cannedData.put("en_CA/DurationRules", en_DurationRules);
0525:
0526: cannedData.put("fr_CA/SpelloutRules", fr_SpelloutRules);
0527: cannedData.put("fr_CA/OrdinalRules", xx_OrdinalRules);
0528: cannedData.put("fr_CA/DurationRules", xx_DurationRules);
0529:
0530: cannedData.put("zh_CN/SpelloutRules", en_SpelloutRules);
0531: cannedData.put("zh_CN/OrdinalRules", en_OrdinalRules);
0532: cannedData.put("zh_CH/DurationRules", xx_DurationRules);
0533:
0534: cannedData.put("zh/SpelloutRules", en_SpelloutRules);
0535: cannedData.put("zh/OrdinalRules", en_OrdinalRules);
0536: cannedData.put("zh_DurationRules", xx_DurationRules);
0537:
0538: cannedData.put("en/SpelloutRules", en_SpelloutRules);
0539: cannedData.put("en/OrdinalRules", en_OrdinalRules);
0540: cannedData.put("en/DurationRules", en_DurationRules);
0541:
0542: cannedData.put("fr_FR/SpelloutRules", fr_SpelloutRules);
0543: cannedData.put("fr_FR/OrdinalRules", xx_OrdinalRules);
0544: cannedData.put("fr_FR/DurationRules", xx_DurationRules);
0545:
0546: cannedData.put("fr/SpelloutRules", fr_SpelloutRules);
0547: cannedData.put("fr/OrdinalRules", xx_OrdinalRules);
0548: cannedData.put("fr/DurationRules", xx_DurationRules);
0549:
0550: cannedData.put("de/SpelloutRules", de_SpelloutRules);
0551: cannedData.put("de/OrdinalRules", xx_OrdinalRules);
0552: cannedData.put("de/DurationRules", xx_DurationRules);
0553:
0554: cannedData.put("de_DE/SpelloutRules", de_SpelloutRules);
0555: cannedData.put("de_DE/OrdinalRules", xx_OrdinalRules);
0556: cannedData.put("de_DE/DurationRules", xx_DurationRules);
0557:
0558: cannedData.put("it/SpelloutRules", it_SpelloutRules);
0559: cannedData.put("it/OrdinalRules", xx_OrdinalRules);
0560: cannedData.put("it/DurationRules", xx_DurationRules);
0561:
0562: cannedData.put("it_IT/SpelloutRules", it_SpelloutRules);
0563: cannedData.put("it_IT/OrdinalRules", xx_OrdinalRules);
0564: cannedData.put("it_IT/DuratonRules", xx_DurationRules);
0565:
0566: cannedData.put("ko_KR/SpelloutRules", en_SpelloutRules);
0567: cannedData.put("ko_KR/OrdinalRules", en_OrdinalRules);
0568: cannedData.put("ko_KR/DurationRules", en_DurationRules);
0569:
0570: cannedData.put("ko/SpelloutRules", en_SpelloutRules);
0571: cannedData.put("ko/OrdinalRules", en_OrdinalRules);
0572: cannedData.put("ko/DurationRules", en_DurationRules);
0573:
0574: cannedData
0575: .put("zh_Hans_CN/SpelloutRules", en_SpelloutRules);
0576: cannedData.put("zh_Hans_CN/OrdinalRules", en_OrdinalRules);
0577: cannedData
0578: .put("zh_Hans_CH/DurationRules", xx_DurationRules);
0579:
0580: cannedData
0581: .put("zh_Hant_TW/SpelloutRules", en_SpelloutRules);
0582: cannedData.put("zh_Hant_TW/OrdinalRules", en_OrdinalRules);
0583: cannedData
0584: .put("zh_Hant_TW/DurationRules", en_DurationRules);
0585:
0586: cannedData.put("zh_TW/SpelloutRules", en_SpelloutRules);
0587: cannedData.put("zh_TW/OrdinalRules", en_OrdinalRules);
0588: cannedData.put("zh_TW/DurationRules", en_DurationRules);
0589:
0590: cannedData.put("en_GB/SpelloutRules", en_GB_SpelloutRules);
0591: cannedData.put("en_GB/OrdinalRules", en_OrdinalRules);
0592: cannedData.put("en_GB/DurationRules", en_DurationRules);
0593:
0594: cannedData.put("en_US/SpelloutRules", en_SpelloutRules);
0595: cannedData.put("en_US/OrdinalRules", en_OrdinalRules);
0596: cannedData.put("en_US/DurationRules", en_DurationRules);
0597:
0598: cannedData.put("ja/SpelloutRules", ja_spelloutRules);
0599: cannedData.put("ja/OrdinalRules", xx_OrdinalRules);
0600: cannedData.put("ja/DurationRules", xx_DurationRules);
0601:
0602: cannedData.put("ja_JP/SpelloutRules", ja_spelloutRules);
0603: cannedData.put("ja_JP/OrdinalRules", xx_OrdinalRules);
0604: cannedData.put("ja_JP/DurationRules", xx_DurationRules);
0605: }
0606:
0607: int types[] = { RuleBasedNumberFormat.SPELLOUT,
0608: RuleBasedNumberFormat.ORDINAL,
0609: RuleBasedNumberFormat.DURATION };
0610: String typeNames[] = { "SpelloutRules", "OrdinalRules",
0611: "DurationRules" };
0612:
0613: public Object[] getTestObjects() {
0614: Locale locales[] = SerializableTest.getLocales();
0615: RuleBasedNumberFormat formats[] = new RuleBasedNumberFormat[types.length
0616: * locales.length];
0617: int i = 0;
0618:
0619: for (int t = 0; t < types.length; t += 1) {
0620: for (int l = 0; l < locales.length; l += 1) {
0621: String cannedRules = (String) cannedData
0622: .get(locales[l].toString() + "/"
0623: + typeNames[t]);
0624:
0625: if (cannedRules != null) {
0626: formats[i++] = new RuleBasedNumberFormat(
0627: cannedRules, locales[l]);
0628: } else {
0629: formats[i++] = new RuleBasedNumberFormat(
0630: locales[l], types[t]);
0631: }
0632: }
0633: }
0634:
0635: return formats;
0636: }
0637: }
0638:
0639: public static class DecimalFormatSymbolsHandler implements
0640: SerializableTest.Handler {
0641: /*
0642: * The serialized form of a normally created DecimalFormatSymbols object
0643: * will have locale-specific data in it that might change from one version
0644: * of ICU4J to another. To guard against this, we store the following canned
0645: * data into the test objects we create.
0646: */
0647: static HashMap cannedData = new HashMap();
0648:
0649: static String en_CA_StringSymbols[] = { "$", "E", "\u221E",
0650: "CAD", "\uFFFD", };
0651:
0652: static String fr_CA_StringSymbols[] = { "$", "E", "\u221E",
0653: "CAD", "\uFFFD", };
0654:
0655: static String zh_CN_StringSymbols[] = { "\uFFE5", "E",
0656: "\u221E", "CNY", "\uFFFD", };
0657:
0658: static String zh_StringSymbols[] = { "\u00A4", "E", "\u221E",
0659: "XXX", "\uFFFD", };
0660:
0661: static String en_StringSymbols[] = { "\u00A4", "E", "\u221E",
0662: "XXX", "\uFFFD", };
0663:
0664: static String fr_FR_StringSymbols[] = { "\u20AC", "E",
0665: "\u221E", "EUR", "\uFFFD", };
0666:
0667: static String fr_StringSymbols[] = { "\u00A4", "E", "\u221E",
0668: "XXX", "\uFFFD", };
0669:
0670: static String de_StringSymbols[] = { "\u00A4", "E", "\u221E",
0671: "XXX", "\uFFFD", };
0672:
0673: static String de_DE_StringSymbols[] = { "\u20AC", "E",
0674: "\u221E", "EUR", "\uFFFD", };
0675:
0676: static String it_StringSymbols[] = { "\u00A4", "E", "\u221E",
0677: "XXX", "\uFFFD", };
0678:
0679: static String it_IT_StringSymbols[] = { "\u20AC", "E",
0680: "\u221E", "EUR", "\uFFFD", };
0681:
0682: static String ja_JP_StringSymbols[] = { "\uFFE5", "E",
0683: "\u221E", "JPY", "\uFFFD", };
0684:
0685: static String ja_StringSymbols[] = { "\u00A4", "E", "\u221E",
0686: "XXX", "\uFFFD", };
0687:
0688: static String ko_KR_StringSymbols[] = { "\uFFE6", "E",
0689: "\u221E", "KRW", "\uFFFD", };
0690:
0691: static String ko_StringSymbols[] = { "\u00A4", "E", "\u221E",
0692: "XXX", "\uFFFD", };
0693:
0694: static String zh_Hans_CN_StringSymbols[] = { "\uFFE5", "E",
0695: "\u221E", "CNY", "\uFFFD", };
0696:
0697: static String zh_Hant_TW_StringSymbols[] = { "NT$", "E",
0698: "\u221E", "TWD", "\uFFFD", };
0699:
0700: static String zh_TW_StringSymbols[] = { "NT$", "E", "\u221E",
0701: "TWD", "\uFFFD", };
0702:
0703: static String en_GB_StringSymbols[] = { "\u00A3", "E",
0704: "\u221E", "GBP", "\uFFFD", };
0705:
0706: static String en_US_StringSymbols[] = { "$", "E", "\u221E",
0707: "USD", "\uFFFD", };
0708:
0709: {
0710: cannedData.put("en_CA", en_CA_StringSymbols);
0711: cannedData.put("fr_CA", fr_CA_StringSymbols);
0712: cannedData.put("zh_CN", zh_CN_StringSymbols);
0713: cannedData.put("zh", zh_StringSymbols);
0714: cannedData.put("en", en_StringSymbols);
0715: cannedData.put("fr_FR", fr_FR_StringSymbols);
0716: cannedData.put("fr", fr_StringSymbols);
0717: cannedData.put("de", de_StringSymbols);
0718: cannedData.put("de_DE", de_DE_StringSymbols);
0719: cannedData.put("it", it_StringSymbols);
0720: cannedData.put("it_IT", it_IT_StringSymbols);
0721: cannedData.put("ja_JP", ja_JP_StringSymbols);
0722: cannedData.put("ja", ja_StringSymbols);
0723: cannedData.put("ko_KR", ko_KR_StringSymbols);
0724: cannedData.put("ko", ko_StringSymbols);
0725: cannedData.put("zh_Hans_CN", zh_Hans_CN_StringSymbols);
0726: cannedData.put("zh_Hant_TW", zh_Hant_TW_StringSymbols);
0727: cannedData.put("zh_TW", zh_TW_StringSymbols);
0728: cannedData.put("en_GB", en_GB_StringSymbols);
0729: cannedData.put("en_US", en_US_StringSymbols);
0730: }
0731:
0732: private char[] getCharSymbols(DecimalFormatSymbols dfs) {
0733: char symbols[] = { dfs.getDecimalSeparator(),
0734: dfs.getDigit(), dfs.getGroupingSeparator(),
0735: dfs.getMinusSign(),
0736: dfs.getMonetaryDecimalSeparator(),
0737: dfs.getPadEscape(), dfs.getPatternSeparator(),
0738: dfs.getPercent(), dfs.getPerMill(),
0739: dfs.getPlusSign(), dfs.getSignificantDigit(),
0740: dfs.getZeroDigit() };
0741:
0742: return symbols;
0743: }
0744:
0745: private String[] getStringSymbols(DecimalFormatSymbols dfs) {
0746: String symbols[] = { dfs.getCurrencySymbol(),
0747: dfs.getExponentSeparator(), dfs.getInfinity(),
0748: dfs.getInternationalCurrencySymbol(), dfs.getNaN() };
0749:
0750: return symbols;
0751: }
0752:
0753: private void setStringSymbols(DecimalFormatSymbols dfs,
0754: String symbols[]) {
0755: dfs.setCurrencySymbol(symbols[0]);
0756: dfs.setExponentSeparator(symbols[1]);
0757: dfs.setInfinity(symbols[2]);
0758: dfs.setInternationalCurrencySymbol(symbols[3]);
0759: dfs.setNaN(symbols[4]);
0760: }
0761:
0762: public Object[] getTestObjects() {
0763: Locale locales[] = SerializableTest.getLocales();
0764: DecimalFormatSymbols dfs[] = new DecimalFormatSymbols[locales.length];
0765:
0766: for (int i = 0; i < locales.length; i += 1) {
0767: ULocale uloc = ULocale.forLocale(locales[i]);
0768:
0769: dfs[i] = new DecimalFormatSymbols(uloc);
0770: setStringSymbols(dfs[i], (String[]) cannedData.get(uloc
0771: .toString()));
0772: }
0773:
0774: return dfs;
0775: }
0776:
0777: public boolean hasSameBehavior(Object a, Object b) {
0778: DecimalFormatSymbols dfs_a = (DecimalFormatSymbols) a;
0779: DecimalFormatSymbols dfs_b = (DecimalFormatSymbols) b;
0780: String strings_a[] = getStringSymbols(dfs_a);
0781: String strings_b[] = getStringSymbols(dfs_b);
0782: char chars_a[] = getCharSymbols(dfs_a);
0783: char chars_b[] = getCharSymbols(dfs_b);
0784:
0785: return SerializableTest
0786: .compareStrings(strings_a, strings_b)
0787: && SerializableTest.compareChars(chars_a, chars_b);
0788: }
0789: }
0790:
0791: public static class MessageFormatHandler implements
0792: SerializableTest.Handler {
0793: public Object[] getTestObjects() {
0794: MessageFormat formats[] = { new MessageFormat("pattern{0}") };
0795:
0796: return formats;
0797: }
0798:
0799: public boolean hasSameBehavior(Object a, Object b) {
0800: MessageFormat mfa = (MessageFormat) a;
0801: MessageFormat mfb = (MessageFormat) b;
0802: Object arguments[] = { new Integer(123456) };
0803:
0804: return mfa.format(arguments) != mfb.format(arguments);
0805: }
0806: }
0807:
0808: public static class DateFormatHandler implements
0809: SerializableTest.Handler {
0810: public Object[] getTestObjects() {
0811: Locale locales[] = SerializableTest.getLocales();
0812: DateFormat formats[] = new DateFormat[locales.length];
0813:
0814: for (int i = 0; i < locales.length; i += 1) {
0815: formats[i] = DateFormat.getDateTimeInstance(
0816: DateFormat.FULL, DateFormat.FULL, locales[i]);
0817: }
0818:
0819: return formats;
0820: }
0821:
0822: public boolean hasSameBehavior(Object a, Object b) {
0823: DateFormat dfa = (DateFormat) a;
0824: DateFormat dfb = (DateFormat) b;
0825: Date date = new Date(System.currentTimeMillis());
0826: String sfa = dfa.format(date);
0827: String sfb = dfa.format(date);
0828:
0829: return sfa.equals(sfb);
0830: }
0831:
0832: }
0833:
0834: public static class DateFormatSymbolsHandler implements
0835: SerializableTest.Handler {
0836: /*
0837: * The serialized form of a normally created DateFormatSymbols object
0838: * will have locale-specific data in it that might change from one version
0839: * of ICU4J to another. To guard against this, we store the following canned
0840: * data into the test objects we create.
0841: */
0842: static HashMap cannedData = new HashMap();
0843:
0844: static String en_CA_MonthNames[] = { "January", "February",
0845: "March", "April", "May", "June", "July", "August",
0846: "September", "October", "November", "December", };
0847:
0848: static String fr_CA_MonthNames[] = { "janvier", "f\u00E9vrier",
0849: "mars", "avril", "mai", "juin", "juillet", "ao\u00FBt",
0850: "septembre", "octobre", "novembre", "d\u00E9cembre", };
0851:
0852: static String zh_Hans_CN_MonthNames[] = { "\u4E00\u6708",
0853: "\u4E8C\u6708", "\u4E09\u6708", "\u56DB\u6708",
0854: "\u4E94\u6708", "\u516D\u6708", "\u4E03\u6708",
0855: "\u516B\u6708", "\u4E5D\u6708", "\u5341\u6708",
0856: "\u5341\u4E00\u6708", "\u5341\u4E8C\u6708", };
0857:
0858: static String zh_CN_MonthNames[] = { "\u4E00\u6708",
0859: "\u4E8C\u6708", "\u4E09\u6708", "\u56DB\u6708",
0860: "\u4E94\u6708", "\u516D\u6708", "\u4E03\u6708",
0861: "\u516B\u6708", "\u4E5D\u6708", "\u5341\u6708",
0862: "\u5341\u4E00\u6708", "\u5341\u4E8C\u6708", };
0863:
0864: static String zh_MonthNames[] = { "\u4E00\u6708",
0865: "\u4E8C\u6708", "\u4E09\u6708", "\u56DB\u6708",
0866: "\u4E94\u6708", "\u516D\u6708", "\u4E03\u6708",
0867: "\u516B\u6708", "\u4E5D\u6708", "\u5341\u6708",
0868: "\u5341\u4E00\u6708", "\u5341\u4E8C\u6708", };
0869:
0870: static String en_MonthNames[] = { "January", "February",
0871: "March", "April", "May", "June", "July", "August",
0872: "September", "October", "November", "December", };
0873:
0874: static String fr_FR_MonthNames[] = { "janvier", "f\u00E9vrier",
0875: "mars", "avril", "mai", "juin", "juillet", "ao\u00FBt",
0876: "septembre", "octobre", "novembre", "d\u00E9cembre", };
0877:
0878: static String fr_MonthNames[] = { "janvier", "f\u00E9vrier",
0879: "mars", "avril", "mai", "juin", "juillet", "ao\u00FBt",
0880: "septembre", "octobre", "novembre", "d\u00E9cembre", };
0881:
0882: static String de_MonthNames[] = { "Januar", "Februar",
0883: "M\u00E4rz", "April", "Mai", "Juni", "Juli", "August",
0884: "September", "Oktober", "November", "Dezember", };
0885:
0886: static String de_DE_MonthNames[] = { "Januar", "Februar",
0887: "M\u00E4rz", "April", "Mai", "Juni", "Juli", "August",
0888: "September", "Oktober", "November", "Dezember", };
0889:
0890: static String it_MonthNames[] = { "gennaio", "febbraio",
0891: "marzo", "aprile", "maggio", "giugno", "luglio",
0892: "agosto", "settembre", "ottobre", "novembre",
0893: "dicembre", };
0894:
0895: static String it_IT_MonthNames[] = { "gennaio", "febbraio",
0896: "marzo", "aprile", "maggio", "giugno", "luglio",
0897: "agosto", "settembre", "ottobre", "novembre",
0898: "dicembre", };
0899:
0900: static String ja_JP_MonthNames[] = { "1\u6708", "2\u6708",
0901: "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708",
0902: "8\u6708", "9\u6708", "10\u6708", "11\u6708",
0903: "12\u6708", };
0904:
0905: static String ja_MonthNames[] = { "1\u6708", "2\u6708",
0906: "3\u6708", "4\u6708", "5\u6708", "6\u6708", "7\u6708",
0907: "8\u6708", "9\u6708", "10\u6708", "11\u6708",
0908: "12\u6708", };
0909:
0910: static String ko_KR_MonthNames[] = { "1\uC6D4", "2\uC6D4",
0911: "3\uC6D4", "4\uC6D4", "5\uC6D4", "6\uC6D4", "7\uC6D4",
0912: "8\uC6D4", "9\uC6D4", "10\uC6D4", "11\uC6D4",
0913: "12\uC6D4", };
0914:
0915: static String ko_MonthNames[] = { "1\uC6D4", "2\uC6D4",
0916: "3\uC6D4", "4\uC6D4", "5\uC6D4", "6\uC6D4", "7\uC6D4",
0917: "8\uC6D4", "9\uC6D4", "10\uC6D4", "11\uC6D4",
0918: "12\uC6D4", };
0919:
0920: static String zh_Hant_TW_MonthNames[] = { "\u4E00\u6708",
0921: "\u4E8C\u6708", "\u4E09\u6708", "\u56DB\u6708",
0922: "\u4E94\u6708", "\u516D\u6708", "\u4E03\u6708",
0923: "\u516B\u6708", "\u4E5D\u6708", "\u5341\u6708",
0924: "\u5341\u4E00\u6708", "\u5341\u4E8C\u6708", };
0925:
0926: static String zh_TW_MonthNames[] = { "\u4E00\u6708",
0927: "\u4E8C\u6708", "\u4E09\u6708", "\u56DB\u6708",
0928: "\u4E94\u6708", "\u516D\u6708", "\u4E03\u6708",
0929: "\u516B\u6708", "\u4E5D\u6708", "\u5341\u6708",
0930: "\u5341\u4E00\u6708", "\u5341\u4E8C\u6708", };
0931:
0932: static String en_GB_MonthNames[] = { "January", "February",
0933: "March", "April", "May", "June", "July", "August",
0934: "September", "October", "November", "December", };
0935:
0936: static String en_US_MonthNames[] = { "January", "February",
0937: "March", "April", "May", "June", "July", "August",
0938: "September", "October", "November", "December", };
0939:
0940: {
0941: cannedData.put("en_CA", en_CA_MonthNames);
0942: cannedData.put("fr_CA", fr_CA_MonthNames);
0943: cannedData.put("zh_Hans_CN", zh_Hans_CN_MonthNames);
0944: cannedData.put("zh_CN", zh_CN_MonthNames);
0945: cannedData.put("zh", zh_MonthNames);
0946: cannedData.put("en", en_MonthNames);
0947: cannedData.put("fr_FR", fr_FR_MonthNames);
0948: cannedData.put("fr", fr_MonthNames);
0949: cannedData.put("de", de_MonthNames);
0950: cannedData.put("de_DE", de_DE_MonthNames);
0951: cannedData.put("it", it_MonthNames);
0952: cannedData.put("it_IT", it_IT_MonthNames);
0953: cannedData.put("ja_JP", ja_JP_MonthNames);
0954: cannedData.put("ja", ja_MonthNames);
0955: cannedData.put("ko_KR", ko_KR_MonthNames);
0956: cannedData.put("ko", ko_MonthNames);
0957: cannedData.put("zh_Hant_TW", zh_Hant_TW_MonthNames);
0958: cannedData.put("zh_TW", zh_TW_MonthNames);
0959: cannedData.put("en_GB", en_GB_MonthNames);
0960: cannedData.put("en_US", en_US_MonthNames);
0961: }
0962:
0963: public Object[] getTestObjects() {
0964: Locale locales[] = SerializableTest.getLocales();
0965: DateFormatSymbols dfs[] = new DateFormatSymbols[locales.length];
0966:
0967: for (int i = 0; i < locales.length; i += 1) {
0968: ULocale uloc = ULocale.forLocale(locales[i]);
0969:
0970: dfs[i] = new DateFormatSymbols(GregorianCalendar.class,
0971: uloc);
0972: dfs[i].setMonths((String[]) cannedData.get(uloc
0973: .toString()));
0974: }
0975:
0976: return dfs;
0977: }
0978:
0979: public boolean hasSameBehavior(Object a, Object b) {
0980: DateFormatSymbols dfs_a = (DateFormatSymbols) a;
0981: DateFormatSymbols dfs_b = (DateFormatSymbols) b;
0982: String months_a[] = dfs_a.getMonths();
0983: String months_b[] = dfs_b.getMonths();
0984:
0985: return SerializableTest.compareStrings(months_a, months_b);
0986: }
0987: }
0988:
0989: public static class SimpleDateFormatHandler extends
0990: DateFormatHandler {
0991: String patterns[] = { "EEEE, yyyy MMMM dd", "yyyy MMMM d",
0992: "yyyy MMM d", "yy/MM/dd" };
0993:
0994: public Object[] getTestObjects() {
0995: Locale locales[] = SerializableTest.getLocales();
0996: SimpleDateFormat dateFormats[] = new SimpleDateFormat[patterns.length
0997: * locales.length];
0998: int i = 0;
0999:
1000: for (int p = 0; p < patterns.length; p += 1) {
1001: for (int l = 0; l < locales.length; l += 1) {
1002: dateFormats[i++] = new SimpleDateFormat(
1003: patterns[p], ULocale.forLocale(locales[l]));
1004: }
1005: }
1006:
1007: return dateFormats;
1008: }
1009: }
1010:
1011: public static class ChineseDateFormatHandler extends
1012: DateFormatHandler {
1013: String patterns[] = { "EEEE y'x'G-Ml-d", "y'x'G-Ml-d",
1014: "y'x'G-Ml-d", "y'x'G-Ml-d" };
1015:
1016: public Object[] getTestObjects() {
1017: Locale locales[] = SerializableTest.getLocales();
1018: ChineseDateFormat dateFormats[] = new ChineseDateFormat[patterns.length
1019: * locales.length];
1020: int i = 0;
1021:
1022: for (int p = 0; p < patterns.length; p += 1) {
1023: for (int l = 0; l < locales.length; l += 1) {
1024: ULocale locale = new ULocale(locales[l].toString()
1025: + "@calendar=chinese");
1026:
1027: dateFormats[i++] = new ChineseDateFormat(
1028: patterns[p], locale);
1029: }
1030: }
1031:
1032: return dateFormats;
1033: }
1034: }
1035:
1036: public static class ChineseDateFormatSymbolsHandler extends
1037: DateFormatSymbolsHandler {
1038: public Object[] getTestObjects() {
1039: Locale locales[] = SerializableTest.getLocales();
1040: ChineseDateFormatSymbols cdfs[] = new ChineseDateFormatSymbols[locales.length];
1041:
1042: for (int i = 0; i < locales.length; i += 1) {
1043: ULocale uloc = ULocale.forLocale(locales[i]);
1044:
1045: cdfs[i] = new ChineseDateFormatSymbols(uloc);
1046: cdfs[i].setMonths((String[]) cannedData.get(uloc
1047: .toString()));
1048: }
1049:
1050: return cdfs;
1051: }
1052:
1053: public boolean hasSameBehavior(Object a, Object b) {
1054: if (!super .hasSameBehavior(a, b)) {
1055: return false;
1056: }
1057:
1058: ChineseDateFormatSymbols cdfs_a = (ChineseDateFormatSymbols) a;
1059: ChineseDateFormatSymbols cdfs_b = (ChineseDateFormatSymbols) b;
1060:
1061: return cdfs_a.getLeapMonth(0)
1062: .equals(cdfs_b.getLeapMonth(0))
1063: && cdfs_a.getLeapMonth(1).equals(
1064: cdfs_b.getLeapMonth(1));
1065: }
1066: }
1067:
1068: //#ifndef FOUNDATION
1069: public static class NumberFormatFieldHandler implements
1070: SerializableTest.Handler {
1071: public Object[] getTestObjects() {
1072: NumberFormat.Field fields[] = {
1073: NumberFormat.Field.CURRENCY,
1074: NumberFormat.Field.DECIMAL_SEPARATOR,
1075: NumberFormat.Field.EXPONENT,
1076: NumberFormat.Field.EXPONENT_SIGN,
1077: NumberFormat.Field.EXPONENT_SYMBOL,
1078: NumberFormat.Field.FRACTION,
1079: NumberFormat.Field.GROUPING_SEPARATOR,
1080: NumberFormat.Field.INTEGER,
1081: NumberFormat.Field.PERCENT,
1082: NumberFormat.Field.PERMILLE,
1083: NumberFormat.Field.SIGN };
1084:
1085: return fields;
1086: }
1087:
1088: public boolean hasSameBehavior(Object a, Object b) {
1089: NumberFormat.Field field_a = (NumberFormat.Field) a;
1090: NumberFormat.Field field_b = (NumberFormat.Field) b;
1091:
1092: return field_a.toString().equals(field_b.toString());
1093: }
1094: }
1095:
1096: //#endif
1097:
1098: public static void main(String[] args) {
1099: // nothing needed...
1100: }
1101: }
1102: //eof
|