Commit 89066f10 by Tom Tromey Committed by Tom Tromey

RuleBasedCollator.java (clone): Rewrote.

	* java/text/RuleBasedCollator.java (clone): Rewrote.
	(RuleBasedCollator(RuleBasedCollator)): Removed.
	* java/text/MessageFormat.java: Re-merged from Classpath.
	* java/text/DecimalFormat.java: Re-merged from Classpath.

From-SVN: r45458
parent cffb2601
2001-09-06 Tom Tromey <tromey@redhat.com>
* java/text/RuleBasedCollator.java (clone): Rewrote.
(RuleBasedCollator(RuleBasedCollator)): Removed.
* java/text/MessageFormat.java: Re-merged from Classpath.
* java/text/DecimalFormat.java: Re-merged from Classpath.
2001-09-06 Anthony Green <green@redhat.com> 2001-09-06 Anthony Green <green@redhat.com>
* include/jvm.h: Declare _Jv_RegisterResource. * include/jvm.h: Declare _Jv_RegisterResource.
......
...@@ -350,21 +350,9 @@ public class DecimalFormat extends NumberFormat ...@@ -350,21 +350,9 @@ public class DecimalFormat extends NumberFormat
public Object clone () public Object clone ()
{ {
return new DecimalFormat (this); DecimalFormat c = (DecimalFormat) super.clone ();
} c.symbols = (DecimalFormatSymbols) symbols.clone ();
return c;
private DecimalFormat (DecimalFormat dup)
{
decimalSeparatorAlwaysShown = dup.decimalSeparatorAlwaysShown;
groupingSize = dup.groupingSize;
minExponentDigits = dup.minExponentDigits;
multiplier = dup.multiplier;
negativePrefix = dup.negativePrefix;
negativeSuffix = dup.negativeSuffix;
positivePrefix = dup.positivePrefix;
positiveSuffix = dup.positiveSuffix;
symbols = (DecimalFormatSymbols) dup.symbols.clone();
useExponentialNotation = dup.useExponentialNotation;
} }
public DecimalFormat () public DecimalFormat ()
......
...@@ -33,6 +33,7 @@ import java.util.Vector; ...@@ -33,6 +33,7 @@ import java.util.Vector;
/** /**
* @author Tom Tromey <tromey@cygnus.com> * @author Tom Tromey <tromey@cygnus.com>
* @author Jorge Aliss <jaliss@hotmail.com>
* @date March 3, 1999 * @date March 3, 1999
*/ */
/* Written using "Java Class Libraries", 2nd edition, plus online /* Written using "Java Class Libraries", 2nd edition, plus online
...@@ -40,7 +41,6 @@ import java.util.Vector; ...@@ -40,7 +41,6 @@ import java.util.Vector;
* Status: Believed complete and correct to 1.2, except serialization. * Status: Believed complete and correct to 1.2, except serialization.
* and parsing. * and parsing.
*/ */
final class MessageFormatElement final class MessageFormatElement
{ {
// Argument number. // Argument number.
...@@ -64,70 +64,70 @@ final class MessageFormatElement ...@@ -64,70 +64,70 @@ final class MessageFormatElement
// Recompute the locale-based formatter. // Recompute the locale-based formatter.
void setLocale (Locale loc) void setLocale (Locale loc)
{ {
if (type == null) if (type == null)
; ;
else if (type.equals("number")) else if (type.equals("number"))
{ {
formatClass = java.lang.Number.class; formatClass = java.lang.Number.class;
if (style == null) if (style == null)
format = NumberFormat.getInstance(loc); format = NumberFormat.getInstance(loc);
else if (style.equals("currency")) else if (style.equals("currency"))
format = NumberFormat.getCurrencyInstance(loc); format = NumberFormat.getCurrencyInstance(loc);
else if (style.equals("percent")) else if (style.equals("percent"))
format = NumberFormat.getPercentInstance(loc); format = NumberFormat.getPercentInstance(loc);
else if (style.equals("integer")) else if (style.equals("integer"))
{ {
NumberFormat nf = NumberFormat.getNumberInstance(loc); NumberFormat nf = NumberFormat.getNumberInstance(loc);
nf.setMaximumFractionDigits(0); nf.setMaximumFractionDigits(0);
nf.setGroupingUsed(false); nf.setGroupingUsed(false);
format = nf; format = nf;
} }
else else
{ {
format = NumberFormat.getNumberInstance(loc); format = NumberFormat.getNumberInstance(loc);
DecimalFormat df = (DecimalFormat) format; DecimalFormat df = (DecimalFormat) format;
df.applyPattern(style); df.applyPattern(style);
} }
} }
else if (type.equals("time") || type.equals("date")) else if (type.equals("time") || type.equals("date"))
{ {
formatClass = java.util.Date.class; formatClass = java.util.Date.class;
int val = DateFormat.DEFAULT; int val = DateFormat.DEFAULT;
if (style == null) if (style == null)
; ;
else if (style.equals("short")) else if (style.equals("short"))
val = DateFormat.SHORT; val = DateFormat.SHORT;
else if (style.equals("medium")) else if (style.equals("medium"))
val = DateFormat.MEDIUM; val = DateFormat.MEDIUM;
else if (style.equals("long")) else if (style.equals("long"))
val = DateFormat.LONG; val = DateFormat.LONG;
else if (style.equals("full")) else if (style.equals("full"))
val = DateFormat.FULL; val = DateFormat.FULL;
if (type.equals("time")) if (type.equals("time"))
format = DateFormat.getTimeInstance(val, loc); format = DateFormat.getTimeInstance(val, loc);
else else
format = DateFormat.getDateInstance(val, loc); format = DateFormat.getDateInstance(val, loc);
if (style != null && val == DateFormat.DEFAULT) if (style != null && val == DateFormat.DEFAULT)
{ {
SimpleDateFormat sdf = (SimpleDateFormat) format; SimpleDateFormat sdf = (SimpleDateFormat) format;
sdf.applyPattern(style); sdf.applyPattern(style);
} }
} }
else if (type.equals("choice")) else if (type.equals("choice"))
{ {
formatClass = java.lang.Number.class; formatClass = java.lang.Number.class;
if (style == null) if (style == null)
throw new throw new
IllegalArgumentException ("style required for choice format"); IllegalArgumentException ("style required for choice format");
format = new ChoiceFormat (style); format = new ChoiceFormat (style);
} }
} }
} }
public class MessageFormat extends Format public class MessageFormat extends Format
...@@ -137,403 +137,469 @@ public class MessageFormat extends Format ...@@ -137,403 +137,469 @@ public class MessageFormat extends Format
// string. Throws IllegalArgumentException on error. // string. Throws IllegalArgumentException on error.
private static final int scanString (String pat, int index, private static final int scanString (String pat, int index,
StringBuffer buffer) StringBuffer buffer)
{ {
int max = pat.length(); int max = pat.length();
buffer.setLength(0); buffer.setLength(0);
for (; index < max; ++index) for (; index < max; ++index)
{ {
char c = pat.charAt(index); char c = pat.charAt(index);
if (c == '\'' && index + 2 < max && pat.charAt(index + 2) == '\'') if (c == '\'' && index + 2 < max && pat.charAt(index + 2) == '\'')
{ {
buffer.append(pat.charAt(index + 1)); buffer.append(pat.charAt(index + 1));
index += 2; index += 2;
} }
else if (c == '\'' && index + 1 < max else if (c == '\'' && index + 1 < max
&& pat.charAt(index + 1) == '\'') && pat.charAt(index + 1) == '\'')
{ {
buffer.append(c);
++index;
}
else if (c == '{')
break;
else if (c == '}')
throw new IllegalArgumentException ();
else
buffer.append(c); buffer.append(c);
} ++index;
return index; }
} else if (c == '{')
break;
else if (c == '}')
throw new IllegalArgumentException ();
else
buffer.append(c);
}
return index;
}
// This helper retrieves a single part of a format element. Returns // This helper retrieves a single part of a format element. Returns
// the index of the terminating character. // the index of the terminating character.
private static final int scanFormatElement (String pat, int index, private static final int scanFormatElement (String pat, int index,
StringBuffer buffer, StringBuffer buffer,
char term) char term)
{ {
int max = pat.length(); int max = pat.length();
buffer.setLength(0); buffer.setLength(0);
int brace_depth = 1; int brace_depth = 1;
for (; index < max; ++index) for (; index < max; ++index)
{ {
char c = pat.charAt(index); char c = pat.charAt(index);
if (c == '\'' && index + 2 < max && pat.charAt(index + 2) == '\'') if (c == '\'' && index + 2 < max && pat.charAt(index + 2) == '\'')
{ {
buffer.append(c); buffer.append(c);
buffer.append(pat.charAt(index + 1)); buffer.append(pat.charAt(index + 1));
buffer.append(c); buffer.append(c);
index += 2; index += 2;
} }
else if (c == '\'' && index + 1 < max else if (c == '\'' && index + 1 < max
&& pat.charAt(index + 1) == '\'') && pat.charAt(index + 1) == '\'')
{ {
buffer.append(c);
++index;
}
else if (c == '{')
{
buffer.append(c);
++brace_depth;
}
else if (c == '}')
{
if (--brace_depth == 0)
break;
buffer.append(c);
}
// Check for TERM after braces, because TERM might be `}'.
else if (c == term)
break;
else
buffer.append(c); buffer.append(c);
} ++index;
return index; }
} else if (c == '{')
{
buffer.append(c);
++brace_depth;
}
else if (c == '}')
{
if (--brace_depth == 0)
break;
buffer.append(c);
}
// Check for TERM after braces, because TERM might be `}'.
else if (c == term)
break;
else
buffer.append(c);
}
return index;
}
// This is used to parse a format element and whatever non-format // This is used to parse a format element and whatever non-format
// text might trail it. // text might trail it.
private static final int scanFormat (String pat, int index, private static final int scanFormat (String pat, int index,
StringBuffer buffer, Vector elts, StringBuffer buffer, Vector elts,
Locale locale) Locale locale)
{ {
MessageFormatElement mfe = new MessageFormatElement (); MessageFormatElement mfe = new MessageFormatElement ();
elts.addElement(mfe); elts.addElement(mfe);
int max = pat.length(); int max = pat.length();
// Skip the opening `{'. // Skip the opening `{'.
++index; ++index;
// Fetch the argument number. // Fetch the argument number.
index = scanFormatElement (pat, index, buffer, ','); index = scanFormatElement (pat, index, buffer, ',');
try try
{ {
mfe.argNumber = Integer.parseInt(buffer.toString()); mfe.argNumber = Integer.parseInt(buffer.toString());
} }
catch (NumberFormatException nfx) catch (NumberFormatException nfx)
{ {
throw new IllegalArgumentException ();
}
// Extract the element format.
if (index < max && pat.charAt(index) == ',')
{
index = scanFormatElement (pat, index + 1, buffer, ',');
mfe.type = buffer.toString();
// Extract the style.
if (index < max && pat.charAt(index) == ',')
{
index = scanFormatElement (pat, index + 1, buffer, '}');
mfe.style = buffer.toString ();
}
}
// Advance past the last terminator.
if (index >= max || pat.charAt(index) != '}')
throw new IllegalArgumentException (); throw new IllegalArgumentException ();
++index; }
// Now fetch trailing string. // Extract the element format.
index = scanString (pat, index, buffer); if (index < max && pat.charAt(index) == ',')
mfe.trailer = buffer.toString (); {
index = scanFormatElement (pat, index + 1, buffer, ',');
mfe.setLocale(locale); mfe.type = buffer.toString();
return index; // Extract the style.
} if (index < max && pat.charAt(index) == ',')
{
index = scanFormatElement (pat, index + 1, buffer, '}');
mfe.style = buffer.toString ();
}
}
// Advance past the last terminator.
if (index >= max || pat.charAt(index) != '}')
throw new IllegalArgumentException ();
++index;
// Now fetch trailing string.
index = scanString (pat, index, buffer);
mfe.trailer = buffer.toString ();
mfe.setLocale(locale);
return index;
}
/**
* Applies the specified pattern to this MessageFormat.
*
* @param aPattern The Pattern
*/
public void applyPattern (String newPattern) public void applyPattern (String newPattern)
{ {
pattern = newPattern; pattern = newPattern;
StringBuffer tempBuffer = new StringBuffer (); StringBuffer tempBuffer = new StringBuffer ();
int index = scanString (newPattern, 0, tempBuffer); int index = scanString (newPattern, 0, tempBuffer);
leader = tempBuffer.toString(); leader = tempBuffer.toString();
Vector elts = new Vector (); Vector elts = new Vector ();
while (index < newPattern.length()) while (index < newPattern.length())
index = scanFormat (newPattern, index, tempBuffer, elts, locale); index = scanFormat (newPattern, index, tempBuffer, elts, locale);
elements = new MessageFormatElement[elts.size()]; elements = new MessageFormatElement[elts.size()];
elts.copyInto(elements); elts.copyInto(elements);
} }
/**
* Overrides Format.clone()
*/
public Object clone () public Object clone ()
{ {
MessageFormat c = new MessageFormat (); MessageFormat c = (MessageFormat) super.clone ();
c.setLocale(locale); c.elements = (MessageFormatElement[]) elements.clone ();
c.applyPattern(pattern); return c;
return (Object) c; }
}
/**
* Overrides Format.equals(Object obj)
*/
public boolean equals (Object obj) public boolean equals (Object obj)
{ {
if (! (obj instanceof MessageFormat)) if (! (obj instanceof MessageFormat))
return false; return false;
MessageFormat mf = (MessageFormat) obj; MessageFormat mf = (MessageFormat) obj;
return (pattern.equals(mf.pattern) return (pattern.equals(mf.pattern)
&& locale.equals(mf.locale)); && locale.equals(mf.locale));
} }
/**
* A convinience method to format patterns.
*
* @param aPattern The pattern used when formatting.
* @param arguments The array containing the objects to be formatted.
*/
public static String format (String pattern, Object arguments[]) public static String format (String pattern, Object arguments[])
{ {
MessageFormat mf = new MessageFormat (pattern); MessageFormat mf = new MessageFormat (pattern);
StringBuffer sb = new StringBuffer (); StringBuffer sb = new StringBuffer ();
FieldPosition fp = new FieldPosition (NumberFormat.INTEGER_FIELD); FieldPosition fp = new FieldPosition (NumberFormat.INTEGER_FIELD);
return mf.format(arguments, sb, fp).toString(); return mf.format(arguments, sb, fp).toString();
} }
/**
* Returns the pattern with the formatted objects.
*
* @param source The array containing the objects to be formatted.
* @param result The StringBuffer where the text is appened.
* @param fp A FieldPosition object (it is ignored).
*/
public final StringBuffer format (Object arguments[], StringBuffer appendBuf, public final StringBuffer format (Object arguments[], StringBuffer appendBuf,
FieldPosition ignore) FieldPosition ignore)
{ {
appendBuf.append(leader); appendBuf.append(leader);
for (int i = 0; i < elements.length; ++i)
{
if (elements[i].argNumber >= arguments.length)
throw new IllegalArgumentException ();
Object thisArg = arguments[elements[i].argNumber];
Format formatter = null;
if (elements[i].setFormat != null)
formatter = elements[i].setFormat;
else if (elements[i].format != null)
{
if (elements[i].formatClass != null
&& ! elements[i].formatClass.isInstance(thisArg))
throw new IllegalArgumentException ();
formatter = elements[i].format;
}
else if (thisArg instanceof Number)
formatter = NumberFormat.getInstance(locale);
else if (thisArg instanceof Date)
formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
else
appendBuf.append(thisArg);
if (formatter != null)
{
// Special-case ChoiceFormat.
if (formatter instanceof ChoiceFormat)
{
StringBuffer buf = new StringBuffer ();
// FIXME: don't actually know what is correct here.
// Can a sub-format refer to any argument, or just
// the single argument passed to it? Must test
// against JDK.
formatter.format(thisArg, buf, ignore);
MessageFormat mf = new MessageFormat ();
mf.setLocale(locale);
mf.applyPattern(buf.toString());
formatter = mf;
}
formatter.format(thisArg, appendBuf, ignore);
}
appendBuf.append(elements[i].trailer);
}
return appendBuf;
}
for (int i = 0; i < elements.length; ++i)
{
if (elements[i].argNumber >= arguments.length)
throw new IllegalArgumentException ();
Object thisArg = arguments[elements[i].argNumber];
Format formatter = null;
if (elements[i].setFormat != null)
formatter = elements[i].setFormat;
else if (elements[i].format != null)
{
if (elements[i].formatClass != null
&& ! elements[i].formatClass.isInstance(thisArg))
throw new IllegalArgumentException ();
formatter = elements[i].format;
}
else if (thisArg instanceof Number)
formatter = NumberFormat.getInstance(locale);
else if (thisArg instanceof Date)
formatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, locale);
else
appendBuf.append(thisArg);
if (formatter != null)
{
// Special-case ChoiceFormat.
if (formatter instanceof ChoiceFormat)
{
StringBuffer buf = new StringBuffer ();
// FIXME: don't actually know what is correct here.
// Can a sub-format refer to any argument, or just
// the single argument passed to it? Must test
// against JDK.
formatter.format(thisArg, buf, ignore);
MessageFormat mf = new MessageFormat ();
mf.setLocale(locale);
mf.applyPattern(buf.toString());
formatter = mf;
}
formatter.format(thisArg, appendBuf, ignore);
}
appendBuf.append(elements[i].trailer);
}
return appendBuf;
}
/**
* Returns the pattern with the formatted objects.
*
* @param source The object to be formatted.
* @param result The StringBuffer where the text is appened.
* @param fp A FieldPosition object (it is ignored).
*/
public final StringBuffer format (Object singleArg, StringBuffer appendBuf, public final StringBuffer format (Object singleArg, StringBuffer appendBuf,
FieldPosition ignore) FieldPosition ignore)
{ {
Object[] args; Object[] args;
if (singleArg instanceof Object[]) if (singleArg instanceof Object[])
{ {
// This isn't specified in any manual, but it follows the // This isn't specified in any manual, but it follows the
// JDK implementation. // JDK implementation.
args = (Object[]) singleArg; args = (Object[]) singleArg;
} }
else else
{ {
args = new Object[1]; args = new Object[1];
args[0] = singleArg; args[0] = singleArg;
} }
return format (args, appendBuf, ignore); return format (args, appendBuf, ignore);
} }
/**
* Returns an array with the Formats for
* the arguments.
*/
public Format[] getFormats () public Format[] getFormats ()
{ {
Format[] f = new Format[elements.length]; Format[] f = new Format[elements.length];
for (int i = elements.length - 1; i >= 0; --i) for (int i = elements.length - 1; i >= 0; --i)
f[i] = elements[i].setFormat; f[i] = elements[i].setFormat;
return f; return f;
} }
/**
* Returns the locale.
*/
public Locale getLocale () public Locale getLocale ()
{ {
return locale; return locale;
} }
/**
* Overrides Format.hashCode()
*/
public int hashCode () public int hashCode ()
{ {
// FIXME: not a very good hash. // FIXME: not a very good hash.
return pattern.hashCode() + locale.hashCode(); return pattern.hashCode() + locale.hashCode();
} }
private MessageFormat () private MessageFormat ()
{ {
} }
/**
* Creates a new MessageFormat object with
* the specified pattern
*
* @param aPattern The Pattern
*/
public MessageFormat (String pattern) public MessageFormat (String pattern)
{ {
locale = Locale.getDefault(); locale = Locale.getDefault();
applyPattern (pattern); applyPattern (pattern);
} }
public Object[] parse (String sourceStr, ParsePosition pos) public Object[] parse (String sourceStr, ParsePosition pos)
{ {
// Check initial text. // Check initial text.
int index = pos.getIndex(); int index = pos.getIndex();
if (! sourceStr.startsWith(leader, index)) if (! sourceStr.startsWith(leader, index))
{ {
pos.setErrorIndex(index); pos.setErrorIndex(index);
return null; return null;
} }
index += leader.length(); index += leader.length();
Vector results = new Vector (elements.length, 1); Vector results = new Vector (elements.length, 1);
// Now check each format. // Now check each format.
for (int i = 0; i < elements.length; ++i) for (int i = 0; i < elements.length; ++i)
{ {
Format formatter = null; Format formatter = null;
if (elements[i].setFormat != null) if (elements[i].setFormat != null)
formatter = elements[i].setFormat; formatter = elements[i].setFormat;
else if (elements[i].format != null) else if (elements[i].format != null)
formatter = elements[i].format; formatter = elements[i].format;
Object value = null; Object value = null;
if (formatter instanceof ChoiceFormat) if (formatter instanceof ChoiceFormat)
{ {
// We must special-case a ChoiceFormat because it might // We must special-case a ChoiceFormat because it might
// have recursive formatting. // have recursive formatting.
ChoiceFormat cf = (ChoiceFormat) formatter; ChoiceFormat cf = (ChoiceFormat) formatter;
String[] formats = (String[]) cf.getFormats(); String[] formats = (String[]) cf.getFormats();
double[] limits = (double[]) cf.getLimits(); double[] limits = (double[]) cf.getLimits();
MessageFormat subfmt = new MessageFormat (); MessageFormat subfmt = new MessageFormat ();
subfmt.setLocale(locale); subfmt.setLocale(locale);
ParsePosition subpos = new ParsePosition (index); ParsePosition subpos = new ParsePosition (index);
int j; int j;
for (j = 0; value == null && j < limits.length; ++j) for (j = 0; value == null && j < limits.length; ++j)
{ {
subfmt.applyPattern(formats[j]); subfmt.applyPattern(formats[j]);
subpos.setIndex(index); subpos.setIndex(index);
value = subfmt.parse(sourceStr, subpos); value = subfmt.parse(sourceStr, subpos);
} }
if (value != null) if (value != null)
{ {
index = subpos.getIndex(); index = subpos.getIndex();
value = new Double (limits[j]); value = new Double (limits[j]);
} }
} }
else if (formatter != null) else if (formatter != null)
{ {
pos.setIndex(index); pos.setIndex(index);
value = formatter.parseObject(sourceStr, pos); value = formatter.parseObject(sourceStr, pos);
if (value != null) if (value != null)
index = pos.getIndex(); index = pos.getIndex();
} }
else else
{ {
// We have a String format. This can lose in a number // We have a String format. This can lose in a number
// of ways, but we give it a shot. // of ways, but we give it a shot.
int next_index = sourceStr.indexOf(elements[i].trailer, index); int next_index = sourceStr.indexOf(elements[i].trailer, index);
if (next_index == -1) if (next_index == -1)
{ {
pos.setErrorIndex(index); pos.setErrorIndex(index);
return null; return null;
} }
value = sourceStr.substring(index, next_index); value = sourceStr.substring(index, next_index);
index = next_index; index = next_index;
} }
if (value == null if (value == null
|| ! sourceStr.startsWith(elements[i].trailer, index)) || ! sourceStr.startsWith(elements[i].trailer, index))
{ {
pos.setErrorIndex(index); pos.setErrorIndex(index);
return null; return null;
} }
if (elements[i].argNumber >= results.size()) if (elements[i].argNumber >= results.size())
results.setSize(elements[i].argNumber + 1); results.setSize(elements[i].argNumber + 1);
results.setElementAt(value, elements[i].argNumber); results.setElementAt(value, elements[i].argNumber);
index += elements[i].trailer.length(); index += elements[i].trailer.length();
} }
Object[] r = new Object[results.size()]; Object[] r = new Object[results.size()];
results.copyInto(r); results.copyInto(r);
return r; return r;
} }
public Object[] parse (String sourceStr) throws ParseException public Object[] parse (String sourceStr) throws ParseException
{ {
ParsePosition pp = new ParsePosition (0); ParsePosition pp = new ParsePosition (0);
Object[] r = parse (sourceStr, pp); Object[] r = parse (sourceStr, pp);
if (r == null) if (r == null)
throw new ParseException ("couldn't parse string", pp.getErrorIndex()); throw new ParseException ("couldn't parse string", pp.getErrorIndex());
return r; return r;
} }
public Object parseObject (String sourceStr, ParsePosition pos) public Object parseObject (String sourceStr, ParsePosition pos)
{ {
return parse (sourceStr, pos); return parse (sourceStr, pos);
} }
/**
* Sets the format for the argument at an specified
* index.
*
* @param index The index.
* @format The Format object.
*/
public void setFormat (int variableNum, Format newFormat) public void setFormat (int variableNum, Format newFormat)
{ {
elements[variableNum].setFormat = newFormat; elements[variableNum].setFormat = newFormat;
} }
/**
* Sets the formats for the arguments.
*
* @param formats An array of Format objects.
*/
public void setFormats (Format[] newFormats) public void setFormats (Format[] newFormats)
{ {
if (newFormats.length < elements.length) if (newFormats.length < elements.length)
throw new IllegalArgumentException (); throw new IllegalArgumentException ();
int len = Math.min(newFormats.length, elements.length); int len = Math.min(newFormats.length, elements.length);
for (int i = 0; i < len; ++i) for (int i = 0; i < len; ++i)
elements[i].setFormat = newFormats[i]; elements[i].setFormat = newFormats[i];
} }
/**
* Sets the locale.
*
* @param locale A Locale
*/
public void setLocale (Locale loc) public void setLocale (Locale loc)
{ {
locale = loc; locale = loc;
if (elements != null) if (elements != null)
{ {
for (int i = 0; i < elements.length; ++i) for (int i = 0; i < elements.length; ++i)
elements[i].setLocale(loc); elements[i].setLocale(loc);
} }
} }
/**
* Returns the pattern.
*/
public String toPattern () public String toPattern ()
{ {
return pattern; return pattern;
} }
// The pattern string. // The pattern string.
private String pattern; private String pattern;
......
// RuleBasedCollator.java - Concrete class for locale-based string compare. // RuleBasedCollator.java - Concrete class for locale-based string compare.
/* Copyright (C) 1999, 2000 Free Software Foundation /* Copyright (C) 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -39,7 +39,10 @@ public class RuleBasedCollator extends Collator ...@@ -39,7 +39,10 @@ public class RuleBasedCollator extends Collator
{ {
public Object clone () public Object clone ()
{ {
return new RuleBasedCollator (this); RuleBasedCollator c = (RuleBasedCollator) super.clone ();
c.map = (Hashtable) map.clone ();
c.prefixes = (Hashtable) map.clone ();
return c;
} }
// A helper for CollationElementIterator.next(). // A helper for CollationElementIterator.next().
...@@ -352,17 +355,6 @@ public class RuleBasedCollator extends Collator ...@@ -352,17 +355,6 @@ public class RuleBasedCollator extends Collator
} }
} }
// This is a helper for clone.
private RuleBasedCollator (RuleBasedCollator other)
{
frenchAccents = other.frenchAccents;
rules = other.rules;
decmp = other.decmp;
strength = other.strength;
map = other.map;
prefixes = other.prefixes;
}
// True if we are using French-style accent ordering. // True if we are using French-style accent ordering.
private boolean frenchAccents; private boolean frenchAccents;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment