[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
This commit is contained in:
parent
33ebe68e64
commit
a01387ddb7
@ -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
|
||||
|
@ -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.
|
||||
@ -325,6 +452,36 @@ public abstract class NumberFormat extends Format implements Cloneable
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns an instance of <code>NumberFormat</code> suitable
|
||||
* for formatting and parsing percentage values in the default locale.
|
||||
|
Loading…
Reference in New Issue
Block a user