[kaffe] CVS kaffe (guilhem): java.text.Format.Field implementation last part + fixes for java.text

Kaffe CVS cvs-commits at kaffe.org
Tue Aug 26 08:06:01 PDT 2003


PatchSet 3982 
Date: 2003/08/26 15:03:08
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
java.text.Format.Field implementation last part + fixes for java.text

Implemented java.text.DecimalFormat.formatToCharacterIterator but
handling of CURRENT, PERCENT, PERMILLE is still missing.
Added serialVersionUID for Field classes.
Removed an extra state in CollationElement.

Members: 
	ChangeLog:1.1579->1.1580 
	libraries/javalib/java/text/DateFormat.java:1.14->1.15 
	libraries/javalib/java/text/DecimalFormat.java:1.18->1.19 
	libraries/javalib/java/text/Format.java:1.11->1.12 
	libraries/javalib/java/text/MessageFormat.java:1.18->1.19 
	libraries/javalib/java/text/NumberFormat.java:1.16->1.17 
	libraries/javalib/java/text/RuleBasedCollator.java:1.13->1.14 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1579 kaffe/ChangeLog:1.1580
--- kaffe/ChangeLog:1.1579	Tue Aug 26 14:14:44 2003
+++ kaffe/ChangeLog	Tue Aug 26 15:03:08 2003
@@ -8,6 +8,24 @@
 	
 2003-08-26  Guilhem Lavaux <guilhem at kaffe.org>
 
+	* libraries/javalib/java/text/DecimalFormat.java:
+	(formatToCharacterAttribute) new method.
+	(formatInternal) renamed from format(double) and added attributes
+	handling
+	(addAttribute) added a final method to add attributes in vectors
+	(format(double)) use formatInternal
+
+	* libraries/javalib/java/text/NumberFormat.java,
+	libraries/javalib/java/text/MessageFormat.java,
+	libraries/javalib/java/text/DateFormat.java,
+	libraries/javalib/java/text/DecimalFormat.java:
+	Added serialVersionUID to Field subclasses.
+
+	* libraries/javalib/java/text/RuleBasedCollator.java:
+	Removed an extra unused state of CollationElement.
+
+2003-08-26  Guilhem Lavaux <guilhem at kaffe.org>
+
 	* libraries/javalib/java/text/SimpleDateFormat.java:
 	(formatWithAttribute) Added a if branch condition when we are not
 	setting attributes for an iterator.
Index: kaffe/libraries/javalib/java/text/DateFormat.java
diff -u kaffe/libraries/javalib/java/text/DateFormat.java:1.14 kaffe/libraries/javalib/java/text/DateFormat.java:1.15
--- kaffe/libraries/javalib/java/text/DateFormat.java:1.14	Mon Aug 25 06:14:48 2003
+++ kaffe/libraries/javalib/java/text/DateFormat.java	Tue Aug 26 15:03:10 2003
@@ -90,6 +90,8 @@
 
   public static class Field extends Format.Field
   {
+    static final long serialVersionUID = 7441350119349544720L;
+    
     private int calendarField;
 
     public static final DateFormat.Field ERA = new Field("era", Calendar.ERA);
Index: kaffe/libraries/javalib/java/text/DecimalFormat.java
diff -u kaffe/libraries/javalib/java/text/DecimalFormat.java:1.18 kaffe/libraries/javalib/java/text/DecimalFormat.java:1.19
--- kaffe/libraries/javalib/java/text/DecimalFormat.java:1.18	Mon Aug 25 06:30:12 2003
+++ kaffe/libraries/javalib/java/text/DecimalFormat.java	Tue Aug 26 15:03:10 2003
@@ -40,6 +40,8 @@
 import java.util.Locale;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.util.HashMap;
+import java.util.Vector;
 import java.io.ObjectInputStream;
 import java.io.IOException;
 
@@ -406,9 +408,29 @@
 	    && useExponentialNotation == dup.useExponentialNotation);
   }
 
-  public StringBuffer format (double number, StringBuffer dest,
-			      FieldPosition fieldPos)
+  private final void addAttribute(Vector ranges, Vector attributes,
+				  int new_range, Format.Field new_attribute)
+  {
+    HashMap map;
+
+    if (new_attribute != null)
+      {
+	map = new HashMap();
+	map.put(new_attribute, new_attribute);
+	attributes.add(map);
+      }
+    else
+      attributes.add(null);
+
+    ranges.add(new Integer(new_range));
+  }
+
+  protected StringBuffer formatInternal (double number, StringBuffer dest,
+					 FieldPosition fieldPos, Vector ranges,
+					 Vector attributes)
   {
+    boolean set_attributes = (ranges != null && attributes != null);
+   
     // A very special case.
     if (Double.isNaN(number))
       {
@@ -432,6 +454,14 @@
 	else
 	  {
 	    dest.append(symbols.getMinusSign());
+	    if (set_attributes)
+	      {
+		addAttribute(ranges, attributes, dest.length(),
+			     NumberFormat.Field.SIGN);
+		addAttribute(ranges, attributes, 
+			     dest.length()+positivePrefix.length(),
+			     null);
+	      }
 	    dest.append(positivePrefix);
 	  }
 	number = - number;
@@ -477,12 +507,23 @@
 
 	    // Append group separator if required.
 	    if (groupingUsed && count > 0 && groupingSize != 0 && count % groupingSize == 0)
-	      dest.insert(index, symbols.getGroupingSeparator());
+	      {
+		if (set_attributes)
+		  {
+		    addAttribute(ranges, attributes, dest.length(),
+				 NumberFormat.Field.INTEGER);
+		    addAttribute(ranges, attributes, dest.length()+1,
+				 NumberFormat.Field.GROUPING_SEPARATOR);
+		  }
 
+		dest.insert(index, symbols.getGroupingSeparator());
+	      }
 	    dest.insert(index, (char) (symbols.getZeroDigit() + dig));
 
 	    ++count;
 	  }
+	if (set_attributes)
+	  addAttribute(ranges, attributes, dest.length(), NumberFormat.Field.INTEGER); 
 
 	integerEndIndex = dest.length();
 
@@ -525,6 +566,15 @@
 	    || total_digits > 0)
 	  {
 	    dest.insert(decimal_index, symbols.getDecimalSeparator());
+	    
+	    if (set_attributes)
+	      {
+		addAttribute(ranges, attributes, decimal_index + 1,
+			     NumberFormat.Field.DECIMAL_SEPARATOR);
+		addAttribute(ranges, attributes, dest.length(),
+			     NumberFormat.Field.FRACTION);
+	      }
+	    
 	    if (fieldPos != null && 
 		(fieldPos.getField() == FRACTION_FIELD ||
 		 fieldPos.getFieldAttribute() == NumberFormat.Field.FRACTION))
@@ -538,10 +588,17 @@
 	if (useExponentialNotation)
 	  {
 	    dest.append(symbols.getExponential());
+	    if (set_attributes)
+	      addAttribute(ranges, attributes, dest.length(),
+			   NumberFormat.Field.EXPONENT_SYMBOL);
+	    
 	    if (exponent < 0)
 	      {
 		dest.append (symbols.getMinusSign ());
 		exponent = - exponent;
+		if (set_attributes)
+		  addAttribute(ranges, attributes, dest.length(),
+			       NumberFormat.Field.EXPONENT_SIGN);
 	      }
 	    index = dest.length();
 	    for (count = 0;
@@ -551,7 +608,11 @@
 		long dig = exponent % 10;
 		exponent /= 10;
 		dest.insert(index, (char) (symbols.getZeroDigit() + dig));
+
 	      }
+	    if (set_attributes)
+	      addAttribute(ranges, attributes, dest.length(),
+			   NumberFormat.Field.EXPONENT);
 	  }
       }
 
@@ -567,6 +628,40 @@
 		? negativeSuffix
 		: positiveSuffix);
     return dest;
+  }
+
+  public StringBuffer format (double number, StringBuffer dest,
+			      FieldPosition fieldPos)
+  {
+    return formatInternal (number, dest, fieldPos, null, null);
+  }
+
+  public AttributedCharacterIterator formatToCharacterIterator (Object value)
+  {
+    Vector ranges = new Vector();
+    Vector attributes = new Vector();
+    StringBuffer sbuf = new StringBuffer();
+    
+    if (value instanceof Number)
+      formatInternal(((Number) value).doubleValue(), sbuf, null, ranges, attributes);
+    else
+      throw new IllegalArgumentException 
+	("Cannot format given Object as a Number");
+
+    int[] int_ranges = new int[ranges.size()];
+    HashMap[] array_attributes = new HashMap[ranges.size()];
+    
+    for (int i=0;i<int_ranges.length;i++)
+      int_ranges[i] = ((Integer)ranges.elementAt(i)).intValue();
+
+    System.arraycopy(attributes.toArray(), 0, array_attributes, 0, array_attributes.length);
+
+    /*
+     * TODO: Reparse buffer to find the position of currency, percent, permille.
+     * As current classpath implementation preformat prefixes and suffixes we are
+     * not able to place attributes just when symbols arrive. 
+     */
+    return new FormatCharacterIterator (sbuf.toString(), int_ranges, array_attributes);
   }
 
   public StringBuffer format (long number, StringBuffer dest,
Index: kaffe/libraries/javalib/java/text/Format.java
diff -u kaffe/libraries/javalib/java/text/Format.java:1.11 kaffe/libraries/javalib/java/text/Format.java:1.12
--- kaffe/libraries/javalib/java/text/Format.java:1.11	Mon Aug 25 06:14:48 2003
+++ kaffe/libraries/javalib/java/text/Format.java	Tue Aug 26 15:03:10 2003
@@ -67,6 +67,8 @@
 
   public static class Field extends AttributedCharacterIterator.Attribute
   {
+    static final long serialVersionUID = 276966692217360283L;
+   
     public Field(String name)
     {
       super(name);
Index: kaffe/libraries/javalib/java/text/MessageFormat.java
diff -u kaffe/libraries/javalib/java/text/MessageFormat.java:1.18 kaffe/libraries/javalib/java/text/MessageFormat.java:1.19
--- kaffe/libraries/javalib/java/text/MessageFormat.java:1.18	Mon Aug 25 06:14:48 2003
+++ kaffe/libraries/javalib/java/text/MessageFormat.java	Tue Aug 26 15:03:10 2003
@@ -149,6 +149,8 @@
 
   public static class Field extends Format.Field
   {
+    static final long serialVersionUID = 7899943957617360810L;
+
     /**
      * This is the attribute set for all characters produced
      * by MessageFormat during a formatting.
Index: kaffe/libraries/javalib/java/text/NumberFormat.java
diff -u kaffe/libraries/javalib/java/text/NumberFormat.java:1.16 kaffe/libraries/javalib/java/text/NumberFormat.java:1.17
--- kaffe/libraries/javalib/java/text/NumberFormat.java:1.16	Mon Aug 25 06:14:48 2003
+++ kaffe/libraries/javalib/java/text/NumberFormat.java	Tue Aug 26 15:03:10 2003
@@ -82,6 +82,8 @@
 
   public static class Field extends Format.Field
   {
+    static final long serialVersionUID = 7494728892700160890L;
+
     /**
      * Attribute set to all characters containing digits of the integer
      * part.
Index: kaffe/libraries/javalib/java/text/RuleBasedCollator.java
diff -u kaffe/libraries/javalib/java/text/RuleBasedCollator.java:1.13 kaffe/libraries/javalib/java/text/RuleBasedCollator.java:1.14
--- kaffe/libraries/javalib/java/text/RuleBasedCollator.java:1.13	Mon Aug 25 06:14:48 2003
+++ kaffe/libraries/javalib/java/text/RuleBasedCollator.java	Tue Aug 26 15:03:10 2003
@@ -196,8 +196,7 @@
     static final int RESET = 4;
     static final int IGNORE = 5;
     static final int INVERSE_SECONDARY = 6;
-    static final int NEW_SEQUENCE = 7; /* For expansion */
-
+    
     int comparisonType;
     String textElement;
     int hashText;




More information about the kaffe mailing list