This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Patch: java.text.NumberFormat


Hi list,


I commited the attached patch to merge java.text.NumberFormat with classpath 
again.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2376
diff -u -b -B -r1.2376 ChangeLog
--- ChangeLog	27 Nov 2003 09:16:12 -0000	1.2376
+++ ChangeLog	27 Nov 2003 09:36:08 -0000
@@ -1,3 +1,19 @@
+2003-11-27  Guilhem Lavaux <guilhem@kaffe.org>
+
+	* java/text/NumberFormat.java:
+	(getIntegerInstance) Added the java version in the comments.
+
+2003-11-27  Mark Wielaard  <mark@klomp.org>
+
+	* java/text/NumberFormat.java: Import java.io.InvalidObjectException.
+	(readResolve): Reformat.
+
+2003-11-27  Guilhem Lavaux <guilhem@kaffe.org>
+
+	* java/text/NumberFormat.java
+	(NumberFormat.Field): New implemented class to match Java 1.4. 
+	(getIntegerInstance): Two new Java 1.4 methods.o
+
 2003-11-27  Ito Kazumitsu  <kaz@maczuka.gcd.org>
 
 	* java/util/GregorianCalendar.java (getLinearTime): Avoid counting
Index: java/text/NumberFormat.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/text/NumberFormat.java,v
retrieving revision 1.9
diff -u -b -B -r1.9 NumberFormat.java
--- java/text/NumberFormat.java	22 Jan 2002 22:40:37 -0000	1.9
+++ java/text/NumberFormat.java	27 Nov 2003 09:36:08 -0000
@@ -1,5 +1,5 @@
 /* NumberFormat.java -- Formats and parses numbers
-   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -44,6 +44,7 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.IOException;
+import java.io.InvalidObjectException;
 
 /**
  * This is the abstract superclass of all classes which format and 
@@ -79,6 +80,132 @@
    */
   public static final int FRACTION_FIELD = 1;
 
+  public static class Field extends Format.Field
+  {
+    static final long serialVersionUID = 7494728892700160890L;
+
+    /**
+     * Attribute set to all characters containing digits of the integer
+     * part.
+     */
+    public static final NumberFormat.Field INTEGER
+      = new Field("integer");
+
+    /**
+     * Attribute set to all characters containing digits of the fractional
+     * part.
+     */
+    public static final NumberFormat.Field FRACTION
+      = new Field("fraction");
+
+    /**
+     * Attribute set to all characters containing digits of the exponential
+     * part.
+     */
+    public static final NumberFormat.Field EXPONENT
+      = new Field("exponent");
+
+    /**
+     * Attribute set to all characters containing a decimal separator.
+     */
+    public static final NumberFormat.Field DECIMAL_SEPARATOR
+      = new Field("decimal separator");
+
+    /**
+     * Attribute set to all characters containing a sign (plus or minus).
+     */
+    public static final NumberFormat.Field SIGN
+      = new Field("sign");
+
+    /**
+     * Attribute set to all characters containing a grouping separator (e.g.
+     * a comma, a white space,...).
+     */
+    public static final NumberFormat.Field GROUPING_SEPARATOR
+      = new Field("grouping separator");
+
+    /**
+     * Attribute set to all characters containing an exponential symbol (e.g.
+     * 'E')
+     */
+    public static final NumberFormat.Field EXPONENT_SYMBOL
+      = new Field("exponent symbol");
+
+    /**
+     * Attribute set to all characters containing a percent symbol (e.g. '%')
+     */
+    public static final NumberFormat.Field PERCENT
+      = new Field("percent");
+
+    /**
+     * Attribute set to all characters containing a permille symbol.
+     */
+    public static final NumberFormat.Field PERMILLE
+      = new Field("permille");
+
+    /**
+     * Attribute set to all characters containing the currency unit.
+     */
+    public static final NumberFormat.Field CURRENCY
+      = new Field("currency");
+
+    /**
+     * Attribute set to all characters containing the exponent sign.
+     */
+    public static final NumberFormat.Field EXPONENT_SIGN
+      = new Field("exponent sign");
+
+    /**
+     * Private fields to register all fields contained in this descriptor.
+     */
+    private static final NumberFormat.Field[] allFields =
+    {
+      INTEGER, FRACTION, EXPONENT, DECIMAL_SEPARATOR, SIGN,
+      GROUPING_SEPARATOR, EXPONENT_SYMBOL, PERCENT,
+      PERMILLE, CURRENCY, EXPONENT_SIGN
+    };
+
+    /**
+     * This constructor is only used by the deserializer. Without it,
+     * it would fail to construct a valid object.
+     */
+    private Field()
+    {
+      super("");
+    }
+
+    /**
+     * Create a Field instance with the specified field name.
+     *
+     * @param field_name Field name for the new Field instance.
+     */
+    protected Field(String field_name)
+    {
+      super (field_name);
+    }
+
+    /**
+     * This function is used by the deserializer to know which object
+     * to use when it encounters an encoded NumberFormat.Field in a 
+     * serialization stream. If the stream is valid it should return
+     * one of the above field. In the other case we throw an exception.
+     *
+     * @return a valid official NumberFormat.Field instance.
+     *
+     * @throws InvalidObjectException if the field name is invalid.
+     */
+    protected Object readResolve() throws InvalidObjectException
+    {
+      String s = getName();
+      for (int i = 0; i < allFields.length; i++)
+	if (s.equals(allFields[i].getName()))
+	  return allFields[i];
+
+      throw new InvalidObjectException("no such NumberFormat field called "
+				       + s);
+    }
+  }
+
   /**
    * This method is a specialization of the format method that performs
    * a simple formatting of the specified <code>long</code> number.
@@ -323,6 +450,36 @@
   public static NumberFormat getNumberInstance (Locale loc)
   {
     return computeInstance (loc, "numberFormat", "#,##0.###");
+  }
+
+  /**
+   * This method returns an integer formatting and parsing class for the
+   * default locale. This will be a concrete subclass of <code>NumberFormat</code>,
+   * but the actual class returned is dependent on the locale.
+   *
+   * @return An instance of an integer number formatter for the default locale.
+   * @since 1.4 
+   */
+  public static final NumberFormat getIntegerInstance()
+  {
+    return getIntegerInstance (Locale.getDefault());
+  }
+
+  /**
+   * This method returns an integer formatting and parsing class for the
+   * default locale. This will be a concrete subclass of <code>NumberFormat</code>,
+   * but the actual class returned is dependent on the locale.
+   *
+   * @param locale the desired locale.
+   *
+   * @return An instance of an integer number formatter for the desired locale.
+   * @since 1.4 
+   */
+  public static NumberFormat getIntegerInstance(Locale locale)
+  {
+    NumberFormat format = computeInstance (locale, "numberFormat", "#,##0");
+    format.setParseIntegerOnly (true);
+    return format;
   }
 
   /**

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]