[kaffe] CVS kaffe (guilhem): JThread fix + OpenBSD fix + new java.text classes
Kaffe CVS
cvs-commits at kaffe.org
Sun Aug 24 23:17:01 PDT 2003
PatchSet 3976
Date: 2003/08/25 06:14:45
Author: guilhem
Branch: HEAD
Tag: (none)
Log:
JThread fix + OpenBSD fix + new java.text classes
Added jqueue variable node pool.
Added SIGNAL_* macros in config/i386/openbsd2/md.h
Added java.text.*.Field classes as in spec.
Implemented an AttributeCharacterIterator for Format classes
DecimalFormat.formatToCharacterIterator is still missing
Regenerated libraries/javalib/Makefile.[am,in]
Members:
ChangeLog:1.1573->1.1574
config/i386/openbsd2/md.h:1.2->1.3
kaffe/kaffevm/systems/unix-jthreads/jqueue.c:1.1->1.2
kaffe/kaffevm/systems/unix-jthreads/jqueue.h:1.1->1.2
libraries/javalib/Makefile.am:1.132->1.133
libraries/javalib/Makefile.in:1.179->1.180
libraries/javalib/essential.files:1.21->1.22
libraries/javalib/java/text/AttributedCharacterIterator.java:1.2->1.3
libraries/javalib/java/text/DateFormat.java:1.13->1.14
libraries/javalib/java/text/DecimalFormat.java:1.16->1.17
libraries/javalib/java/text/FieldPosition.java:1.6->1.7
libraries/javalib/java/text/Format.java:1.10->1.11
libraries/javalib/java/text/FormatCharacterIterator.java:INITIAL->1.1
libraries/javalib/java/text/MessageFormat.java:1.17->1.18
libraries/javalib/java/text/NumberFormat.java:1.15->1.16
libraries/javalib/java/text/RuleBasedCollator.java:1.12->1.13
libraries/javalib/java/text/SimpleDateFormat.java:1.22->1.23
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1573 kaffe/ChangeLog:1.1574
--- kaffe/ChangeLog:1.1573 Mon Aug 25 00:00:25 2003
+++ kaffe/ChangeLog Mon Aug 25 06:14:45 2003
@@ -1,3 +1,34 @@
+2003-08-24 Guilhem Lavaux <guilhem at kaffe.org>
+
+ * config/i386/openbsd2/md.h: Added signal defines for profiler in
+ jthreads.
+
+ * libraries/javalib/java/text/Format.java,
+ libraries/javalib/java/text/DateFormat.java,
+ libraries/javalib/java/text/NumberFormat.java,
+ libraries/javalib/java/text/SimpleDateFormat.java,
+ libraries/javalib/java/text/MessageFormat.java,
+ libraries/javalib/java/text/FormatCharacterIterator.java:
+ Implemented field description of returned formatted string.
+ Added object constants and constant resolution for all format types.
+ Added an AttributedCharacterIterator implementation called
+ FormatCharacterIterator (package protected).
+
+ * kaffe/kaffevm/systems/unix-jthreads/jqueue.c,
+ kaffe/kaffevm/systems/unix-jthreads/jqueue.h:
+ Implemented a variable node pool allocator for thread queues. The pool
+ size increase by step of DEFAULT_NUMBER_OF_NODES_IN_POOL.
+ (KaffeCreatePool) allocate one pool
+ (KaffePoolNewNode) build a new pool if the number of free nodes is
+ insufficient
+ (KaffePoolReleaseNode) deleted the assertion which was checking the
+ owner of the node. As nodes may be stored in different pools this may
+ not be achieved quickly.
+ (KaffeDestroyPool) destroy all pools
+
+ * libraries/javalib/Makefile.am, libraries/javalib/Makefile.in:
+ regenerated.
+
2003-08-04 Jim Pick <jim at kaffe.org>
* include/kaffe/.cvsignore,
Index: kaffe/config/i386/openbsd2/md.h
diff -u kaffe/config/i386/openbsd2/md.h:1.2 kaffe/config/i386/openbsd2/md.h:1.3
--- kaffe/config/i386/openbsd2/md.h:1.2 Wed Apr 1 04:18:48 1998
+++ kaffe/config/i386/openbsd2/md.h Mon Aug 25 06:14:46 2003
@@ -21,6 +21,12 @@
#undef SP_OFFSET
#define SP_OFFSET 2
+/* Define signal context macros for xprofiling */
+#define SIGNAL_ARGS(sig, sc) int sig, int __code, struct sigcontext *sc
+#define SIGNAL_CONTEXT_POINTER(scp) struct sigcontext *scp
+#define GET_SIGNAL_CONTEXT_POINTER(sc) (sc)
+#define SIGNAL_PC(scp) (scp)->sc_pc
+
#if defined(TRANSLATOR)
#include "jit-md.h"
#endif
Index: kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.c
diff -u kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.c:1.1 kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.c:1.2
--- kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.c:1.1 Mon Aug 4 13:56:32 2003
+++ kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.c Mon Aug 25 06:14:47 2003
@@ -12,12 +12,15 @@
static KaffeAllocator gs_default_allocator;
static KaffeDeallocator gs_default_deallocator;
+static KaffeDeallocator gs_default_reallocator;
void KaffeSetDefaultAllocator(KaffeAllocator allocator,
- KaffeDeallocator deallocator)
+ KaffeDeallocator deallocator,
+ KaffeReallocator reallocator)
{
gs_default_allocator = allocator;
gs_default_deallocator = deallocator;
+ gs_default_reallocator = reallocator;
}
KaffePool *KaffeCreatePool()
@@ -27,27 +30,39 @@
assert(gs_default_allocator != NULL);
assert(gs_default_deallocator != NULL);
+ assert(gs_default_reallocator != NULL);
pool = (KaffePool *)gs_default_allocator(sizeof(KaffePool));
pool->num_nodes_in_pool = DEFAULT_NUMBER_OF_NODES_IN_POOL;
pool->num_free_nodes = pool->num_nodes_in_pool;
- pool->pool = (KaffeNodeQueue *)gs_default_allocator(sizeof(KaffeNodeQueue)*pool->num_nodes_in_pool);
- pool->free_nodes = (KaffeNodeQueue **)gs_default_allocator(sizeof(KaffeNodeQueue *)*pool->num_nodes_in_pool);
+ pool->pools = (KaffeNodeQueue **)gs_default_allocator(sizeof(KaffeNodeQueue));
+ pool->pools[0] =
+ (KaffeNodeQueue *)gs_default_allocator(
+ sizeof(KaffeNodeQueue)*pool->num_nodes_in_pool);
+ pool->free_nodes =
+ (KaffeNodeQueue **)gs_default_allocator(
+ sizeof(KaffeNodeQueue *)*pool->num_nodes_in_pool);
for (i=0;i<pool->num_nodes_in_pool;i++) {
- pool->free_nodes[i] = &pool->pool[i];
+ pool->free_nodes[i] = &pool->pools[0][i];
}
+ pool->num_pools = 1;
pool->allocator = gs_default_allocator;
pool->deallocator = gs_default_deallocator;
+ pool->reallocator = gs_default_reallocator;
return pool;
}
void KaffeDestroyPool(KaffePool *pool)
{
- pool->deallocator(pool->pool);
+ int i;
+
+ pool->deallocator(pool->pools);
+ for (i=0;i<pool->num_pools;i++)
+ pool->deallocator(pool->pools[i]);
pool->deallocator(pool->free_nodes);
pool->deallocator(pool);
}
@@ -57,6 +72,38 @@
int chosen_node;
assert(pool != NULL);
+ if (pool->num_free_nodes == 0)
+ {
+ int old_free = pool->num_free_nodes;
+ int i;
+
+ /* We need to increment the number of internal pool nodes.
+ * The array of free nodes is reallocated, a new pool
+ * array node is allocated (to preserve the old nodes).
+ */
+ pool->num_free_nodes += DEFAULT_NUMBER_OF_NODES_IN_POOL;
+ pool->num_nodes_in_pool += DEFAULT_NUMBER_OF_NODES_IN_POOL;
+
+ pool->free_nodes =
+ pool->reallocator(pool->free_nodes,
+ pool->num_free_nodes*sizeof(KaffeNodeQueue *));
+ /* No more memory to handle threads, abort */
+ /* TODO: Be friendly */
+ assert(pool->free_nodes != NULL);
+
+ pool->num_pools++;
+ pool->pools = (KaffeNodeQueue **)
+ pool->reallocator(pool->pools,
+ pool->num_pools*sizeof(KaffeNodeQueue *));
+ /* No more memory to handle threads, abort */
+ assert(pool->pools != NULL);
+
+ pool->pools[num_pools-1] = (KaffeNodeQueue *)
+ pool->allocator(sizeof(KaffeNodeQueue)*DEFAULT_NUMBER_NODES_IN_POOL);
+
+ for (i=old_free;i<pool->num_free_nodes;i++)
+ pool->free_nodes[i] = &pool->pools[num_pools-1][i];
+ }
assert(pool->num_free_nodes != 0);
pool->num_free_nodes--;
@@ -70,8 +117,13 @@
int node_id;
assert(pool != NULL);
- node_id = (int)(node-pool->pool)/sizeof(KaffeNodeQueue);
- assert(node_id >= 0 && node_id < pool->num_nodes_in_pool);
+ /*
+ * This check cannot be done anymore as there different pools
+ * now.
+ *
+ * node_id = (int)(node-pool->pool)/sizeof(KaffeNodeQueue);
+ * assert(node_id >= 0 && node_id < pool->num_nodes_in_pool);
+ */
assert(pool->num_free_nodes < pool->num_nodes_in_pool);
pool->free_nodes[pool->num_free_nodes] = node;
Index: kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.h
diff -u kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.h:1.1 kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.h:1.2
--- kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.h:1.1 Mon Aug 4 13:56:32 2003
+++ kaffe/kaffe/kaffevm/systems/unix-jthreads/jqueue.h Mon Aug 25 06:14:47 2003
@@ -19,6 +19,7 @@
typedef void *(*KaffeAllocator)(size_t s);
typedef void (*KaffeDeallocator)(void *ptr);
+typedef void *(*KaffeReallocator)(void *ptr, size_t s);
typedef struct _KaffeNodeQueue {
void *element;
@@ -26,10 +27,11 @@
} KaffeNodeQueue;
typedef struct {
- KaffeNodeQueue *pool;
+ KaffeNodeQueue **pools;
KaffeNodeQueue **free_nodes;
int num_free_nodes;
int num_nodes_in_pool;
+ int num_pools;
KaffeAllocator allocator;
KaffeDeallocator deallocator;
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.132 kaffe/libraries/javalib/Makefile.am:1.133
--- kaffe/libraries/javalib/Makefile.am:1.132 Thu Aug 21 12:48:46 2003
+++ kaffe/libraries/javalib/Makefile.am Mon Aug 25 06:14:47 2003
@@ -1514,6 +1514,7 @@
java/text/DecimalFormat.java \
java/text/DecimalFormatSymbols.java \
java/text/FieldPosition.java \
+ java/text/FormatCharacterIterator.java \
java/text/Format.java \
java/text/MessageFormat.java \
java/text/NumberFormat.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.179 kaffe/libraries/javalib/Makefile.in:1.180
--- kaffe/libraries/javalib/Makefile.in:1.179 Mon Aug 18 17:40:31 2003
+++ kaffe/libraries/javalib/Makefile.in Mon Aug 25 06:14:47 2003
@@ -654,6 +654,7 @@
gnu/java/rmi/server/RMIHashes.java \
gnu/java/rmi/server/RMIObjectInputStream.java \
gnu/java/rmi/server/RMIObjectOutputStream.java \
+ gnu/java/rmi/server/RMIVoidValue.java \
gnu/java/rmi/server/UnicastConnection.java \
gnu/java/rmi/server/UnicastConnectionManager.java \
gnu/java/rmi/server/UnicastRef.java \
@@ -1811,6 +1812,7 @@
java/text/DecimalFormat.java \
java/text/DecimalFormatSymbols.java \
java/text/FieldPosition.java \
+ java/text/FormatCharacterIterator.java \
java/text/Format.java \
java/text/MessageFormat.java \
java/text/NumberFormat.java \
Index: kaffe/libraries/javalib/essential.files
diff -u kaffe/libraries/javalib/essential.files:1.21 kaffe/libraries/javalib/essential.files:1.22
--- kaffe/libraries/javalib/essential.files:1.21 Tue Aug 12 08:11:09 2003
+++ kaffe/libraries/javalib/essential.files Mon Aug 25 06:14:48 2003
@@ -226,6 +226,7 @@
java/text/DecimalFormatSymbols.java
java/text/FieldPosition.java
java/text/Format.java
+java/text/FormatCharacterIterator.java
java/text/MessageFormat.java
java/text/NumberFormat.java
java/text/ParseException.java
Index: kaffe/libraries/javalib/java/text/AttributedCharacterIterator.java
diff -u kaffe/libraries/javalib/java/text/AttributedCharacterIterator.java:1.2 kaffe/libraries/javalib/java/text/AttributedCharacterIterator.java:1.3
--- kaffe/libraries/javalib/java/text/AttributedCharacterIterator.java:1.2 Sat Aug 16 11:03:47 2003
+++ kaffe/libraries/javalib/java/text/AttributedCharacterIterator.java Mon Aug 25 06:14:48 2003
@@ -124,8 +124,7 @@
*
* @param name The name of this attribute key.
*/
-protected
-Attribute(String name)
+protected Attribute(String name)
{
this.name = name;
}
@@ -141,8 +140,7 @@
*
* @return The attribute name
*/
-protected String
-getName()
+protected String getName()
{
return(name);
}
@@ -159,8 +157,7 @@
*
* @exception InvalidObjectException If the object being deserialized cannot be resolved.
*/
-protected Object
-readResolve() throws InvalidObjectException
+protected Object readResolve() throws InvalidObjectException
{
if (this.equals(READING))
return(READING);
@@ -189,8 +186,7 @@
*
* @return <code>true</code> if the specified object is equal to this one, <code>false</code> otherwise.
*/
-public final boolean
-equals(Object obj)
+public final boolean equals(Object obj)
{
if (obj == this)
return(true);
@@ -205,8 +201,7 @@
*
* @return A hash value for this object.
*/
-public final int
-hashCode()
+public final int hashCode()
{
return(super.hashCode());
}
@@ -218,8 +213,7 @@
*
* @return A <code>String</code> representation of this object.
*/
-public String
-toString()
+public String toString()
{
return(getClass().getName() + "(" + getName() + ")");
}
@@ -238,8 +232,7 @@
*
* @return A list of keys
*/
-public abstract Set
-getAllAttributeKeys();
+public abstract Set getAllAttributeKeys();
/*************************************************************************/
@@ -249,8 +242,7 @@
*
* @return A <code>Map</code> of the attributes for the current character.
*/
-public abstract Map
-getAttributes();
+public abstract Map getAttributes();
/*************************************************************************/
@@ -263,8 +255,7 @@
*
* @return The value of the specified attribute
*/
-public abstract Object
-getAttribute(AttributedCharacterIterator.Attribute attrib);
+public abstract Object getAttribute(AttributedCharacterIterator.Attribute attrib);
/*************************************************************************/
@@ -274,8 +265,7 @@
*
* @return The start index of the run
*/
-public abstract int
-getRunStart();
+public abstract int getRunStart();
/*************************************************************************/
@@ -288,8 +278,7 @@
*
* @return The start index of the run.
*/
-public abstract int
-getRunStart(Set attribs);
+public abstract int getRunStart(Set attribs);
/*************************************************************************/
@@ -301,8 +290,8 @@
*
* @return The start index of the run.
*/
-public abstract int
-getRunStart(AttributedCharacterIterator.Attribute attrib);
+public abstract int getRunStart(AttributedCharacterIterator.Attribute
+ attrib);
/*************************************************************************/
@@ -312,8 +301,7 @@
*
* @return The end index of the run.
*/
-public abstract int
-getRunLimit();
+public abstract int getRunLimit();
/*************************************************************************/
@@ -326,8 +314,7 @@
*
* @return The end index of the run.
*/
-public abstract int
-getRunLimit(Set attribs);
+public abstract int getRunLimit(Set attribs);
/*************************************************************************/
@@ -339,8 +326,8 @@
*
* @return The end index of the run.
*/
-public abstract int
-getRunLimit(AttributedCharacterIterator.Attribute attrib);
+public abstract int getRunLimit(AttributedCharacterIterator.Attribute
+ attrib);
} // interface AttributedCharacterIterator
Index: kaffe/libraries/javalib/java/text/DateFormat.java
diff -u kaffe/libraries/javalib/java/text/DateFormat.java:1.13 kaffe/libraries/javalib/java/text/DateFormat.java:1.14
--- kaffe/libraries/javalib/java/text/DateFormat.java:1.13 Sat Aug 16 11:03:47 2003
+++ kaffe/libraries/javalib/java/text/DateFormat.java Mon Aug 25 06:14:48 2003
@@ -39,6 +39,7 @@
package java.text;
import java.util.*;
+import java.io.InvalidObjectException;
/**
* @author Per Bothner <bothner at cygnus.com>
@@ -85,6 +86,77 @@
public static final int HOUR1_FIELD = 15;
public static final int HOUR0_FIELD = 16;
public static final int TIMEZONE_FIELD = 17;
+
+
+ public static class Field extends Format.Field
+ {
+ private int calendarField;
+
+ public static final DateFormat.Field ERA = new Field("era", Calendar.ERA);
+ public static final DateFormat.Field YEAR = new Field("year", Calendar.YEAR);
+ public static final DateFormat.Field MONTH = new Field("month", Calendar.MONTH);
+ public static final DateFormat.Field DAY_OF_MONTH = new Field("day of month", Calendar.DAY_OF_MONTH);
+ public static final DateFormat.Field HOUR_OF_DAY1 = new Field("hour of day 1", Calendar.HOUR_OF_DAY);
+ public static final DateFormat.Field HOUR_OF_DAY0 = new Field("hour of day 0", Calendar.HOUR_OF_DAY);
+ public static final DateFormat.Field MINUTE = new Field("minute", Calendar.MINUTE);
+ public static final DateFormat.Field SECOND = new Field("second", Calendar.SECOND);
+ public static final DateFormat.Field MILLISECOND = new Field("millisecond", Calendar.MILLISECOND);
+ public static final DateFormat.Field DAY_OF_WEEK = new Field("day of week", Calendar.DAY_OF_WEEK);
+ public static final DateFormat.Field DAY_OF_YEAR = new Field("day of year", Calendar.DAY_OF_YEAR);
+ public static final DateFormat.Field DAY_OF_WEEK_IN_MONTH = new Field("day of week in month",
+ Calendar.DAY_OF_WEEK_IN_MONTH);
+ public static final DateFormat.Field WEEK_OF_YEAR = new Field("week of year", Calendar.WEEK_OF_YEAR);
+ public static final DateFormat.Field WEEK_OF_MONTH = new Field("week of month", Calendar.WEEK_OF_MONTH);
+ public static final DateFormat.Field AM_PM = new Field("am/pm", Calendar.AM_PM);
+ public static final DateFormat.Field HOUR1 = new Field("hour1", Calendar.HOUR);
+ public static final DateFormat.Field HOUR0 = new Field("hour0", Calendar.HOUR);
+ public static final DateFormat.Field TIME_ZONE = new Field("timezone", Calendar.ZONE_OFFSET);
+
+ public static final DateFormat.Field[] allFields =
+ {
+ ERA, YEAR, MONTH, DAY_OF_MONTH, HOUR_OF_DAY1,
+ HOUR_OF_DAY0, MINUTE, SECOND, MILLISECOND,
+ DAY_OF_WEEK, DAY_OF_YEAR, DAY_OF_WEEK_IN_MONTH,
+ WEEK_OF_YEAR, WEEK_OF_MONTH, AM_PM, HOUR1, HOUR0,
+ TIME_ZONE
+ };
+
+ // For deserialization
+ private Field()
+ {
+ super("");
+ }
+
+ protected Field(String name, int calendarField)
+ {
+ super(name);
+ this.calendarField = calendarField;
+ }
+
+ public int getCalendarField()
+ {
+ return calendarField;
+ }
+
+ public static Field ofCalendarField(int calendarField)
+ {
+ if (calendarField >= allFields.length || calendarField < 0)
+ throw new IllegalArgumentException("no such calendar field (" + calendarField + ")");
+
+ return allFields[calendarField];
+ }
+
+ 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 DateFormat field called " + s);
+ }
+ }
/**
* This method initializes a new instance of <code>DateFormat</code>.
Index: kaffe/libraries/javalib/java/text/DecimalFormat.java
diff -u kaffe/libraries/javalib/java/text/DecimalFormat.java:1.16 kaffe/libraries/javalib/java/text/DecimalFormat.java:1.17
--- kaffe/libraries/javalib/java/text/DecimalFormat.java:1.16 Sat Aug 16 11:03:47 2003
+++ kaffe/libraries/javalib/java/text/DecimalFormat.java Mon Aug 25 06:14:48 2003
@@ -413,7 +413,9 @@
if (Double.isNaN(number))
{
dest.append(symbols.getNaN());
- if (fieldPos != null && fieldPos.getField() == INTEGER_FIELD)
+ if (fieldPos != null &&
+ (fieldPos.getField() == INTEGER_FIELD ||
+ fieldPos.getFieldAttribute() == NumberFormat.Field.INTEGER))
{
int index = dest.length();
fieldPos.setBeginIndex(index - symbols.getNaN().length());
@@ -523,7 +525,9 @@
|| total_digits > 0)
{
dest.insert(decimal_index, symbols.getDecimalSeparator());
- if (fieldPos != null && fieldPos.getField() == FRACTION_FIELD)
+ if (fieldPos != null &&
+ (fieldPos.getField() == FRACTION_FIELD ||
+ fieldPos.getFieldAttribut() == NumberFormat.Field.FRACTION))
{
fieldPos.setBeginIndex(decimal_index + 1);
fieldPos.setEndIndex(dest.length());
@@ -551,7 +555,9 @@
}
}
- if (fieldPos != null && fieldPos.getField() == INTEGER_FIELD)
+ if (fieldPos != null &&
+ (fieldPos.getField() == INTEGER_FIELD ||
+ fieldPos.getFieldAttribute() == NumberFormat.Field.INTEGER))
{
fieldPos.setBeginIndex(integerBeginIndex);
fieldPos.setEndIndex(integerEndIndex);
Index: kaffe/libraries/javalib/java/text/FieldPosition.java
diff -u kaffe/libraries/javalib/java/text/FieldPosition.java:1.6 kaffe/libraries/javalib/java/text/FieldPosition.java:1.7
--- kaffe/libraries/javalib/java/text/FieldPosition.java:1.6 Sat Aug 16 11:03:47 2003
+++ kaffe/libraries/javalib/java/text/FieldPosition.java Mon Aug 25 06:14:48 2003
@@ -65,6 +65,13 @@
private int end;
/**
+ *
+ */
+ public FieldPosition (Format.Field field, int attribute)
+ {
+ }
+
+ /**
* This method initializes a new instance of <code>FieldPosition</code> to
* have the specified field id.
*
Index: kaffe/libraries/javalib/java/text/Format.java
diff -u kaffe/libraries/javalib/java/text/Format.java:1.10 kaffe/libraries/javalib/java/text/Format.java:1.11
--- kaffe/libraries/javalib/java/text/Format.java:1.10 Sat Aug 16 11:03:47 2003
+++ kaffe/libraries/javalib/java/text/Format.java Mon Aug 25 06:14:48 2003
@@ -38,6 +38,10 @@
package java.text;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.HashMap;
import java.io.Serializable;
/**
@@ -61,6 +65,14 @@
{
static final long serialVersionUID = 4479235611355683992L;
+ public static class Field extends AttributedCharacterIterator.Attribute
+ {
+ public Field(String name)
+ {
+ super(name);
+ }
+ }
+
/**
* This method initializes a new instance of <code>Format</code>.
* It performs no actions, but acts as a default constructor for
@@ -141,6 +153,15 @@
* case of error.
*/
public abstract Object parseObject (String str, ParsePosition pos);
+
+ /**
+ *
+ *
+ */
+ public AttributedCharacterIterator formatToCharacterIterator(Object obj)
+ {
+ return new FormatCharacterIterator(format(obj), null, null);
+ }
/**
* Creates a copy of this object.
===================================================================
Checking out kaffe/libraries/javalib/java/text/FormatCharacterIterator.java
RCS: /home/cvs/kaffe/kaffe/libraries/javalib/java/text/FormatCharacterIterator.java,v
VERS: 1.1
***************
--- /dev/null Sun Aug 4 19:57:58 2002
+++ kaffe/libraries/javalib/java/text/FormatCharacterIterator.java Mon Aug 25 06:16:32 2003
@@ -0,0 +1,404 @@
+/* FormatCharacter.java -- Implementation of AttributedCharacterIterator for
+ formatters.
+ Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+package java.text;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Vector;
+
+class FormatCharacterIterator implements AttributedCharacterIterator
+{
+ private String formattedString;
+ private int charIndex;
+ private int attributeIndex;
+ private int[] ranges;
+ private HashMap[] attributes;
+
+ FormatCharacterIterator()
+ {
+ formattedString = "";
+ ranges = new int[0];
+ attributes = new HashMap[0];
+ }
+
+ FormatCharacterIterator(String s, int[] ranges, HashMap[] attributes)
+ {
+ formattedString = s;
+ this.ranges = ranges;
+ this.attributes = attributes;
+ }
+
+ /*
+ * -----------------------------------
+ * AttributedCharacterIterator methods
+ * -----------------------------------
+ */
+ public Set getAllAttributeKeys()
+ {
+ if (attributes != null && attributes[attributeIndex] != null)
+ return attributes[attributeIndex].keySet();
+ else
+ return new HashSet();
+ }
+
+ public Map getAttributes()
+ {
+ if (attributes != null && attributes[attributeIndex] != null)
+ return attributes[attributeIndex];
+ else
+ return new HashMap();
+ }
+
+ public Object getAttribute(AttributedCharacterIterator.Attribute attrib)
+ {
+ if (attributes != null && attributes[attributeIndex] != null)
+ return attributes[attributeIndex].get(attrib);
+ else
+ return null;
+ }
+
+ public int getRunLimit(Set reqAttrs)
+ {
+ if (attributes == null)
+ return formattedString.length();
+
+ int currentAttrIndex = attributeIndex;
+ Set newKeys;
+
+ do
+ {
+ currentAttrIndex++;
+ if (currentAttrIndex == attributes.length)
+ return formattedString.length();
+ if (attributes[currentAttrIndex] == null)
+ break;
+ newKeys = attributes[currentAttrIndex].keySet();
+ }
+ while (newKeys.containsAll(reqAttrs));
+
+ return ranges[currentAttrIndex-1];
+ }
+
+ public int getRunLimit(AttributedCharacterIterator.Attribute attribute)
+ {
+ Set s = new HashSet();
+
+ s.add(attribute);
+ return getRunLimit(s);
+ }
+
+ public int getRunLimit()
+ {
+ if (attributes == null)
+ return formattedString.length();
+ if (attributes[attributeIndex] == null)
+ {
+ for (int i=attributeIndex+1;i<attributes.length;i++)
+ if (attributes[i] != null)
+ return ranges[i-1];
+ return formattedString.length();
+ }
+
+ return getRunLimit (attributes[attributeIndex].keySet());
+ }
+
+ public int getRunStart(Set reqAttrs)
+ {
+ if (attributes == null)
+ return formattedString.length();
+
+ int currentAttrIndex = attributeIndex;
+ Set newKeys = null;
+
+ do
+ {
+ if (currentAttrIndex == 0)
+ return 0;
+
+ currentAttrIndex--;
+ if (attributes[currentAttrIndex] == null)
+ break;
+ newKeys = attributes[currentAttrIndex].keySet();
+ }
+ while (newKeys.containsAll(reqAttrs));
+
+ return (currentAttrIndex > 0) ? ranges[currentAttrIndex-1] : 0;
+ }
+
+ public int getRunStart()
+ {
+ if (attributes == null)
+ return 0;
+
+ if (attributes[attributeIndex] == null)
+ {
+ for (int i=attributeIndex;i>0;i--)
+ if (attributes[i] != null)
+ return ranges[attributeIndex-1];
+ return 0;
+ }
+
+ return getRunStart(attributes[attributeIndex].keySet());
+ }
+
+ public int getRunStart(AttributedCharacterIterator.Attribute attribute)
+ {
+ Set s = new HashSet();
+
+ s.add(attribute);
+ return getRunStart(s);
+ }
+
+ public Object clone()
+ {
+ return new FormatCharacterIterator(formattedString, ranges, attributes);
+ }
+
+ /*
+ * ---------------------------------
+ * CharacterIterator methods
+ * ---------------------------------
+ */
+ public char current()
+ {
+ return formattedString.charAt(charIndex);
+ }
+
+ public char first()
+ {
+ charIndex = 0;
+ attributeIndex = 0;
+ return formattedString.charAt(0);
+ }
+
+ public int getBeginIndex()
+ {
+ return 0;
+ }
+
+ public int getEndIndex()
+ {
+ return formattedString.length();
+ }
+
+ public int getIndex()
+ {
+ return charIndex;
+ }
+
+ public char last()
+ {
+ charIndex = formattedString.length()-1;
+ if (attributes != null)
+ attributeIndex = attributes.length-1;
+ return formattedString.charAt(charIndex);
+ }
+
+ public char next()
+ {
+ charIndex++;
+ if (charIndex >= formattedString.length())
+ {
+ charIndex = getEndIndex();
+ return DONE;
+ }
+ if (attributes != null)
+ {
+ if (charIndex >= ranges[attributeIndex])
+ attributeIndex++;
+ }
+ return formattedString.charAt(charIndex);
+ }
+
+ public char previous()
+ {
+ charIndex--;
+ if (charIndex < 0)
+ {
+ charIndex = 0;
+ return DONE;
+ }
+
+ if (attributes != null)
+ {
+ if (charIndex < ranges[attributeIndex])
+ attributeIndex--;
+ }
+ return formattedString.charAt(charIndex);
+ }
+
+ public char setIndex(int position)
+ {
+ if (position < 0 || position > formattedString.length())
+ throw new IllegalArgumentException("position is out of range");
+
+ charIndex = position;
+ if (attributes != null)
+ {
+ for (attributeIndex=0;attributeIndex<attributes.length;
+ attributeIndex++)
+ if (ranges[attributeIndex] > charIndex)
+ break;
+ attributeIndex--;
+ }
+ if (charIndex == formattedString.length())
+ return DONE;
+ else
+ return formattedString.charAt(charIndex);
+ }
+
+ protected void mergeAttributes(HashMap[] attributes, int[] ranges)
+ {
+ Vector new_ranges = new Vector();
+ Vector new_attributes = new Vector();
+ int i = 0, j = 0;
+
+ while (i < this.ranges.length && j < ranges.length)
+ {
+ if (this.attributes[i] != null)
+ {
+ new_attributes.add(this.attributes[i]);
+ if (attributes[j] != null)
+ this.attributes[i].putAll(attributes[j]);
+ }
+ else
+ {
+ new_attributes.add(attributes[j]);
+ }
+ if (this.ranges[i] == ranges[j])
+ {
+ new_ranges.add(new Integer(ranges[j]));
+ i++;
+ j++;
+ }
+ else if (this.ranges[i] < ranges[j])
+ {
+ new_ranges.add(new Integer(this.ranges[i]));
+ i++;
+ }
+ else
+ {
+ new_ranges.add(new Integer(ranges[j]));
+ j++;
+ }
+ }
+
+ if (i != this.ranges.length)
+ {
+ for (;i<this.ranges.length;i++)
+ {
+ new_attributes.add(this.attributes[i]);
+ new_ranges.add(new Integer(this.ranges[i]));
+ }
+ }
+ if (j != ranges.length)
+ {
+ for (;j<ranges.length;j++)
+ {
+ new_attributes.add(attributes[j]);
+ new_ranges.add(new Integer(ranges[j]));
+ }
+ }
+
+ this.attributes = new HashMap[new_attributes.size()];
+ this.ranges = new int[new_ranges.size()];
+ System.arraycopy(new_attributes.toArray(), 0, this.attributes,
+ 0, this.attributes.length);
+
+ for (i=0;i<new_ranges.size();i++)
+ {
+ this.ranges[i] = ((Integer)new_ranges.elementAt(i)).intValue();
+ }
+
+ }
+
+ protected void append(AttributedCharacterIterator iterator)
+ {
+ char c = iterator.first();
+ Vector more_ranges = new Vector();
+ Vector more_attributes = new Vector();
+
+ do
+ {
+ formattedString = formattedString + String.valueOf(c);
+ // TODO: Reduce the size of the output array.
+ more_attributes.add (iterator.getAttributes());
+ more_ranges.add(new Integer(formattedString.length()));
+ // END TOOD
+ c = iterator.next();
+ }
*** Patch too long, truncated ***
More information about the kaffe
mailing list