2004-01-07 Michael Koch <konqueror@gmx.de>

* java/text/CollationElementIterator.java
	(textIndex): Renamed from index.
	* java/text/CollationKey.java
	(collator): New member.
	(CollationKey): New argument for parent collator.
	(equals): Check for same collator, source string and key array.
	* java/text/RuleBasedCollator.java:
	Reformated.
	(RuleBasedCollator): Don't re-initialize frenchAccents with default
	value.
	(getCollationElementIterator): Rewritten.
	(getCollationKey): Added new argument to CollationKey constructor.

From-SVN: r75510
This commit is contained in:
Michael Koch 2004-01-07 18:40:08 +00:00 committed by Michael Koch
parent 677e7ddcee
commit 9b773289f8
4 changed files with 57 additions and 31 deletions

View File

@ -1,3 +1,18 @@
2004-01-07 Michael Koch <konqueror@gmx.de>
* java/text/CollationElementIterator.java
(textIndex): Renamed from index.
* java/text/CollationKey.java
(collator): New member.
(CollationKey): New argument for parent collator.
(equals): Check for same collator, source string and key array.
* java/text/RuleBasedCollator.java:
Reformated.
(RuleBasedCollator): Don't re-initialize frenchAccents with default
value.
(getCollationElementIterator): Rewritten.
(getCollationKey): Added new argument to CollationKey constructor.
2004-01-07 Michael Koch <konqueror@gmx.de> 2004-01-07 Michael Koch <konqueror@gmx.de>
* gnu/java/nio/DatagramChannelImpl.java * gnu/java/nio/DatagramChannelImpl.java

View File

@ -76,7 +76,7 @@ public final class CollationElementIterator
/** /**
* This is the index into the String where we are currently scanning. * This is the index into the String where we are currently scanning.
*/ */
int index; int textIndex;
// A piece of lookahead. // A piece of lookahead.
boolean lookahead_set; boolean lookahead_set;
@ -107,7 +107,7 @@ public final class CollationElementIterator
*/ */
public int next() public int next()
{ {
if (index == text.length()) if (textIndex == text.length())
return NULLORDER; return NULLORDER;
return collator.ceiNext (this); return collator.ceiNext (this);
@ -133,7 +133,7 @@ public final class CollationElementIterator
*/ */
public void reset() public void reset()
{ {
index = 0; textIndex = 0;
} }
/** /**
@ -175,7 +175,7 @@ public final class CollationElementIterator
public void setText(String text) public void setText(String text)
{ {
this.text = text; this.text = text;
this.index = 0; this.textIndex = 0;
this.lookahead_set = false; this.lookahead_set = false;
this.lookahead = 0; this.lookahead = 0;
} }
@ -190,6 +190,6 @@ public final class CollationElementIterator
*/ */
public int getOffset() public int getOffset()
{ {
return index; return textIndex;
} }
} }

View File

@ -65,6 +65,11 @@ package java.text;
*/ */
public final class CollationKey implements Comparable public final class CollationKey implements Comparable
{ {
/**
* This is the <code>Collator</code> this object was created from.
*/
private Collator collator;
/** /**
* This is the <code>String</code> this object represents. * This is the <code>String</code> this object represents.
*/ */
@ -75,9 +80,10 @@ public final class CollationKey implements Comparable
*/ */
private int[] key; private int[] key;
CollationKey (CollationElementIterator iter, String originalText, CollationKey(Collator collator, CollationElementIterator iter,
int strength) String originalText, int strength)
{ {
this.collator = collator;
this.originalText = originalText; this.originalText = originalText;
// Compute size of required array. // Compute size of required array.
@ -153,12 +159,14 @@ public final class CollationKey implements Comparable
CollationKey ck = (CollationKey) obj; CollationKey ck = (CollationKey) obj;
if (key.length != ck.key.length) if (ck.collator != collator)
return false; return false;
for (int i = 0; i < key.length; ++i) if (!ck.getSourceString ().equals (getSourceString ()))
if (key[i] != ck.key[i]) return false;
return false;
if (!ck.toByteArray ().equals (toByteArray ()))
return false;
return true; return true;
} }

View File

@ -152,13 +152,12 @@ public class RuleBasedCollator extends Collator
String key; String key;
char relation; char relation;
CollationElement (String key, char relation) CollationElement(String key, char relation)
{ {
this.key = key; this.key = key;
this.relation = relation; this.relation = relation;
} }
}
} // inner class CollationElement
// True if we are using French-style accent ordering. // True if we are using French-style accent ordering.
private boolean frenchAccents; private boolean frenchAccents;
@ -188,21 +187,21 @@ public class RuleBasedCollator extends Collator
*/ */
public RuleBasedCollator(String rules) throws ParseException public RuleBasedCollator(String rules) throws ParseException
{ {
if (rules.equals ("")) if (rules.equals(""))
throw new ParseException ("empty rule set", 0); throw new ParseException("empty rule set", 0);
this.rules = rules; this.rules = rules;
this.frenchAccents = false;
// We keep each rule in order in a vector. At the end we traverse // We keep each rule in order in a vector. At the end we traverse
// the vector and compute collation values from it. // the vector and compute collation values from it.
int insertion_index = 0; int insertion_index = 0;
Vector vec = new Vector (); Vector vec = new Vector ();
StringBuffer argument = new StringBuffer (); int index;
StringBuffer argument = new StringBuffer();
int len = rules.length(); int len = rules.length();
for (int index = 0; index < len; ++index)
for (index = 0; index < len; ++index)
{ {
char c = rules.charAt(index); char c = rules.charAt(index);
@ -339,7 +338,7 @@ public class RuleBasedCollator extends Collator
return cei.lookahead; return cei.lookahead;
} }
int save = cei.index; int save = cei.textIndex;
int max = cei.text.length(); int max = cei.text.length();
String s = null; String s = null;
@ -368,7 +367,7 @@ public class RuleBasedCollator extends Collator
} }
// Update state. // Update state.
cei.index = i; cei.textIndex = i;
if (obj == null) if (obj == null)
{ {
@ -490,10 +489,12 @@ public class RuleBasedCollator extends Collator
*/ */
public CollationElementIterator getCollationElementIterator(String source) public CollationElementIterator getCollationElementIterator(String source)
{ {
StringBuffer expand = new StringBuffer (source.length()); int len = source.length();
int max = source.length(); StringBuffer expand = new StringBuffer(len);
for (int i = 0; i < max; ++i)
decomposeCharacter (source.charAt(i), expand); for (int index = 0; index < len; ++index)
decomposeCharacter(source.charAt(index), expand);
return new CollationElementIterator(this, expand.toString()); return new CollationElementIterator(this, expand.toString());
} }
@ -508,11 +509,13 @@ public class RuleBasedCollator extends Collator
*/ */
public CollationElementIterator getCollationElementIterator(CharacterIterator source) public CollationElementIterator getCollationElementIterator(CharacterIterator source)
{ {
StringBuffer expand = new StringBuffer(); StringBuffer expand = new StringBuffer("");
for (char c = source.first ();
// Right now we assume that we will read from the beginning of the string.
for (char c = source.first();
c != CharacterIterator.DONE; c != CharacterIterator.DONE;
c = source.next ()) c = source.next())
decomposeCharacter (c, expand); decomposeCharacter(c, expand);
return new CollationElementIterator(this, expand.toString()); return new CollationElementIterator(this, expand.toString());
} }
@ -530,7 +533,7 @@ public class RuleBasedCollator extends Collator
*/ */
public CollationKey getCollationKey(String source) public CollationKey getCollationKey(String source)
{ {
return new CollationKey(getCollationElementIterator(source), source, return new CollationKey(this, getCollationElementIterator(source), source,
strength); strength);
} }