Hashtable, RuleBasedCollator and natIconv (again)
Vladimir Puškaš
vpuskas@eunet.yu
Wed Mar 5 21:20:00 GMT 2003
Hi,
I am using "gcc version 3.3 20030305 (prerelease)", configured with:
"../gcc/configure --prefix=/home/support/gcc-3.3 \
--enable-threads=posix --enable-languages=c,c++,java \
--enable-java-awt=xlib", on Slackware 8.1 Linux.
I had some problems, here are solutions which work for me.
First - java.util.Hashtable
Xalan 1.2 (yes, it's old, but it's included with project I have to build
native) has a simple class "org.apache.xalan.xpath.xml.StringKey".
StringKey caches hash values of its String for fast lookups when used
in Hashtables. Idea is to fill StringKeys into hashtable, then using a
String (!?!) get values out.
hashtable.put(new StringKey("one"),new Integer(1));
hashtable.put(new StringKey("two"),new Integer(2));
hashtable.put(new StringKey("three"),new Integer(3));
someInteger = hashtable.get("two");
GNU Classpaths's Hashtable doesn't work this way. All methods use
key.equals(element), instead element.equals(key), thus invalidating the
concept, so get method returns null.
One solution is attached bellow :), other approach would be to search
and replace all hashtable gets in Xalan which use this little trick :(
Second - Tom's patch for natIconv.cc
It's discussed earlier (last August) on the list, so I'll repeat only
test class:
---sample-- (by Suresh Raman)
public class encodingtest
{
public static void main(String args[]) throws Exception
{
String encoding = "UTF-16BE";
String str = "hello world";
byte[] strbytes = str.getBytes(encoding);
String newstr = new String(strbytes, encoding);
System.out.println(newstr);
}
}
--end sample---
Third - java.text.RuleBasedCollator
Collator.getInstance throws an exception for "de" locale. Problem is in
RuleBasedCollator constructor which doesn't handle '&' reset properly.
---sample---
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Locale;
class TestCollator {
public static void main (String[]argv) throws Throwable
{
Collator c = Collator.getInstance (new Locale ("de"));
printCompare (c, "stra\u00dfe", "stra\u00dfe");
printCompare (c, "M\u00fcnchen", "Muenchen");
c = new RuleBasedCollator ("<a<b<c&c<d<e");
printCompare (c, "bc", "bc");
printCompare (c, "abcde", "abcd");
}
public static void printCompare (Collator c, String one, String two)
{
System.out.println (one +"-("+ c.compare (one, two) +")-"+ two);
}
}
--end sample---
This diff helps me, if you find it good enough to merge in, please do.
V.Puskas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-3.3.diff
Type: text/x-diff
Size: 4246 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/java/attachments/20030305/66066f6d/attachment.bin>
More information about the Java
mailing list