Search in sources :

Example 1 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class TransliteratorRegistry method removeSTV.

/**
 * Remove a source-target/variant from the specDAG.
 */
private void removeSTV(String source, String target, String variant) {
    // assert(source.length() > 0);
    // assert(target.length() > 0);
    CaseInsensitiveString cisrc = new CaseInsensitiveString(source);
    CaseInsensitiveString citrg = new CaseInsensitiveString(target);
    CaseInsensitiveString civar = new CaseInsensitiveString(variant);
    Map<CaseInsensitiveString, List<CaseInsensitiveString>> targets = specDAG.get(cisrc);
    if (targets == null) {
        // should never happen for valid s-t/v
        return;
    }
    List<CaseInsensitiveString> variants = targets.get(citrg);
    if (variants == null) {
        // should never happen for valid s-t/v
        return;
    }
    variants.remove(civar);
    if (variants.size() == 0) {
        // should delete variants
        targets.remove(citrg);
        if (targets.size() == 0) {
            // should delete targets
            specDAG.remove(cisrc);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) CaseInsensitiveString(android.icu.util.CaseInsensitiveString)

Example 2 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class TransliteratorRegistry method registerSTV.

/**
 * Register a source-target/variant in the specDAG.  Variant may be
 * empty, but source and target must not be.  If variant is empty then
 * the special variant NO_VARIANT is stored in slot zero of the
 * UVector of variants.
 */
private void registerSTV(String source, String target, String variant) {
    // assert(source.length() > 0);
    // assert(target.length() > 0);
    CaseInsensitiveString cisrc = new CaseInsensitiveString(source);
    CaseInsensitiveString citrg = new CaseInsensitiveString(target);
    CaseInsensitiveString civar = new CaseInsensitiveString(variant);
    Map<CaseInsensitiveString, List<CaseInsensitiveString>> targets = specDAG.get(cisrc);
    if (targets == null) {
        targets = Collections.synchronizedMap(new HashMap<CaseInsensitiveString, List<CaseInsensitiveString>>());
        specDAG.put(cisrc, targets);
    }
    List<CaseInsensitiveString> variants = targets.get(citrg);
    if (variants == null) {
        variants = new ArrayList<CaseInsensitiveString>();
        targets.put(citrg, variants);
    }
    // string, that is, the empty string, we add it at position zero.
    if (!variants.contains(civar)) {
        if (variant.length() > 0) {
            variants.add(civar);
        } else {
            variants.add(0, civar);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) CaseInsensitiveString(android.icu.util.CaseInsensitiveString)

Example 3 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class TransliteratorRegistry method getAvailableTargets.

/**
 * Returns an enumeration over visible target names for the given
 * source.
 *
 * @return An <code>Enumeration</code> over <code>String</code> objects
 */
public Enumeration<String> getAvailableTargets(String source) {
    CaseInsensitiveString cisrc = new CaseInsensitiveString(source);
    Map<CaseInsensitiveString, List<CaseInsensitiveString>> targets = specDAG.get(cisrc);
    if (targets == null) {
        return new IDEnumeration(null);
    }
    return new IDEnumeration(Collections.enumeration(targets.keySet()));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) CaseInsensitiveString(android.icu.util.CaseInsensitiveString)

Example 4 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class TransliteratorRegistry method getAvailableVariants.

/**
 * Returns an enumeration over visible variant names for the given
 * source and target.
 *
 * @return An <code>Enumeration</code> over <code>String</code> objects
 */
public Enumeration<String> getAvailableVariants(String source, String target) {
    CaseInsensitiveString cisrc = new CaseInsensitiveString(source);
    CaseInsensitiveString citrg = new CaseInsensitiveString(target);
    Map<CaseInsensitiveString, List<CaseInsensitiveString>> targets = specDAG.get(cisrc);
    if (targets == null) {
        return new IDEnumeration(null);
    }
    List<CaseInsensitiveString> variants = targets.get(citrg);
    if (variants == null) {
        return new IDEnumeration(null);
    }
    return new IDEnumeration(Collections.enumeration(variants));
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) CaseInsensitiveString(android.icu.util.CaseInsensitiveString)

Example 5 with CaseInsensitiveString

use of android.icu.util.CaseInsensitiveString in project j2objc by google.

the class TransliteratorRegistry method remove.

/**
 * Unregister an ID.  This removes an entry from the dynamic store
 * if there is one.  The static locale resource store is
 * unaffected.
 */
public void remove(String ID) {
    String[] stv = TransliteratorIDParser.IDtoSTV(ID);
    // Only need to do this if ID.indexOf('-') < 0
    String id = TransliteratorIDParser.STVtoID(stv[0], stv[1], stv[2]);
    registry.remove(new CaseInsensitiveString(id));
    removeSTV(stv[0], stv[1], stv[2]);
    availableIDs.remove(new CaseInsensitiveString(id));
}
Also used : CaseInsensitiveString(android.icu.util.CaseInsensitiveString) CaseInsensitiveString(android.icu.util.CaseInsensitiveString)

Aggregations

CaseInsensitiveString (android.icu.util.CaseInsensitiveString)9 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ICUResourceBundle (android.icu.impl.ICUResourceBundle)1 MessageFormat (java.text.MessageFormat)1 HashMap (java.util.HashMap)1 MissingResourceException (java.util.MissingResourceException)1 Test (org.junit.Test)1