/[classpath]/classpath/java/text/MessageFormat.java
ViewVC logotype

Diff of /classpath/java/text/MessageFormat.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11.2.6 by gnu_andrew, Tue Feb 1 00:25:39 2005 UTC revision 1.11.2.7 by gnu_andrew, Fri Feb 4 09:44:45 2005 UTC
# Line 46  import java.util.HashMap; Line 46  import java.util.HashMap;
46  import java.util.Locale;  import java.util.Locale;
47  import java.util.Vector;  import java.util.Vector;
48    
49  /**  public class MessageFormat extends Format
  * @author Tom Tromey <tromey@cygnus.com>  
  * @author Jorge Aliss <jaliss@hotmail.com>  
  * @date March 3, 1999  
  */  
 /* Written using "Java Class Libraries", 2nd edition, plus online  
  * API docs for JDK 1.2 from http://www.javasoft.com.  
  * Status:  Believed complete and correct to 1.2, except serialization.  
  *          and parsing.  
  */  
 final class MessageFormatElement  
50  {  {
51    // Argument number.    /**
52    int argNumber;     * @author Tom Tromey <tromey@cygnus.com>
53    // Formatter to be used.  This is the format set by setFormat.     * @author Jorge Aliss <jaliss@hotmail.com>
54    Format setFormat;     * @date March 3, 1999
55    // Formatter to be used based on the type.     */
56    Format format;    /* Written using "Java Class Libraries", 2nd edition, plus online
57       * API docs for JDK 1.2 from http://www.javasoft.com.
58    // Argument will be checked to make sure it is an instance of this     * Status:  Believed complete and correct to 1.2, except serialization.
59    // class.     *          and parsing.
60    Class formatClass;     */
61      private static final class MessageFormatElement
   // Formatter type.  
   String type;  
   // Formatter style.  
   String style;  
   
   // Text to follow this element.  
   String trailer;  
   
   // Recompute the locale-based formatter.  
   void setLocale (Locale loc)  
62    {    {
63      if (type == null)      // Argument number.
64        ;      int argNumber;
65      else if (type.equals("number"))      // Formatter to be used.  This is the format set by setFormat.
66        {      Format setFormat;
67          formatClass = java.lang.Number.class;      // Formatter to be used based on the type.
68        Format format;
69          if (style == null)  
70            format = NumberFormat.getInstance(loc);      // Argument will be checked to make sure it is an instance of this
71          else if (style.equals("currency"))      // class.
72            format = NumberFormat.getCurrencyInstance(loc);      Class formatClass;
73          else if (style.equals("percent"))  
74            format = NumberFormat.getPercentInstance(loc);      // Formatter type.
75          else if (style.equals("integer"))      String type;
76            {      // Formatter style.
77              NumberFormat nf = NumberFormat.getNumberInstance(loc);      String style;
78              nf.setMaximumFractionDigits(0);  
79              nf.setGroupingUsed(false);      // Text to follow this element.
80              format = nf;      String trailer;
81            }  
82          else      // Recompute the locale-based formatter.
83            {      void setLocale (Locale loc)
84              format = NumberFormat.getNumberInstance(loc);      {
85              DecimalFormat df = (DecimalFormat) format;        if (type == null)
86              df.applyPattern(style);          ;
87            }        else if (type.equals("number"))
88        }          {
89      else if (type.equals("time") || type.equals("date"))            formatClass = java.lang.Number.class;
90        {  
91          formatClass = java.util.Date.class;            if (style == null)
92                format = NumberFormat.getInstance(loc);
93          int val = DateFormat.DEFAULT;            else if (style.equals("currency"))
94          if (style == null)              format = NumberFormat.getCurrencyInstance(loc);
95            ;            else if (style.equals("percent"))
96          else if (style.equals("short"))              format = NumberFormat.getPercentInstance(loc);
97            val = DateFormat.SHORT;            else if (style.equals("integer"))
98          else if (style.equals("medium"))              {
99            val = DateFormat.MEDIUM;                NumberFormat nf = NumberFormat.getNumberInstance(loc);
100          else if (style.equals("long"))                nf.setMaximumFractionDigits(0);
101            val = DateFormat.LONG;                nf.setGroupingUsed(false);
102          else if (style.equals("full"))                format = nf;
103            val = DateFormat.FULL;              }
104              else
105          if (type.equals("time"))              {
106            format = DateFormat.getTimeInstance(val, loc);                format = NumberFormat.getNumberInstance(loc);
107          else                DecimalFormat df = (DecimalFormat) format;
108            format = DateFormat.getDateInstance(val, loc);                df.applyPattern(style);
109                }
110          if (style != null && val == DateFormat.DEFAULT)          }
111            {        else if (type.equals("time") || type.equals("date"))
112              SimpleDateFormat sdf = (SimpleDateFormat) format;          {
113              sdf.applyPattern(style);            formatClass = java.util.Date.class;
114            }  
115        }            int val = DateFormat.DEFAULT;
116      else if (type.equals("choice"))            if (style == null)
117        {              ;
118          formatClass = java.lang.Number.class;            else if (style.equals("short"))
119                val = DateFormat.SHORT;
120          if (style == null)            else if (style.equals("medium"))
121            throw new              val = DateFormat.MEDIUM;
122              IllegalArgumentException ("style required for choice format");            else if (style.equals("long"))
123          format = new ChoiceFormat (style);              val = DateFormat.LONG;
124        }            else if (style.equals("full"))
125                val = DateFormat.FULL;
126    
127              if (type.equals("time"))
128                format = DateFormat.getTimeInstance(val, loc);
129              else
130                format = DateFormat.getDateInstance(val, loc);
131    
132              if (style != null && val == DateFormat.DEFAULT)
133                {
134                  SimpleDateFormat sdf = (SimpleDateFormat) format;
135                  sdf.applyPattern(style);
136                }
137            }
138          else if (type.equals("choice"))
139            {
140              formatClass = java.lang.Number.class;
141    
142              if (style == null)
143                throw new
144                  IllegalArgumentException ("style required for choice format");
145              format = new ChoiceFormat (style);
146            }
147        }
148    }    }
 }  
149    
 public class MessageFormat extends Format  
 {  
150    private static final long serialVersionUID = 6479157306784022952L;    private static final long serialVersionUID = 6479157306784022952L;
151    
152    public static class Field extends Format.Field    public static class Field extends Format.Field

Legend:
Removed from v.1.11.2.6  
changed lines
  Added in v.1.11.2.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26