Search in sources :

Example 1 with CollationTailoring

use of android.icu.impl.coll.CollationTailoring in project j2objc by google.

the class CollatorServiceShim method makeInstance.

// Ported from C++ Collator::makeInstance().
private static final Collator makeInstance(ULocale desiredLocale) {
    Output<ULocale> validLocale = new Output<ULocale>(ULocale.ROOT);
    CollationTailoring t = CollationLoader.loadTailoring(desiredLocale, validLocale);
    return new RuleBasedCollator(t, validLocale.value);
}
Also used : ULocale(android.icu.util.ULocale) Output(android.icu.util.Output) CollationTailoring(android.icu.impl.coll.CollationTailoring)

Example 2 with CollationTailoring

use of android.icu.impl.coll.CollationTailoring in project j2objc by google.

the class RuleBasedCollator method internalBuildTailoring.

/**
 * Implements from-rule constructors.
 * @param rules rule string
 * @throws Exception
 */
private final void internalBuildTailoring(String rules) throws Exception {
    CollationTailoring base = CollationRoot.getRoot();
    // Most code using Collator does not need to build a Collator from rules.
    // By using reflection, most code will not have a static dependency on the builder code.
    // CollationBuilder builder = new CollationBuilder(base);
    ClassLoader classLoader = ClassLoaderUtil.getClassLoader(getClass());
    CollationTailoring t;
    try {
        Class<?> builderClass = classLoader.loadClass("android.icu.impl.coll.CollationBuilder");
        Object builder = builderClass.getConstructor(CollationTailoring.class).newInstance(base);
        // builder.parseAndBuild(rules);
        Method parseAndBuild = builderClass.getMethod("parseAndBuild", String.class);
        t = (CollationTailoring) parseAndBuild.invoke(builder, rules);
    } catch (InvocationTargetException e) {
        throw (Exception) e.getTargetException();
    }
    t.actualLocale = null;
    adoptTailoring(t);
}
Also used : CollationTailoring(android.icu.impl.coll.CollationTailoring) SharedObject(android.icu.impl.coll.SharedObject) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

CollationTailoring (android.icu.impl.coll.CollationTailoring)2 SharedObject (android.icu.impl.coll.SharedObject)1 Output (android.icu.util.Output)1 ULocale (android.icu.util.ULocale)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1