diff options
author | Michael Koch <mkoch@gcc.gnu.org> | 2003-11-27 09:36:25 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2003-11-27 09:36:25 +0000 |
commit | a01387ddb7a90329b4ef9d0fb23cc4fbc46cf6f6 (patch) | |
tree | 0d443242cb8fe868619d5022b75db12890772b3b /libjava/java/text | |
parent | 33ebe68e6423c64ec40a6f82009a6000eb078d74 (diff) | |
download | gcc-a01387ddb7a90329b4ef9d0fb23cc4fbc46cf6f6.zip gcc-a01387ddb7a90329b4ef9d0fb23cc4fbc46cf6f6.tar.gz gcc-a01387ddb7a90329b4ef9d0fb23cc4fbc46cf6f6.tar.bz2 |
[multiple changes]
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
From-SVN: r73985
Diffstat (limited to 'libjava/java/text')
-rw-r--r-- | libjava/java/text/NumberFormat.java | 159 |
1 files changed, 158 insertions, 1 deletions
diff --git a/libjava/java/text/NumberFormat.java b/libjava/java/text/NumberFormat.java index 272cdbd..aa5ed9f 100644 --- a/libjava/java/text/NumberFormat.java +++ b/libjava/java/text/NumberFormat.java @@ -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.util.MissingResourceException; 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 abstract class NumberFormat extends Format implements Cloneable */ 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. @@ -326,6 +453,36 @@ public abstract class NumberFormat extends Format implements Cloneable } /** + * 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; + } + + /** * This method returns an instance of <code>NumberFormat</code> suitable * for formatting and parsing percentage values in the default locale. * |