< prev index next >

test/java/text/Format/MessageFormat/LargeMessageFormat.java

Print this page




  38 
  39     public static void main(String[] args) throws ParseException {
  40         Locale reservedLocale = Locale.getDefault();
  41         TimeZone reservedTimeZone = TimeZone.getDefault();
  42         try {
  43             Locale.setDefault(Locale.GERMANY);
  44             TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
  45             testFormat();
  46             testParse();
  47         } finally {
  48             // restore the reserved locale and time zone
  49             Locale.setDefault(reservedLocale);
  50             TimeZone.setDefault(reservedTimeZone);
  51         }
  52     }
  53 
  54     private static final int REPEATS = 89;
  55 
  56     private static void testFormat() {
  57         // construct large argument array

  58         Object[] sample = {
  59                 new Integer(0), // replace with running count below
  60                 "hello",
  61                 new Date(89, 10, 9),
  62                 new Integer(567890),
  63                 new Double(1234.50)
  64         };
  65         int samples = sample.length;
  66         Object[] arguments = new Object[REPEATS * (samples + 1)];
  67         for (int i = 0; i < REPEATS; i++) {
  68             System.arraycopy(sample, 0, arguments, i * samples, samples);
  69             arguments[i * samples] = new Integer(i);
  70         }
  71 
  72         // construct large template
  73         StringBuffer template = new StringBuffer();
  74         for (int i = 0; i < REPEATS; i++) {
  75             template.append("section {" + (i * samples) + ", number} - ");
  76             template.append("string: {" + (i * samples + 1) + "}; ");
  77             template.append("date: {" + (i * samples + 2) + ", date}; ");
  78             template.append("integer: {" + (i * samples + 3) + ", number}; ");
  79             template.append("currency: {" + (i * samples + 4) + ", number, currency};\n");
  80         }
  81 
  82         // construct expected result string
  83         StringBuffer expected = new StringBuffer();
  84         for (int i = 0; i < REPEATS; i++) {
  85             expected.append("section " + i + " - ");
  86             expected.append("string: hello; ");
  87             expected.append("date: 09.11.1989; ");
  88             expected.append("integer: 567.890; ");
  89             expected.append("currency: 1.234,50 \u20AC;\n");




  38 
  39     public static void main(String[] args) throws ParseException {
  40         Locale reservedLocale = Locale.getDefault();
  41         TimeZone reservedTimeZone = TimeZone.getDefault();
  42         try {
  43             Locale.setDefault(Locale.GERMANY);
  44             TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
  45             testFormat();
  46             testParse();
  47         } finally {
  48             // restore the reserved locale and time zone
  49             Locale.setDefault(reservedLocale);
  50             TimeZone.setDefault(reservedTimeZone);
  51         }
  52     }
  53 
  54     private static final int REPEATS = 89;
  55 
  56     private static void testFormat() {
  57         // construct large argument array
  58         @SuppressWarnings("deprecation")
  59         Object[] sample = {
  60                  0, // replace with running count below
  61                 "hello",
  62                 new Date(89, 10, 9),
  63                 567890,
  64                 1234.50
  65         };
  66         int samples = sample.length;
  67         Object[] arguments = new Object[REPEATS * (samples + 1)];
  68         for (int i = 0; i < REPEATS; i++) {
  69             System.arraycopy(sample, 0, arguments, i * samples, samples);
  70             arguments[i * samples] = i;
  71         }
  72 
  73         // construct large template
  74         StringBuffer template = new StringBuffer();
  75         for (int i = 0; i < REPEATS; i++) {
  76             template.append("section {" + (i * samples) + ", number} - ");
  77             template.append("string: {" + (i * samples + 1) + "}; ");
  78             template.append("date: {" + (i * samples + 2) + ", date}; ");
  79             template.append("integer: {" + (i * samples + 3) + ", number}; ");
  80             template.append("currency: {" + (i * samples + 4) + ", number, currency};\n");
  81         }
  82 
  83         // construct expected result string
  84         StringBuffer expected = new StringBuffer();
  85         for (int i = 0; i < REPEATS; i++) {
  86             expected.append("section " + i + " - ");
  87             expected.append("string: hello; ");
  88             expected.append("date: 09.11.1989; ");
  89             expected.append("integer: 567.890; ");
  90             expected.append("currency: 1.234,50 \u20AC;\n");


< prev index next >