Removed jni files
X-SVN-Rev: 4025
This commit is contained in:
parent
7ad7d69bb1
commit
92a37cb35a
@ -1,181 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/common/Attic/ErrorCode.java,v $
|
||||
* $Date: 2001/03/09 23:40:35 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu4jni.common;
|
||||
|
||||
/**
|
||||
* Error exception class mapping ICU error codes of the enum UErrorCode
|
||||
* @author syn wee quek
|
||||
* @since Jan 18 01
|
||||
*/
|
||||
public final class ErrorCode extends Exception
|
||||
{
|
||||
// static library loading ---------------------------------------
|
||||
|
||||
static
|
||||
{
|
||||
ErrorCode.LIBRARY_LOADED = true;
|
||||
System.loadLibrary("icuinterface");
|
||||
}
|
||||
|
||||
// public methods --------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generic mapping from the error codes to java default exceptions.
|
||||
* @param error error code
|
||||
* @return java default exception that maps to the argument error code,
|
||||
* otherwise if error is not a valid error code, null is returned.
|
||||
*/
|
||||
public static final RuntimeException getException(int error)
|
||||
{
|
||||
if (error <= U_ZERO_ERROR && error >= U_ERROR_LIMIT) {
|
||||
return null;
|
||||
}
|
||||
String errorname = ERROR_NAMES_[U_ILLEGAL_ARGUMENT_ERROR];
|
||||
switch (error) {
|
||||
case U_ILLEGAL_ARGUMENT_ERROR :
|
||||
return new IllegalArgumentException(errorname);
|
||||
case U_INDEX_OUTOFBOUNDS_ERROR :
|
||||
return new ArrayIndexOutOfBoundsException(errorname);
|
||||
case U_BUFFER_OVERFLOW_ERROR :
|
||||
return new ArrayIndexOutOfBoundsException(errorname);
|
||||
case U_UNSUPPORTED_ERROR :
|
||||
return new UnsupportedOperationException(errorname);
|
||||
default :
|
||||
return new RuntimeException(errorname);
|
||||
}
|
||||
}
|
||||
|
||||
// public static data member ---------------------------------------------
|
||||
|
||||
/**
|
||||
* Start of information results (semantically successful)
|
||||
*/
|
||||
public static final int U_ERROR_INFO_START = -128;
|
||||
/**
|
||||
* A resource bundle lookup returned a fallback result (not an error)
|
||||
*/
|
||||
public static final int U_USING_FALLBACK_ERROR = -128;
|
||||
/**
|
||||
* A resource bundle lookup returned a result from the root locale (not an
|
||||
* error)
|
||||
*/
|
||||
public static final int U_USING_DEFAULT_ERROR = -127;
|
||||
/**
|
||||
* This must always be the last warning value to indicate the limit for
|
||||
* UErrorCode warnings (last warning code +1)
|
||||
*/
|
||||
public static final int U_ERROR_INFO_LIMIT = -126;
|
||||
|
||||
/**
|
||||
* No error, no warning
|
||||
*/
|
||||
public static final int U_ZERO_ERROR = 0;
|
||||
/**
|
||||
* Start of codes indicating failure
|
||||
*/
|
||||
public static final int U_ILLEGAL_ARGUMENT_ERROR = 1;
|
||||
public static final int U_MISSING_RESOURCE_ERROR = 2;
|
||||
public static final int U_INVALID_FORMAT_ERROR = 3;
|
||||
public static final int U_FILE_ACCESS_ERROR = 4;
|
||||
/**
|
||||
* Indicates a bug in the library code
|
||||
*/
|
||||
public static final int U_INTERNAL_PROGRAM_ERROR = 5;
|
||||
public static final int U_MESSAGE_PARSE_ERROR = 6;
|
||||
/**
|
||||
* Memory allocation error
|
||||
*/
|
||||
public static final int U_MEMORY_ALLOCATION_ERROR = 7;
|
||||
public static final int U_INDEX_OUTOFBOUNDS_ERROR = 8;
|
||||
/**
|
||||
* Equivalent to Java ParseException
|
||||
*/
|
||||
public static final int U_PARSE_ERROR = 9;
|
||||
/**
|
||||
* In the Character conversion routines: Invalid character or sequence was
|
||||
* encountered
|
||||
*/
|
||||
public static final int U_INVALID_CHAR_FOUND = 10;
|
||||
/**
|
||||
* In the Character conversion routines: More bytes are required to complete
|
||||
* the conversion successfully
|
||||
*/
|
||||
public static final int U_TRUNCATED_CHAR_FOUND = 11;
|
||||
/**
|
||||
* In codeset conversion: a sequence that does NOT belong in the codepage has
|
||||
* been encountered
|
||||
*/
|
||||
public static final int U_ILLEGAL_CHAR_FOUND = 12;
|
||||
/**
|
||||
* Conversion table file found, but corrupted
|
||||
*/
|
||||
public static final int U_INVALID_TABLE_FORMAT = 13;
|
||||
/**
|
||||
* Conversion table file not found
|
||||
*/
|
||||
public static final int U_INVALID_TABLE_FILE = 14;
|
||||
/**
|
||||
* A result would not fit in the supplied buffer
|
||||
*/
|
||||
public static final int U_BUFFER_OVERFLOW_ERROR = 15;
|
||||
/**
|
||||
* Requested operation not supported in current context
|
||||
*/
|
||||
public static final int U_UNSUPPORTED_ERROR = 16;
|
||||
/**
|
||||
* an operation is requested over a resource that does not support it
|
||||
*/
|
||||
public static final int U_RESOURCE_TYPE_MISMATCH = 17;
|
||||
/**
|
||||
* ISO-2022 illlegal escape sequence
|
||||
*/
|
||||
public static final int U_ILLEGAL_ESCAPE_SEQUENCE = 18;
|
||||
/**
|
||||
* ISO-2022 unsupported escape sequence
|
||||
*/
|
||||
public static final int U_UNSUPPORTED_ESCAPE_SEQUENCE = 19;
|
||||
/**
|
||||
* No space available for in-buffer expansion for Arabic shaping
|
||||
*/
|
||||
public static final int U_NO_SPACE_AVAILABLE = 20;
|
||||
/**
|
||||
* This must always be the last value to indicate the limit for UErrorCode
|
||||
* (last error code +1)
|
||||
*/
|
||||
public static final int U_ERROR_LIMIT = 21;
|
||||
/**
|
||||
* Load library flag
|
||||
*/
|
||||
public static boolean LIBRARY_LOADED = false;
|
||||
|
||||
// private data member ----------------------------------------------------
|
||||
|
||||
/**
|
||||
* Array of error code names corresponding to the errorcodes.
|
||||
* ie ERROR_NAMES_[0] = name of U_ZERO_ERROR
|
||||
*/
|
||||
private static final String ERROR_NAMES_[] = {
|
||||
"U_ZERO_ERROR", "U_ILLEGAL_ARGUMENT_ERROR",
|
||||
"U_MISSING_RESOURCE_ERROR", "U_INVALID_FORMAT_ERROR",
|
||||
"U_FILE_ACCESS_ERROR", "U_INTERNAL_PROGRAM_ERROR",
|
||||
"U_MESSAGE_PARSE_ERROR", "U_MEMORY_ALLOCATION_ERROR",
|
||||
"U_INDEX_OUTOFBOUNDS_ERROR", "U_PARSE_ERROR",
|
||||
"U_INVALID_CHAR_FOUND", "U_TRUNCATED_CHAR_FOUND",
|
||||
"U_ILLEGAL_CHAR_FOUND", "U_INVALID_TABLE_FORMAT",
|
||||
"U_INVALID_TABLE_FILE", "U_BUFFER_OVERFLOW_ERROR",
|
||||
"U_UNSUPPORTED_ERROR", "U_RESOURCE_TYPE_MISMATCH",
|
||||
"U_ILLEGAL_ESCAPE_SEQUENCE", "U_UNSUPPORTED_ESCAPE_SEQUENCE"
|
||||
};
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/test/Attic/TestAll.java,v $
|
||||
* $Date: 2001/03/09 23:41:08 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu4jni.test;
|
||||
|
||||
/**
|
||||
* Top level test used to run all other tests as a batch.
|
||||
*/
|
||||
|
||||
public class TestAll extends TestFmwk {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new TestAll().run(args);
|
||||
}
|
||||
|
||||
public void TestCollation() throws Exception{
|
||||
run(new TestFmwk[] {
|
||||
//new com.ibm.icu4jni.test.text.CollatorTest(),
|
||||
new com.ibm.icu4jni.test.text.CollationElementIteratorTest()
|
||||
});
|
||||
}
|
||||
}
|
@ -1,272 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/test/Attic/TestFmwk.java,v $
|
||||
* $Date: 2001/03/09 23:41:08 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu4jni.test;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
import java.io.*;
|
||||
import java.text.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* TestFmwk is a base class for tests that can be run conveniently from
|
||||
* the command line as well as under the Java test harness.
|
||||
* <p>
|
||||
* Sub-classes implement a set of methods named Test<something>. Each
|
||||
* of these methods performs some test. Test methods should indicate
|
||||
* errors by calling either err or errln. This will increment the
|
||||
* errorCount field and may optionally print a message to the log.
|
||||
* Debugging information may also be added to the log via the log
|
||||
* and logln methods. These methods will add their arguments to the
|
||||
* log only if the test is being run in verbose mode.
|
||||
*/
|
||||
|
||||
public class TestFmwk implements TestLog {
|
||||
|
||||
/**
|
||||
* Puts a copyright in the .class file
|
||||
*/
|
||||
private static final String copyrightNotice
|
||||
= "Copyright \u00a92001-2002 IBM Corp. All rights reserved.";
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Everything below here is boilerplate code that makes it possible
|
||||
// to add a new test by simply adding a function to an existing class
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
protected TestFmwk() {
|
||||
// Create a hashtable containing all the test methods.
|
||||
testMethods = new Hashtable();
|
||||
Method[] methods = getClass().getDeclaredMethods();
|
||||
for( int i=0; i<methods.length; i++ ) {
|
||||
if( methods[i].getName().startsWith("Test")
|
||||
|| methods[i].getName().startsWith("test")) {
|
||||
testMethods.put( methods[i].getName(), methods[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _run() throws Exception {
|
||||
writeTestName(getClass().getName());
|
||||
params.indentLevel++;
|
||||
Enumeration methodsToRun;
|
||||
|
||||
if (testsToRun != null && testsToRun.size() >= 1) {
|
||||
methodsToRun = testsToRun.elements();
|
||||
} else {
|
||||
methodsToRun = testMethods.elements();
|
||||
}
|
||||
|
||||
int oldClassCount = params.errorCount;
|
||||
|
||||
// Run the list of tests given in the test arguments
|
||||
while (methodsToRun.hasMoreElements()) {
|
||||
int oldCount = params.errorCount;
|
||||
|
||||
Method testMethod = (Method)methodsToRun.nextElement();
|
||||
writeTestName(testMethod.getName());
|
||||
|
||||
try {
|
||||
testMethod.invoke(this, new Object[0]);
|
||||
} catch( IllegalAccessException e ) {
|
||||
errln("Can't access test method " + testMethod.getName());
|
||||
} catch( InvocationTargetException e ) {
|
||||
errln("Uncaught exception \""+e+"\" thrown in test method "
|
||||
+ testMethod.getName());
|
||||
e.getTargetException().printStackTrace(this.params.log);
|
||||
}
|
||||
writeTestResult(params.errorCount - oldCount);
|
||||
}
|
||||
params.indentLevel--;
|
||||
writeTestResult(params.errorCount - oldClassCount);
|
||||
}
|
||||
|
||||
public void run(String[] args) throws Exception {
|
||||
if (params == null) params = new TestParams();
|
||||
// Parse the test arguments. They can be either the flag
|
||||
// "-verbose" or names of test methods. Create a list of
|
||||
// tests to be run.
|
||||
testsToRun = new Vector(args.length);
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i].equals("-verbose") || args[i].equals("-v")) {
|
||||
params.verbose = true;
|
||||
}
|
||||
else if (args[i].equals("-prompt")) {
|
||||
params.prompt = true;
|
||||
} else if (args[i].equals("-nothrow")) {
|
||||
params.nothrow = true;
|
||||
} else {
|
||||
Object m = testMethods.get(args[i]);
|
||||
if (m != null) {
|
||||
testsToRun.addElement(m);
|
||||
} else {
|
||||
usage();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (params == null) params = new TestParams();
|
||||
_run();
|
||||
|
||||
if (params.prompt) {
|
||||
System.out.println("Hit RETURN to exit...");
|
||||
try {
|
||||
System.in.read();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Exception: " + e.toString() + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (params.nothrow) {
|
||||
System.exit(params.errorCount);
|
||||
}
|
||||
}
|
||||
|
||||
protected void run(TestFmwk childTest) throws Exception {
|
||||
run(new TestFmwk[] { childTest });
|
||||
}
|
||||
|
||||
protected void run(TestFmwk[] tests) throws Exception {
|
||||
for (int i=0; i<tests.length; ++i) {
|
||||
tests[i].params = this.params;
|
||||
params.indentLevel++;
|
||||
tests[i]._run();
|
||||
params.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isVerbose() {
|
||||
return params.verbose;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds given string to the log if we are in verbose mode.
|
||||
*/
|
||||
public void log( String message ) {
|
||||
if( params.verbose ) {
|
||||
indent(params.indentLevel + 1);
|
||||
params.log.print( message );
|
||||
params.log.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void logln( String message ) {
|
||||
log(message + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an error
|
||||
*/
|
||||
public void err( String message ) {
|
||||
params.errorCount++;
|
||||
indent(params.indentLevel + 1);
|
||||
params.log.print( message );
|
||||
params.log.flush();
|
||||
|
||||
if (!params.nothrow) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void errln( String message ) {
|
||||
err(message + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
protected int getErrorCount() {
|
||||
return params.errorCount;
|
||||
}
|
||||
|
||||
protected void writeTestName(String testName) {
|
||||
indent(params.indentLevel);
|
||||
params.log.print(testName);
|
||||
params.log.flush();
|
||||
params.needLineFeed = true;
|
||||
}
|
||||
|
||||
protected void writeTestResult(int count) {
|
||||
if (!params.needLineFeed) {
|
||||
indent(params.indentLevel);
|
||||
params.log.print("}");
|
||||
}
|
||||
params.needLineFeed = false;
|
||||
|
||||
if (count != 0) {
|
||||
params.log.println(" FAILED (" + count + " failures)");
|
||||
} else {
|
||||
params.log.println(" Passed");
|
||||
}
|
||||
}
|
||||
|
||||
private final void indent(int distance) {
|
||||
if (params.needLineFeed) {
|
||||
params.log.println(" {");
|
||||
params.needLineFeed = false;
|
||||
}
|
||||
params.log.print(spaces.substring(0, distance * 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a usage message for this test class.
|
||||
*/
|
||||
void usage() {
|
||||
System.out.println(getClass().getName() +
|
||||
": [-verbose] [-nothrow] [-prompt] [test names]");
|
||||
|
||||
System.out.println("test names:");
|
||||
Enumeration methodNames = testMethods.keys();
|
||||
while( methodNames.hasMoreElements() ) {
|
||||
System.out.println("\t" + methodNames.nextElement() );
|
||||
}
|
||||
}
|
||||
|
||||
public static String hex(char ch) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
String foo = Integer.toString(ch,16).toUpperCase();
|
||||
for (int i = foo.length(); i < 4; ++i) {
|
||||
result.append('0');
|
||||
}
|
||||
return result + foo;
|
||||
}
|
||||
|
||||
public static String hex(String s) {
|
||||
StringBuffer result = new StringBuffer();
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
if (i != 0) result.append(',');
|
||||
result.append(hex(s.charAt(i)));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String hex(StringBuffer s) {
|
||||
return hex(s.toString());
|
||||
}
|
||||
|
||||
private static class TestParams {
|
||||
public boolean prompt = false;
|
||||
public boolean nothrow = false;
|
||||
public boolean verbose = false;
|
||||
|
||||
public PrintWriter log = new PrintWriter(System.out,true);
|
||||
public int indentLevel = 0;
|
||||
public boolean needLineFeed = false;
|
||||
public int errorCount = 0;
|
||||
}
|
||||
|
||||
private TestParams params = null;
|
||||
private Hashtable testMethods;
|
||||
private Vector testsToRun;
|
||||
private final String spaces = " ";
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.ibm.icu4jni.test;
|
||||
|
||||
public interface TestLog {
|
||||
|
||||
/**
|
||||
* Adds given string to the log if we are in verbose mode.
|
||||
*/
|
||||
void log(String message);
|
||||
|
||||
void logln(String message);
|
||||
|
||||
/**
|
||||
* Report an error
|
||||
*/
|
||||
void err(String message);
|
||||
|
||||
void errln(String message);
|
||||
}
|
@ -1,152 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Attic/CollationAttribute.java,v $
|
||||
* $Date: 2001/03/09 23:42:30 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu4jni.text;
|
||||
|
||||
/**
|
||||
* Interface for storing ICU collation equivalent enum values.
|
||||
* Constants with the prefix VALUE corresponds to ICU's UColAttributeValues,
|
||||
* the rest corresponds to UColAttribute.
|
||||
* @author syn wee quek
|
||||
* @since Jan 18 01
|
||||
*/
|
||||
|
||||
public final class CollationAttribute
|
||||
{
|
||||
// Collation strength constants ----------------------------------
|
||||
|
||||
/**
|
||||
* Primary collation strength
|
||||
*/
|
||||
public static final int VALUE_PRIMARY = 0;
|
||||
/**
|
||||
* Secondary collation strength
|
||||
*/
|
||||
public static final int VALUE_SECONDARY = 1;
|
||||
/**
|
||||
* Tertiary collation strength
|
||||
*/
|
||||
public static final int VALUE_TERTIARY = 2;
|
||||
/**
|
||||
* Default collation strength
|
||||
*/
|
||||
public static final int VALUE_DEFAULT_STRENGTH = VALUE_TERTIARY;
|
||||
/**
|
||||
* Quaternary collation strength
|
||||
*/
|
||||
public static final int VALUE_QUATERNARY = 3;
|
||||
/**
|
||||
* Identical collation strength
|
||||
*/
|
||||
public static final int VALUE_IDENTICAL = 15;
|
||||
|
||||
// French collation mode constants ---------------------------------
|
||||
// FRENCH_COLLATION; CASE_LEVEL & DECOMPOSITION_MODE
|
||||
public static final int VALUE_OFF = 16;
|
||||
public static final int VALUE_ON = 17;
|
||||
|
||||
// ALTERNATE_HANDLING mode constants --------------------------
|
||||
public static final int VALUE_SHIFTED = 20;
|
||||
public static final int VALUE_NON_IGNORABLE = 21;
|
||||
|
||||
// CASE_FIRST mode constants ----------------------------------
|
||||
public static final int VALUE_LOWER_FIRST = 24;
|
||||
public static final int VALUE_UPPER_FIRST = 25;
|
||||
|
||||
// NORMALIZATION_MODE mode constants --------------------------
|
||||
public static final int VALUE_ON_WITHOUT_HANGUL = 28;
|
||||
|
||||
// Number of attribute value constants -----------------------------
|
||||
public static final int VALUE_ATTRIBUTE_VALUE_COUNT = 29;
|
||||
|
||||
// Collation attribute constants -----------------------------------
|
||||
|
||||
// attribute for direction of secondary weights
|
||||
public static final int FRENCH_COLLATION = 0;
|
||||
// attribute for handling variable elements
|
||||
public static final int ALTERNATE_HANDLING = 1;
|
||||
// who goes first, lower case or uppercase
|
||||
public static final int CASE_FIRST = 2;
|
||||
// do we have an extra case level
|
||||
public static final int CASE_LEVEL = 3;
|
||||
// attribute for normalization
|
||||
public static final int NORMALIZATION_MODE = 4;
|
||||
// attribute for strength
|
||||
public static final int STRENGTH = 5;
|
||||
// attribute count
|
||||
public static final int ATTRIBUTE_COUNT = 6;
|
||||
|
||||
// public methods --------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks if argument is a valid collation strength
|
||||
* @param strength potential collation strength
|
||||
* @return true if strength is a valid collation strength, false otherwise
|
||||
*/
|
||||
protected static boolean checkStrength(int strength)
|
||||
{
|
||||
if (strength < VALUE_PRIMARY ||
|
||||
(strength > VALUE_QUATERNARY && strength != VALUE_IDENTICAL))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if argument is a valid collation type
|
||||
* @param type collation type to be checked
|
||||
* @return true if type is a valid collation type, false otherwise
|
||||
*/
|
||||
protected static boolean checkType(int type)
|
||||
{
|
||||
if (type < FRENCH_COLLATION || type > STRENGTH)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if attribute type and corresponding attribute value is valid
|
||||
* @param type attribute type
|
||||
* @param value attribute value
|
||||
* @return true if the pair is valid, false otherwise
|
||||
*/
|
||||
protected static boolean checkAttribute(int type, int value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case FRENCH_COLLATION :
|
||||
if (value >= VALUE_OFF && value <= VALUE_ON)
|
||||
return true;
|
||||
break;
|
||||
case ALTERNATE_HANDLING :
|
||||
if (value >= VALUE_SHIFTED &&
|
||||
value <= VALUE_NON_IGNORABLE)
|
||||
return true;
|
||||
break;
|
||||
case CASE_FIRST :
|
||||
if (value >= VALUE_LOWER_FIRST &&
|
||||
value <= VALUE_UPPER_FIRST)
|
||||
return true;
|
||||
break;
|
||||
case CASE_LEVEL :
|
||||
if (value >= VALUE_LOWER_FIRST &&
|
||||
value <= VALUE_UPPER_FIRST)
|
||||
return true;
|
||||
break;
|
||||
case NORMALIZATION_MODE :
|
||||
return NormalizationMode.check(value);
|
||||
case STRENGTH :
|
||||
checkStrength(value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/CollationElementIterator.java,v $
|
||||
* $Date: 2001/03/09 23:42:30 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu4jni.text;
|
||||
|
||||
import com.ibm.icu4jni.common.ErrorCode;
|
||||
|
||||
/**
|
||||
* Collation element iterator JNI wrapper
|
||||
* @author syn wee quek
|
||||
* @since Jan 22 01
|
||||
*/
|
||||
|
||||
public final class CollationElementIterator
|
||||
{
|
||||
// public data member -------------------------------------------
|
||||
|
||||
public static final int NULLORDER = 0xFFFFFFFF;
|
||||
|
||||
// public methods -----------------------------------------------
|
||||
|
||||
/**
|
||||
* Reset the collation elements to their initial state.
|
||||
* This will move the 'cursor' to the beginning of the text.
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
NativeCollation.reset(m_collelemiterator_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ordering priority of the next collation element in the text.
|
||||
* A single character may contain more than one collation element.
|
||||
* @return next collation elements ordering, or NULLORDER if the end of the
|
||||
* text is reached.
|
||||
*/
|
||||
public int next()
|
||||
{
|
||||
return NativeCollation.next(m_collelemiterator_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ordering priority of the previous collation element in the text.
|
||||
* A single character may contain more than one collation element.
|
||||
* @return previous collation element ordering, or NULLORDER if the end of
|
||||
* the text is reached.
|
||||
*/
|
||||
public int previous()
|
||||
{
|
||||
return NativeCollation.previous(m_collelemiterator_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum length of any expansion sequences that end with the
|
||||
* specified comparison order.
|
||||
* @param order collation order returned by previous or next.
|
||||
* @return maximum size of the expansion sequences ending with the collation
|
||||
* element or 1 if collation element does not occur at the end of any
|
||||
* expansion sequence
|
||||
*/
|
||||
public int getMaxExpansion(int order)
|
||||
{
|
||||
return NativeCollation.getMaxExpansion(m_collelemiterator_, order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text containing the collation elements.
|
||||
* @param source text containing the collation elements.
|
||||
*/
|
||||
public void setText(String source)
|
||||
{
|
||||
NativeCollation.setText(m_collelemiterator_, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the offset of the current source character.
|
||||
* This is an offset into the text of the character containing the current
|
||||
* collation elements.
|
||||
* @return offset of the current source character.
|
||||
*/
|
||||
public int getOffset()
|
||||
{
|
||||
return NativeCollation.getOffset(m_collelemiterator_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the offset of the current source character.
|
||||
* This is an offset into the text of the character to be processed.
|
||||
* @param offset The desired character offset.
|
||||
*/
|
||||
public void setOffset(int offset)
|
||||
{
|
||||
NativeCollation.setOffset(m_collelemiterator_, offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the primary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the primary order of a collation order.
|
||||
*/
|
||||
public static int primaryOrder(int order)
|
||||
{
|
||||
return NativeCollation.primaryOrder(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the secondary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the secondary order of a collation order.
|
||||
*/
|
||||
public static int secondaryOrder(int order)
|
||||
{
|
||||
return NativeCollation.secondaryOrder(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tertiary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the tertiary order of a collation order.
|
||||
*/
|
||||
public static int tertiaryOrder(int order)
|
||||
{
|
||||
return NativeCollation.tertiaryOrder(order);
|
||||
}
|
||||
|
||||
// protected constructor ----------------------------------------
|
||||
|
||||
/**
|
||||
* CollationElementIteratorJNI constructor.
|
||||
* The only caller of this class should be
|
||||
* RuleBasedCollator.getCollationElementIterator().
|
||||
* @param collelemiteratoraddress address of C collationelementiterator
|
||||
*/
|
||||
CollationElementIterator(long collelemiteratoraddress)
|
||||
{
|
||||
m_collelemiterator_ = collelemiteratoraddress;
|
||||
}
|
||||
|
||||
// protected methods --------------------------------------------
|
||||
|
||||
/**
|
||||
* Set ownership for C collator element iterator
|
||||
* @param ownership true or false
|
||||
*/
|
||||
/*
|
||||
void setOwnCollationElementIterator(boolean ownership)
|
||||
{
|
||||
m_owncollelemiterator_ = ownership;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Garbage collection.
|
||||
* Close C collator and reclaim memory.
|
||||
*/
|
||||
protected void finalize()
|
||||
{
|
||||
// if (m_owncollelemiterator_)
|
||||
NativeCollation.closeElements(m_collelemiterator_);
|
||||
}
|
||||
|
||||
// private data members -----------------------------------------
|
||||
|
||||
/**
|
||||
* C collator
|
||||
*/
|
||||
private long m_collelemiterator_;
|
||||
|
||||
/**
|
||||
* Flag indicating if the C data associated with m_collelemiterator_ is
|
||||
* created by this object. This flag is used to determine if the C data is
|
||||
* to be destroyed when this object is garbage-collected.
|
||||
*/
|
||||
// private boolean m_owncollelemiterator_ = false;
|
||||
}
|
@ -1,185 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/CollationKey.java,v $
|
||||
* $Date: 2001/03/09 23:42:30 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu4jni.text;
|
||||
|
||||
/**
|
||||
* Collation key wrapper.
|
||||
* @author syn wee quek
|
||||
* @since Jan 23 01
|
||||
*/
|
||||
|
||||
public final class CollationKey implements Comparable
|
||||
{
|
||||
// public methods -----------------------------------------------
|
||||
|
||||
/**
|
||||
* Bitwise comparison for the collation keys
|
||||
* @param target CollationKey to be compared
|
||||
* @return comparison result from Collator, RESULT_LESS, RESULT_EQUAL,
|
||||
* RESULT_GREATER
|
||||
*/
|
||||
public int compareTo(CollationKey target)
|
||||
{
|
||||
byte tgtbytes[] = target.m_bytes_;
|
||||
|
||||
if (m_bytes_ == null || m_bytes_.length == 0) {
|
||||
if (tgtbytes == null || tgtbytes.length == 0) {
|
||||
return Collator.RESULT_EQUAL;
|
||||
}
|
||||
return Collator.RESULT_LESS;
|
||||
}
|
||||
else {
|
||||
if (tgtbytes == null || tgtbytes.length == 0) {
|
||||
return Collator.RESULT_GREATER;
|
||||
}
|
||||
}
|
||||
|
||||
int count = m_bytes_.length;
|
||||
if (tgtbytes.length < count) {
|
||||
count = tgtbytes.length;
|
||||
}
|
||||
|
||||
int s,
|
||||
t;
|
||||
for (int i = 0; i < count; i ++)
|
||||
{
|
||||
s = m_bytes_[i] & UNSIGNED_BYTE_MASK_;
|
||||
t = tgtbytes[i] & UNSIGNED_BYTE_MASK_;
|
||||
if (s < t) {
|
||||
return Collator.RESULT_LESS;
|
||||
}
|
||||
if (s > t) {
|
||||
return Collator.RESULT_GREATER;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bytes_.length < target.m_bytes_.length) {
|
||||
return Collator.RESULT_LESS;
|
||||
}
|
||||
|
||||
if (m_bytes_.length > target.m_bytes_.length) {
|
||||
return Collator.RESULT_GREATER;
|
||||
}
|
||||
|
||||
return Collator.RESULT_EQUAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bitwise comparison for the collation keys.
|
||||
* Argument is casted to CollationKey
|
||||
* @param target CollationKey to be compared
|
||||
* @return comparison result from Collator, RESULT_LESS, RESULT_EQUAL,
|
||||
* RESULT_GREATER
|
||||
*/
|
||||
public int compareTo(Object target)
|
||||
{
|
||||
return compareTo((CollationKey)target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if target object is equal to this object.
|
||||
* Target is first casted to CollationKey and bitwise compared.
|
||||
* @param target comparison object
|
||||
* @return true if both objects are equal, false otherwise
|
||||
*/
|
||||
public boolean equals(Object target)
|
||||
{
|
||||
if (this == target) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// checks getClass here since CollationKey is final not subclassable
|
||||
if (target == null || target.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return compareTo((CollationKey)target) == Collator.RESULT_EQUAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a hash code for this CollationKey.
|
||||
* Compute the hash by iterating sparsely over about 32 (up to 63) bytes
|
||||
* spaced evenly through the string. For each byte, multiply the previous
|
||||
* hash value by a prime number and add the new byte in, like a linear
|
||||
* congruential random number generator, producing a pseudorandom
|
||||
* deterministic value well distributed over the output range.
|
||||
* @return hash value of collation key. Hash value is never 0.
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
if (m_hash_ == 0)
|
||||
{
|
||||
if (m_bytes_ != null || m_bytes_.length != 0)
|
||||
{
|
||||
int len = m_bytes_.length;
|
||||
int inc = ((len - 32) / 32) + 1;
|
||||
for (int i = 0; i < len;)
|
||||
{
|
||||
m_hash_ = (m_hash_ * 37) + m_bytes_[i];
|
||||
i += inc;
|
||||
}
|
||||
}
|
||||
if (m_hash_ == 0)
|
||||
m_hash_ = 1;
|
||||
}
|
||||
return m_hash_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the value of the Collation key in term of bytes
|
||||
* @return value of Collation key in bytes
|
||||
*/
|
||||
public byte[] toByteArray()
|
||||
{
|
||||
if (m_bytes_ == null || m_bytes_.length == 0)
|
||||
return null;
|
||||
|
||||
byte[] result = new byte[m_bytes_.length];
|
||||
|
||||
return (byte[])m_bytes_.clone();
|
||||
}
|
||||
|
||||
// package constructors ----------------------------------------------
|
||||
|
||||
/**
|
||||
* Default constructor, for use by the Collator and its subclasses.
|
||||
*/
|
||||
CollationKey()
|
||||
{
|
||||
m_hash_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor, for use only by the Collator and its subclasses.
|
||||
*/
|
||||
CollationKey(byte[] bytes)
|
||||
{
|
||||
m_bytes_ = bytes;
|
||||
m_hash_ = 0;
|
||||
}
|
||||
|
||||
// private data members -----------------------------------------------
|
||||
|
||||
private byte m_bytes_[];
|
||||
|
||||
/**
|
||||
* Mask value to retrieve a single unsigned byte
|
||||
*/
|
||||
private static final int UNSIGNED_BYTE_MASK_ = 0x00FF;
|
||||
|
||||
/**
|
||||
* Cached hash value
|
||||
*/
|
||||
private int m_hash_;
|
||||
}
|
@ -1,203 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Collator.java,v $
|
||||
* $Date: 2001/03/09 23:42:30 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu4jni.text;
|
||||
|
||||
import java.util.Locale;
|
||||
import com.ibm.icu4jni.text.RuleBasedCollator;
|
||||
|
||||
/**
|
||||
* Abstract class for C Collation.
|
||||
* Considerations :
|
||||
* 1) ErrorCode not returned to user throw exceptions instead
|
||||
* 2) Similar API to java.text.Collator
|
||||
* @author syn wee quek
|
||||
* @since Jan 17 01
|
||||
*/
|
||||
|
||||
public abstract class Collator implements Cloneable
|
||||
{
|
||||
// public data member -------------------------------------------
|
||||
|
||||
// Collation result constants -----------------------------------
|
||||
// corresponds to ICU's UCollationResult enum balues
|
||||
/**
|
||||
* string a == string b
|
||||
*/
|
||||
public static final int RESULT_EQUAL = 0;
|
||||
/**
|
||||
* string a > string b
|
||||
*/
|
||||
public static final int RESULT_GREATER = 1;
|
||||
/**
|
||||
* string a < string b
|
||||
*/
|
||||
public static final int RESULT_LESS = -1;
|
||||
/**
|
||||
* accepted by most attributes
|
||||
*/
|
||||
public static final int RESULT_DEFAULT = -1;
|
||||
|
||||
// public methods -----------------------------------------------
|
||||
|
||||
/**
|
||||
* Factory method to create an appropriate Collator which uses the default
|
||||
* locale collation rules.
|
||||
* Current implementation createInstance() returns a RuleBasedCollator(Locale)
|
||||
* instance. The RuleBasedCollator will be created in the following order,
|
||||
* <ul>
|
||||
* <li> Data from argument locale resource bundle if found, otherwise
|
||||
* <li> Data from parent locale resource bundle of arguemtn locale if found,
|
||||
* otherwise
|
||||
* <li> Data from built-in default collation rules if found, other
|
||||
* <li> null is returned
|
||||
* </ul>
|
||||
* @return an instance of Collator
|
||||
*/
|
||||
public static Collator getInstance()
|
||||
{
|
||||
return getInstance(Locale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to create an appropriate Collator which uses the argument
|
||||
* locale collation rules.<br>
|
||||
* Current implementation createInstance() returns a RuleBasedCollator(Locale)
|
||||
* instance. The RuleBasedCollator will be created in the following order,
|
||||
* <ul>
|
||||
* <li> Data from argument locale resource bundle if found, otherwise
|
||||
* <li> Data from parent locale resource bundle of arguemtn locale if found,
|
||||
* otherwise
|
||||
* <li> Data from built-in default collation rules if found, other
|
||||
* <li> null is returned
|
||||
* </ul>
|
||||
* @param locale to be used for collation
|
||||
* @return an instance of Collator
|
||||
*/
|
||||
public static Collator getInstance(Locale locale)
|
||||
{
|
||||
RuleBasedCollator result = new RuleBasedCollator(locale);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equality check for the argument strings.
|
||||
* @param source string
|
||||
* @param target string
|
||||
* @return true if source is equivalent to target, false otherwise
|
||||
*/
|
||||
public boolean equals(String source, String target)
|
||||
{
|
||||
return (compare(source, target) == RESULT_EQUAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if argument object is equals to this object.
|
||||
* @param target object
|
||||
* @return true if source is equivalent to target, false otherwise
|
||||
*/
|
||||
public abstract boolean equals(Object target);
|
||||
|
||||
/**
|
||||
* Makes a copy of the current object.
|
||||
* @return a copy of this object
|
||||
*/
|
||||
public abstract Object clone() throws CloneNotSupportedException;
|
||||
|
||||
/**
|
||||
* The comparison function compares the character data stored in two
|
||||
* different strings. Returns information about whether a string is less
|
||||
* than, greater than or equal to another string.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . Collator myCollation = Collator.createInstance(Locale::US);
|
||||
* . myCollation.setStrength(Collation.PRIMARY);
|
||||
* . // result would be Collation.EQUAL ("abc" == "ABC")
|
||||
* . // (no primary difference between "abc" and "ABC")
|
||||
* . int result = myCollation.compare("abc", "ABC",3);
|
||||
* . myCollation.setStrength(Collation.TERTIARY);
|
||||
* . // result would be Collation.LESS (abc" <<< "ABC")
|
||||
* . // (with tertiary difference between "abc" and "ABC")
|
||||
* . int result = myCollation.compare("abc", "ABC",3);
|
||||
* </pre>
|
||||
* @param source source string.
|
||||
* @param target target string.
|
||||
* @return result of the comparison, Collation.EQUAL, Collation.GREATER
|
||||
* or Collation.LESS
|
||||
*/
|
||||
public abstract int compare(String source, String target);
|
||||
|
||||
/**
|
||||
* Get the decomposition mode of this Collator
|
||||
* Return values from com.ibm.icu4jni.text.Normalization.
|
||||
* @return the decomposition mode
|
||||
*/
|
||||
public abstract int getDecomposition();
|
||||
|
||||
/**
|
||||
* Set the decomposition mode of the Collator object.
|
||||
* Argument values from com.ibm.icu4jni.text.Normalization.
|
||||
* @param decompositionmode the new decomposition mode
|
||||
*/
|
||||
public abstract void setDecomposition(int mode);
|
||||
|
||||
/**
|
||||
* Determines the minimum strength that will be use in comparison or
|
||||
* transformation.
|
||||
* <p>
|
||||
* E.g. with strength == Collation.SECONDARY, the tertiary difference
|
||||
* is ignored
|
||||
* </p>
|
||||
* <p>
|
||||
* E.g. with strength == PRIMARY, the secondary and tertiary difference are
|
||||
* ignored.
|
||||
* </p>
|
||||
* @return the current comparison level.
|
||||
*/
|
||||
public abstract int getStrength();
|
||||
|
||||
/**
|
||||
* Sets the minimum strength to be used in comparison or transformation.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . Collator myCollation = Collator.createInstance(Locale::US);
|
||||
* . myCollation.setStrength(Collation.PRIMARY);
|
||||
* . // result will be "abc" == "ABC"
|
||||
* . // tertiary differences will be ignored
|
||||
* . int result = myCollation->compare("abc", "ABC");
|
||||
* </pre>
|
||||
* @param strength the new comparison level.
|
||||
*/
|
||||
public abstract void setStrength(int strength);
|
||||
|
||||
/**
|
||||
* Get the sort key as an CollationKey object from the argument string.
|
||||
* To retrieve sort key in terms of byte arrays, use the method as below<br>
|
||||
* <code>
|
||||
* Collator collator = Collator.getInstance();
|
||||
* CollationKey collationkey = collator.getCollationKey("string");
|
||||
* byte[] array = collationkey.toByteArray();
|
||||
* </code><br>
|
||||
* Byte array result are zero-terminated and can be compared using
|
||||
* java.util.Arrays.equals();
|
||||
* @param source string to be processed.
|
||||
* @return the sort key
|
||||
*/
|
||||
public abstract CollationKey getCollationKey(String source);
|
||||
|
||||
/**
|
||||
* Returns a hash of this collation object
|
||||
* @return hash of this collation object
|
||||
*/
|
||||
public abstract int hashCode();
|
||||
}
|
@ -1,247 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Attic/NativeCollation.java,v $
|
||||
* $Date: 2001/03/09 23:42:30 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu4jni.text;
|
||||
|
||||
import com.ibm.icu4jni.common.ErrorCode;
|
||||
|
||||
/**
|
||||
* Package static class for declaring all native methods for collation use.
|
||||
* @author syn wee quek
|
||||
* @since Mar 05 2001
|
||||
*/
|
||||
|
||||
final class NativeCollation
|
||||
{
|
||||
// library loading ----------------------------------------------
|
||||
|
||||
static {
|
||||
if (ErrorCode.LIBRARY_LOADED)
|
||||
System.out.println("test");
|
||||
}
|
||||
|
||||
// collator methods ---------------------------------------------
|
||||
|
||||
/**
|
||||
* Method to create a new C Collator using the argument locale rules.
|
||||
* @param locale locale name
|
||||
* @return new c collator
|
||||
*/
|
||||
static native long openCollator(String locale);
|
||||
|
||||
/**
|
||||
* Method to create a new C Collator using the argument rules.
|
||||
* @param rules, set of collation rules
|
||||
* @param normalizationmode default normalization mode
|
||||
* @param collationstrength default collation strength
|
||||
* @return new c collator
|
||||
*/
|
||||
static native long openCollatorFromRules(String rules,
|
||||
int normalizationmode,
|
||||
int collationstrength);
|
||||
|
||||
/**
|
||||
* Close a C collator
|
||||
* Once closed, a UCollatorOld should not be used.
|
||||
* @param coll The UCollatorOld to close
|
||||
*/
|
||||
static native void closeCollator(long collatoraddress);
|
||||
|
||||
/**
|
||||
* Compare two strings.
|
||||
* The strings will be compared using the normalization mode and options
|
||||
* specified in openCollator or openCollatorFromRules
|
||||
* @param collatoraddress address of the c collator
|
||||
* @param source The source string.
|
||||
* @param target The target string.
|
||||
* @return result of the comparison, Collation.EQUAL,
|
||||
* Collation.GREATER or Collation.LESS
|
||||
*/
|
||||
static native int compare(long collatoraddress, String source,
|
||||
String target);
|
||||
|
||||
/**
|
||||
* Get the normalization mode for this object.
|
||||
* The normalization mode influences how strings are compared.
|
||||
* @param collatoraddress
|
||||
* @return normalization mode; one of the values from Normalization
|
||||
*/
|
||||
static native int getNormalization(long collatoraddress);
|
||||
|
||||
/**
|
||||
* Set the normalization mode used int this object
|
||||
* The normalization mode influences how strings are compared.
|
||||
* @param collatoraddress the address of the C collator
|
||||
* @param normalizationmode desired normalization mode; one of the values
|
||||
* from Normalization
|
||||
*/
|
||||
static native void setNormalization(long collatoraddress,
|
||||
int normalizationmode);
|
||||
|
||||
/**
|
||||
* Get the collation rules from a UCollator.
|
||||
* The rules will follow the rule syntax.
|
||||
* @param collatoraddress the address of the C collator
|
||||
* @return collation rules.
|
||||
*/
|
||||
static native String getRules(long collatoraddress);
|
||||
|
||||
/**
|
||||
* Get a sort key for the argument string
|
||||
* Sort keys may be compared using java.util.Arrays.equals
|
||||
* @param collatoraddress address of the C collator
|
||||
* @param source string for key to be generated
|
||||
* @return sort key
|
||||
*/
|
||||
static native byte[] getSortKey(long collatoraddress, String source);
|
||||
|
||||
/**
|
||||
* Gets the version information for collation.
|
||||
* @param collatoraddress address of the C collator
|
||||
* @return version information
|
||||
*/
|
||||
// private native String getVersion(int collatoraddress);
|
||||
|
||||
/**
|
||||
* Universal attribute setter.
|
||||
* @param collatoraddress address of the C collator
|
||||
* @param type type of attribute to be set
|
||||
* @param value attribute value
|
||||
* @exception thrown when error occurs while setting attribute value
|
||||
*/
|
||||
static native void setAttribute(long collatoraddress, int type, int value);
|
||||
|
||||
/**
|
||||
* Universal attribute getter
|
||||
* @param collatoraddress address of the C collator
|
||||
* @param type type of attribute to be set
|
||||
* @return attribute value
|
||||
* @exception thrown when error occurs while getting attribute value
|
||||
*/
|
||||
static native int getAttribute(long collatoraddress, int type);
|
||||
|
||||
/**
|
||||
* Thread safe cloning operation
|
||||
* @param collatoraddress address of C collator to be cloned
|
||||
* @return address of the new clone
|
||||
* @exception thrown when error occurs while cloning
|
||||
*/
|
||||
static native long safeClone(long collatoraddress);
|
||||
|
||||
/**
|
||||
* Create a CollationElementIterator object that will iterator over the
|
||||
* elements in a string, using the collation rules defined in this
|
||||
* RuleBasedCollator
|
||||
* @param collatoraddress address of C collator
|
||||
* @param source string to iterate over
|
||||
* @return address of C collationelementiterator
|
||||
*/
|
||||
static native long getCollationElementIterator(long collatoraddress,
|
||||
String source);
|
||||
|
||||
/**
|
||||
* Returns a hash of this collation object
|
||||
* @param collatoraddress address of C collator
|
||||
* @return hash of this collation object
|
||||
*/
|
||||
static native int hashCode(long collatoraddress);
|
||||
|
||||
|
||||
// collationelementiterator methods -------------------------------------
|
||||
|
||||
/**
|
||||
* Close a C collation element iterator.
|
||||
* @param address of C collation element iterator to close.
|
||||
*/
|
||||
static native void closeElements(long address);
|
||||
|
||||
/**
|
||||
* Reset the collation elements to their initial state.
|
||||
* This will move the 'cursor' to the beginning of the text.
|
||||
* @param address of C collation element iterator to reset.
|
||||
*/
|
||||
static native void reset(long address);
|
||||
|
||||
/**
|
||||
* Get the ordering priority of the next collation element in the text.
|
||||
* A single character may contain more than one collation element.
|
||||
* @param address if C collation elements containing the text.
|
||||
* @return next collation elements ordering, or NULLORDER if the end of the
|
||||
* text is reached.
|
||||
*/
|
||||
static native int next(long address);
|
||||
|
||||
/**
|
||||
* Get the ordering priority of the previous collation element in the text.
|
||||
* A single character may contain more than one collation element.
|
||||
* @param address of the C collation element iterator containing the text.
|
||||
* @return previous collation element ordering, or NULLORDER if the end of
|
||||
* the text is reached.
|
||||
*/
|
||||
static native int previous(long address);
|
||||
|
||||
/**
|
||||
* Get the maximum length of any expansion sequences that end with the
|
||||
* specified comparison order.
|
||||
* @param address of the C collation element iterator containing the text.
|
||||
* @param order collation order returned by previous or next.
|
||||
* @return maximum length of any expansion sequences ending with the
|
||||
* specified order.
|
||||
*/
|
||||
static native int getMaxExpansion(long address, int order);
|
||||
|
||||
/**
|
||||
* Set the text containing the collation elements.
|
||||
* @param address of the C collation element iterator to be set
|
||||
* @param source text containing the collation elements.
|
||||
*/
|
||||
static native void setText(long address, String source);
|
||||
|
||||
/**
|
||||
* Get the offset of the current source character.
|
||||
* This is an offset into the text of the character containing the current
|
||||
* collation elements.
|
||||
* @param addresss of the C collation elements iterator to query.
|
||||
* @return offset of the current source character.
|
||||
*/
|
||||
static native int getOffset(long address);
|
||||
|
||||
/**
|
||||
* Set the offset of the current source character.
|
||||
* This is an offset into the text of the character to be processed.
|
||||
* @param address of the C collation element iterator to set.
|
||||
* @param offset The desired character offset.
|
||||
*/
|
||||
static native void setOffset(long address, int offset);
|
||||
|
||||
/**
|
||||
* Gets the primary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the primary order of a collation order.
|
||||
*/
|
||||
static native int primaryOrder(int order);
|
||||
|
||||
/**
|
||||
* Gets the secondary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the secondary order of a collation order.
|
||||
*/
|
||||
static native int secondaryOrder(int order);
|
||||
|
||||
/**
|
||||
* Gets the tertiary order of a collation order.
|
||||
* @param order the collation order
|
||||
* @return the tertiary order of a collation order.
|
||||
*/
|
||||
static native int tertiaryOrder(int order);
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Attic/NormalizationMode.java,v $
|
||||
* $Date: 2001/03/09 23:42:30 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu4jni.text;
|
||||
|
||||
/**
|
||||
* Internal interface for storing ICU normalization equivalent enum values.
|
||||
* Used by RuleBaseCollator.
|
||||
* @author syn wee quek
|
||||
* @since Jan 18 01
|
||||
*/
|
||||
|
||||
public final class NormalizationMode
|
||||
{
|
||||
// public static data members -----------------------------------
|
||||
|
||||
public static final int NO_NORMALIZATION = 1;
|
||||
/**
|
||||
* Canonical decomposition
|
||||
*/
|
||||
public static final int DECOMP_CAN = 2;
|
||||
/**
|
||||
* Compatibility decomposition
|
||||
*/
|
||||
public static final int DECOMP_COMPAT = 3;
|
||||
/**
|
||||
* Default normalization
|
||||
*/
|
||||
public static final int DEFAULT_NORMALIZATION = DECOMP_COMPAT;
|
||||
/**
|
||||
* Canonical decomposition followed by canonical composition
|
||||
*/
|
||||
public static final int DECOMP_CAN_COMP_COMPAT = 4;
|
||||
/**
|
||||
* Compatibility decomposition followed by canonical composition
|
||||
*/
|
||||
public static final int DECOMP_COMPAT_COMP_CAN = 5;
|
||||
|
||||
/**
|
||||
* Do not normalize Hangul
|
||||
*/
|
||||
public static final int IGNORE_HANGUL = 16;
|
||||
|
||||
// public methods ------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks if argument is a valid collation strength
|
||||
* @param strength potential collation strength
|
||||
* @return true if strength is a valid collation strength, false otherwise
|
||||
*/
|
||||
static boolean check(int normalizationmode)
|
||||
{
|
||||
if (normalizationmode < NO_NORMALIZATION ||
|
||||
(normalizationmode > DECOMP_COMPAT_COMP_CAN &&
|
||||
normalizationmode != IGNORE_HANGUL))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,361 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/RuleBasedCollator.java,v $
|
||||
* $Date: 2001/03/09 23:42:30 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu4jni.text;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.text.ParseException;
|
||||
import com.ibm.icu4jni.common.ErrorCode;
|
||||
|
||||
/**
|
||||
* Concrete implementation class for Collation.
|
||||
* @author syn wee quek
|
||||
* @since Jan 17 01
|
||||
*/
|
||||
|
||||
public final class RuleBasedCollator extends Collator
|
||||
{
|
||||
// public constructors ------------------------------------------
|
||||
|
||||
/**
|
||||
* RuleBasedCollator constructor. This takes the table rules and builds a
|
||||
* collation table out of them. Please see RuleBasedCollator class
|
||||
* description for more details on the collation rule syntax.
|
||||
* @param rules the collation rules to build the collation table from.
|
||||
* @exception ParseException thrown if rules are empty or a Runtime error
|
||||
* if collator can not be created.
|
||||
*/
|
||||
public RuleBasedCollator(String rules) throws ParseException
|
||||
{
|
||||
|
||||
if (rules.length() == 0)
|
||||
throw new ParseException("Build rules empty.", 0);
|
||||
m_collator_ = NativeCollation.openCollatorFromRules(rules,
|
||||
NormalizationMode.DEFAULT_NORMALIZATION,
|
||||
CollationAttribute.VALUE_DEFAULT_STRENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* RuleBasedCollator constructor. This takes the table rules and builds a
|
||||
* collation table out of them. Please see RuleBasedCollator class
|
||||
* description for more details on the collation rule syntax.
|
||||
* @param rules the collation rules to build the collation table from.
|
||||
* @param strength collation strength
|
||||
* @exception ParseException thrown if rules are empty or a Runtime error
|
||||
* if collator can not be created.
|
||||
*/
|
||||
public RuleBasedCollator(String rules, int strength) throws ParseException
|
||||
{
|
||||
if (rules.length() == 0)
|
||||
throw new ParseException("Build rules empty.", 0);
|
||||
if (!CollationAttribute.checkStrength(strength))
|
||||
throw ErrorCode.getException(ErrorCode.U_ILLEGAL_ARGUMENT_ERROR);
|
||||
|
||||
m_collator_ = NativeCollation.openCollatorFromRules(rules,
|
||||
NormalizationMode.DEFAULT_NORMALIZATION,
|
||||
strength);
|
||||
}
|
||||
|
||||
/**
|
||||
* RuleBasedCollator constructor. This takes the table rules and builds a
|
||||
* collation table out of them. Please see RuleBasedCollator class
|
||||
* description for more details on the collation rule syntax.
|
||||
* @param rules the collation rules to build the collation table from.
|
||||
* @param strength collation strength
|
||||
* @param normalizationmode normalization mode
|
||||
* @exception thrown when constructor error occurs
|
||||
*/
|
||||
public RuleBasedCollator(String rules, int normalizationmode, int strength)
|
||||
{
|
||||
if (!CollationAttribute.checkStrength(strength) ||
|
||||
!NormalizationMode.check(normalizationmode)) {
|
||||
throw ErrorCode.getException(ErrorCode.U_ILLEGAL_ARGUMENT_ERROR);
|
||||
}
|
||||
|
||||
m_collator_ = NativeCollation.openCollatorFromRules(rules,
|
||||
normalizationmode, strength);
|
||||
}
|
||||
|
||||
// public methods -----------------------------------------------
|
||||
|
||||
/**
|
||||
* Makes a complete copy of the current object.
|
||||
* @return a copy of this object if data clone is a success, otherwise null
|
||||
*/
|
||||
public Object clone()
|
||||
{
|
||||
RuleBasedCollator result = null;
|
||||
long collatoraddress = NativeCollation.safeClone(m_collator_);
|
||||
result = new RuleBasedCollator(collatoraddress);
|
||||
return (Collator)result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The comparison function compares the character data stored in two
|
||||
* different strings. Returns information about whether a string is less
|
||||
* than, greater than or equal to another string.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . Collator myCollation = Collator.createInstance(Locale::US);
|
||||
* . myCollation.setStrength(CollationAttribute.VALUE_PRIMARY);
|
||||
* . // result would be Collator.RESULT_EQUAL ("abc" == "ABC")
|
||||
* . // (no primary difference between "abc" and "ABC")
|
||||
* . int result = myCollation.compare("abc", "ABC",3);
|
||||
* . myCollation.setStrength(CollationAttribute.VALUE_TERTIARY);
|
||||
* . // result would be Collation::LESS (abc" <<< "ABC")
|
||||
* . // (with tertiary difference between "abc" and "ABC")
|
||||
* . int result = myCollation.compare("abc", "ABC",3);
|
||||
* </pre>
|
||||
* @param source The source string.
|
||||
* @param target The target string.
|
||||
* @return result of the comparison, Collator.RESULT_EQUAL,
|
||||
* Collator.RESULT_GREATER or Collator.RESULT_LESS
|
||||
*/
|
||||
public int compare(String source, String target)
|
||||
{
|
||||
return NativeCollation.compare(m_collator_, source, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the normalization mode for this object.
|
||||
* The normalization mode influences how strings are compared.
|
||||
* @return normalization mode; one of the values from NormalizationMode
|
||||
*/
|
||||
public int getDecomposition()
|
||||
{
|
||||
return NativeCollation.getNormalization(m_collator_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the normalization mode used int this object
|
||||
* The normalization mode influences how strings are compared.
|
||||
* @param normalizationmode desired normalization mode; one of the values
|
||||
* from NormalizationMode
|
||||
* @exception thrown when argument does not belong to any normalization mode
|
||||
*/
|
||||
public void setDecomposition(int decompositionmode)
|
||||
{
|
||||
if (!NormalizationMode.check(decompositionmode))
|
||||
throw ErrorCode.getException(ErrorCode.U_ILLEGAL_ARGUMENT_ERROR);
|
||||
NativeCollation.setNormalization(m_collator_, decompositionmode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the minimum strength that will be use in comparison or
|
||||
* transformation.
|
||||
* <p>
|
||||
* E.g. with strength == CollationAttribute.VALUE_SECONDARY, the tertiary difference
|
||||
* is ignored
|
||||
* </p>
|
||||
* <p>
|
||||
* E.g. with strength == PRIMARY, the secondary and tertiary difference are
|
||||
* ignored.
|
||||
* </p>
|
||||
* @return the current comparison level.
|
||||
*/
|
||||
public int getStrength()
|
||||
{
|
||||
return NativeCollation.getAttribute(m_collator_,
|
||||
CollationAttribute.STRENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum strength to be used in comparison or transformation.
|
||||
* <p>Example of use:
|
||||
* <pre>
|
||||
* . Collator myCollation = Collator.createInstance(Locale::US);
|
||||
* . myCollation.setStrength(CollationAttribute.VALUE_PRIMARY);
|
||||
* . // result will be "abc" == "ABC"
|
||||
* . // tertiary differences will be ignored
|
||||
* . int result = myCollation->compare("abc", "ABC");
|
||||
* </pre>
|
||||
* @param strength the new comparison level.
|
||||
* @exception thrown when argument does not belong to any collation strength
|
||||
* mode or error occurs while setting data.
|
||||
*/
|
||||
public void setStrength(int strength)
|
||||
{
|
||||
if (!CollationAttribute.checkStrength(strength))
|
||||
throw ErrorCode.getException(ErrorCode.U_ILLEGAL_ARGUMENT_ERROR);
|
||||
NativeCollation.setAttribute(m_collator_, CollationAttribute.STRENGTH,
|
||||
strength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sort key as an CollationKey object from the argument string.
|
||||
* To retrieve sort key in terms of byte arrays, use the method as below<br>
|
||||
* <code>
|
||||
* Collator collator = Collator.getInstance();
|
||||
* byte[] array = collator.getSortKey(source);
|
||||
* </code><br>
|
||||
* Byte array result are zero-terminated and can be compared using
|
||||
* java.util.Arrays.equals();
|
||||
* @param source string to be processed.
|
||||
* @return the sort key
|
||||
*/
|
||||
public CollationKey getCollationKey(String source)
|
||||
{
|
||||
return new CollationKey(NativeCollation.getSortKey(m_collator_, source));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sort key for the argument string
|
||||
* Sort keys may be compared using java.util.Arrays.equals
|
||||
* @param collatoraddress address of the C collator
|
||||
* @param source string for key to be generated
|
||||
* @return sort key
|
||||
*/
|
||||
public byte[] getSortKey(String source)
|
||||
{
|
||||
return NativeCollation.getSortKey(m_collator_, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the collation rules of this Collation object
|
||||
* The rules will follow the rule syntax.
|
||||
* @return collation rules.
|
||||
*/
|
||||
public String getRules()
|
||||
{
|
||||
return NativeCollation.getRules(m_collator_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a CollationElementIterator object that will iterator over the
|
||||
* elements in a string, using the collation rules defined in this
|
||||
* RuleBasedCollator
|
||||
* @param collatoraddress address of C collator
|
||||
* @param source string to iterate over
|
||||
* @return address of C collationelement
|
||||
* @exception thrown when error occurs
|
||||
*/
|
||||
public CollationElementIterator getCollationElementIterator(String source)
|
||||
{
|
||||
CollationElementIterator result = new CollationElementIterator(
|
||||
NativeCollation.getCollationElementIterator(m_collator_, source));
|
||||
// result.setOwnCollationElementIterator(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash of this collation object
|
||||
* @return hash of this collation object
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
// since rules do not change once it is created, we can cache the hash
|
||||
if (m_hashcode_ == 0) {
|
||||
m_hashcode_ = NativeCollation.hashCode(m_collator_);
|
||||
if (m_hashcode_ == 0)
|
||||
m_hashcode_ = 1;
|
||||
}
|
||||
return m_hashcode_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if argument object is equals to this object.
|
||||
* @param target object
|
||||
* @return true if source is equivalent to target, false otherwise
|
||||
*/
|
||||
public boolean equals(Object target)
|
||||
{
|
||||
if (this == target)
|
||||
return true;
|
||||
if (target == null)
|
||||
return false;
|
||||
if (getClass() != target.getClass())
|
||||
return false;
|
||||
|
||||
long tgtcollatoraddress = ((RuleBasedCollator)target).m_collator_;
|
||||
return m_collator_ == tgtcollatoraddress;
|
||||
}
|
||||
|
||||
// package constructor ----------------------------------------
|
||||
|
||||
/**
|
||||
* RuleBasedCollator default constructor. This constructor takes the default
|
||||
* locale. The only caller of this class should be Collator.getInstance().
|
||||
* Current implementation createInstance() returns a RuleBasedCollator(Locale)
|
||||
* instance. The RuleBasedCollator will be created in the following order,
|
||||
* <ul>
|
||||
* <li> Data from argument locale resource bundle if found, otherwise
|
||||
* <li> Data from parent locale resource bundle of arguemtn locale if found,
|
||||
* otherwise
|
||||
* <li> Data from built-in default collation rules if found, other
|
||||
* <li> null is returned
|
||||
* </ul>
|
||||
* @param desiredLocale locale used
|
||||
* @param status error code status
|
||||
*/
|
||||
RuleBasedCollator()
|
||||
{
|
||||
Locale locale = Locale.getDefault();
|
||||
m_collator_ = NativeCollation.openCollator(locale.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* RuleBasedCollator constructor. This constructor takes a locale. The
|
||||
* only caller of this class should be Collator.createInstance().
|
||||
* Current implementation createInstance() returns a RuleBasedCollator(Locale)
|
||||
* instance. The RuleBasedCollator will be created in the following order,
|
||||
* <ul>
|
||||
* <li> Data from argument locale resource bundle if found, otherwise
|
||||
* <li> Data from parent locale resource bundle of arguemtn locale if found,
|
||||
* otherwise
|
||||
* <li> Data from built-in default collation rules if found, other
|
||||
* <li> null is returned
|
||||
* </ul>
|
||||
* @param desiredLocale locale used
|
||||
* @param status error code status
|
||||
*/
|
||||
RuleBasedCollator(Locale locale)
|
||||
{
|
||||
m_collator_ = NativeCollation.openCollator(locale.toString());
|
||||
}
|
||||
|
||||
// protected methods --------------------------------------------
|
||||
|
||||
/**
|
||||
* Garbage collection.
|
||||
* Close C collator and reclaim memory.
|
||||
*/
|
||||
protected void finalize()
|
||||
{
|
||||
NativeCollation.closeCollator(m_collator_);
|
||||
}
|
||||
|
||||
// private data members -----------------------------------------
|
||||
|
||||
/**
|
||||
* C collator
|
||||
*/
|
||||
private long m_collator_;
|
||||
|
||||
/**
|
||||
* Hash code for rules
|
||||
*/
|
||||
private int m_hashcode_ = 0;
|
||||
|
||||
// private constructor -----------------------------------------
|
||||
|
||||
/**
|
||||
* Private use constructor.
|
||||
* Does not create any instance of the C collator. Accepts argument as the
|
||||
* C collator for new instance.
|
||||
* @param collatoraddress address of C collator
|
||||
*/
|
||||
private RuleBasedCollator(long collatoraddress)
|
||||
{
|
||||
m_collator_ = collatoraddress;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user