Java Code Examples for com.ibm.icu.text.Collator#SECONDARY

The following examples show how to use com.ibm.icu.text.Collator#SECONDARY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CollationBuilder.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
private int findOrInsertNodeForRootCE(long ce, int strength) {
    assert((int)(ce >>> 56) != Collation.UNASSIGNED_IMPLICIT_BYTE);

    // Find or insert the node for each of the root CE's weights,
    // down to the requested level/strength.
    // Root CEs must have common=zero quaternary weights (for which we never insert any nodes).
    assert((ce & 0xc0) == 0);
    int index = findOrInsertNodeForPrimary(ce >>> 32);
    if(strength >= Collator.SECONDARY) {
        int lower32 = (int)ce;
        index = findOrInsertWeakNode(index, lower32 >>> 16, Collator.SECONDARY);
        if(strength >= Collator.TERTIARY) {
            index = findOrInsertWeakNode(index, lower32 & Collation.ONLY_TERTIARY_MASK,
                                        Collator.TERTIARY);
        }
    }
    return index;
}
 
Example 2
Source File: CollationBuilder.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Makes and inserts a new tailored node into the list, after the one at index.
 * Skips over nodes of weaker strength to maintain collation order
 * ("postpone insertion").
 * @return the new node's index
 */
private int insertTailoredNodeAfter(int index, int strength) {
    assert(0 <= index && index < nodes.size());
    if(strength >= Collator.SECONDARY) {
        index = findCommonNode(index, Collator.SECONDARY);
        if(strength >= Collator.TERTIARY) {
            index = findCommonNode(index, Collator.TERTIARY);
        }
    }
    // Postpone insertion:
    // Insert the new node before the next one with a strength at least as strong.
    long node = nodes.elementAti(index);
    int nextIndex;
    while((nextIndex = nextIndexFromNode(node)) != 0) {
        node = nodes.elementAti(nextIndex);
        if(strengthFromNode(node) <= strength) { break; }
        // Skip the next node which has a weaker (larger) strength than the new one.
        index = nextIndex;
    }
    node = IS_TAILORED | nodeFromStrength(strength);
    return insertNodeBetween(index, nextIndex, node);
}
 
Example 3
Source File: CollationBuilder.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the node which implies or contains a common=05 weight of the given strength
 * (secondary or tertiary), if the current node is stronger.
 * Skips weaker nodes and tailored nodes if the current node is stronger
 * and is followed by an explicit-common-weight node.
 * Always returns the input index if that node is no stronger than the given strength.
 */
private int findCommonNode(int index, int strength) {
    assert(Collator.SECONDARY <= strength && strength <= Collator.TERTIARY);
    long node = nodes.elementAti(index);
    if(strengthFromNode(node) >= strength) {
        // The current node is no stronger.
        return index;
    }
    if(strength == Collator.SECONDARY ? !nodeHasBefore2(node) : !nodeHasBefore3(node)) {
        // The current node implies the strength-common weight.
        return index;
    }
    index = nextIndexFromNode(node);
    node = nodes.elementAti(index);
    assert(!isTailoredNode(node) && strengthFromNode(node) == strength &&
            weight16FromNode(node) < Collation.COMMON_WEIGHT16);
    // Skip to the explicit common node.
    do {
        index = nextIndexFromNode(node);
        node = nodes.elementAti(index);
        assert(strengthFromNode(node) >= strength);
    } while(isTailoredNode(node) || strengthFromNode(node) > strength ||
            weight16FromNode(node) < Collation.COMMON_WEIGHT16);
    assert(weight16FromNode(node) == Collation.COMMON_WEIGHT16);
    return index;
}
 
Example 4
Source File: CollationSettings.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
public void setStrength(int value) {
    int noStrength = options & ~STRENGTH_MASK;
    switch(value) {
    case Collator.PRIMARY:
    case Collator.SECONDARY:
    case Collator.TERTIARY:
    case Collator.QUATERNARY:
    case Collator.IDENTICAL:
        options = noStrength | (value << STRENGTH_SHIFT);
        break;
    default:
        throw new IllegalArgumentException("illegal strength value " + value);
    }
}
 
Example 5
Source File: CollationBuilder.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
private static int ceStrength(long ce) {
    return
        isTempCE(ce) ? strengthFromTempCE(ce) :
        (ce & 0xff00000000000000L) != 0 ? Collator.PRIMARY :
        ((int)ce & 0xff000000) != 0 ? Collator.SECONDARY :
        ce != 0 ? Collator.TERTIARY :
        Collator.IDENTICAL;
}
 
Example 6
Source File: Sorting.java    From vespa with Apache License 2.0 5 votes vote down vote up
static private int strength2Collator(Strength strength) {
    switch (strength) {
        case PRIMARY: return Collator.PRIMARY;
        case SECONDARY: return Collator.SECONDARY;
        case TERTIARY: return Collator.TERTIARY;
        case QUATERNARY: return Collator.QUATERNARY;
        case IDENTICAL: return Collator.IDENTICAL;
        case UNDEFINED: return Collator.PRIMARY;
    }
    return Collator.PRIMARY;
}
 
Example 7
Source File: CollationRuleParser.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
private int parseRelationOperator() {
    ruleIndex = skipWhiteSpace(ruleIndex);
    if(ruleIndex >= rules.length()) { return UCOL_DEFAULT; }
    int strength;
    int i = ruleIndex;
    char c = rules.charAt(i++);
    switch(c) {
    case 0x3c:  // '<'
        if(i < rules.length() && rules.charAt(i) == 0x3c) {  // <<
            ++i;
            if(i < rules.length() && rules.charAt(i) == 0x3c) {  // <<<
                ++i;
                if(i < rules.length() && rules.charAt(i) == 0x3c) {  // <<<<
                    ++i;
                    strength = Collator.QUATERNARY;
                } else {
                    strength = Collator.TERTIARY;
                }
            } else {
                strength = Collator.SECONDARY;
            }
        } else {
            strength = Collator.PRIMARY;
        }
        if(i < rules.length() && rules.charAt(i) == 0x2a) {  // '*'
            ++i;
            strength |= STARRED_FLAG;
        }
        break;
    case 0x3b:  // ';' same as <<
        strength = Collator.SECONDARY;
        break;
    case 0x2c:  // ',' same as <<<
        strength = Collator.TERTIARY;
        break;
    case 0x3d:  // '='
        strength = Collator.IDENTICAL;
        if(i < rules.length() && rules.charAt(i) == 0x2a) {  // '*'
            ++i;
            strength |= STARRED_FLAG;
        }
        break;
    default:
        return UCOL_DEFAULT;
    }
    return ((i - ruleIndex) << OFFSET_SHIFT) | strength;
}
 
Example 8
Source File: CollationBuilder.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the secondary or tertiary weight preceding the current node's weight.
 * node=nodes[index].
 */
private int getWeight16Before(int index, long node, int level) {
    assert(strengthFromNode(node) < level || !isTailoredNode(node));
    // Collect the root CE weights if this node is for a root CE.
    // If it is not, then return the low non-primary boundary for a tailored CE.
    int t;
    if(strengthFromNode(node) == Collator.TERTIARY) {
        t = weight16FromNode(node);
    } else {
        t = Collation.COMMON_WEIGHT16;  // Stronger node with implied common weight.
    }
    while(strengthFromNode(node) > Collator.SECONDARY) {
        index = previousIndexFromNode(node);
        node = nodes.elementAti(index);
    }
    if(isTailoredNode(node)) {
        return Collation.BEFORE_WEIGHT16;
    }
    int s;
    if(strengthFromNode(node) == Collator.SECONDARY) {
        s = weight16FromNode(node);
    } else {
        s = Collation.COMMON_WEIGHT16;  // Stronger node with implied common weight.
    }
    while(strengthFromNode(node) > Collator.PRIMARY) {
        index = previousIndexFromNode(node);
        node = nodes.elementAti(index);
    }
    if(isTailoredNode(node)) {
        return Collation.BEFORE_WEIGHT16;
    }
    // [p, s, t] is a root CE. Return the preceding weight for the requested level.
    long p = weight32FromNode(node);
    int weight16;
    if(level == Collator.SECONDARY) {
        weight16 = rootElements.getSecondaryBefore(p, s);
    } else {
        weight16 = rootElements.getTertiaryBefore(p, s, t);
        assert((weight16 & ~Collation.ONLY_TERTIARY_MASK) == 0);
    }
    return weight16;
}
 
Example 9
Source File: AkCollatorICU.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean isCaseSensitive() {
    return collator.get().getStrength() > Collator.SECONDARY;
}
 
Example 10
Source File: TestICUUnicodeKeyBuilder.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Test examines the behavior when the
     * {@link SuccessorUtil#successor(String)} of an Unicode string is formed by
     * appending a <code>nul</code> character and reports an error if the
     * resulting byte[] when the key are formed compares as equal to the
     * original string from which the successor was formed.
     * <p>
     * Note: Since {@link Collator#IDENTICAL} appears to be required to
     * differentiate a trailing nul character (i.e., the successor of some
     * Unicode string), then I would strongly recommend that you form the sort
     * key first and then its successor (by appending a trailing nul).
     */
    public void test_keyBuilder_unicode_trailingNuls() {

        /*
         * Setup for US English.
         */

        final Properties properties = new Properties();
        
        properties.setProperty(Options.USER_LANGUAGE, Locale.US.getLanguage());

        properties.setProperty(Options.USER_COUNTRY, Locale.US.getCountry());
        
        final int[] strengths = new int[] { 
                Collator.PRIMARY,
                Collator.SECONDARY,
                Collator.TERTIARY,
                Collator.QUATERNARY,
                Collator.IDENTICAL,
                };
        
        int minStrength = -1;
        
        for(int i=0; i<strengths.length; i++) {
           
            final int strength = strengths[i];

            // set the strength on the collator.
            properties.setProperty(Options.STRENGTH, ""+Collator.IDENTICAL);
            
//            RuleBasedCollator collator = (RuleBasedCollator) Collator
//                    .getInstance(Locale.getDefault());
//            
//            collator.setStrength(strength);
            
            if(!doSuccessorTest( "Hello World!", properties)) {
                
                log.warn("Collator does not differentiate trailing nul characters at strength="+strength);
                
            } else {
                
                minStrength = strength;
                
            }

        }
        
        assertFalse(
                "Collator will not differentiate trailing nul characters at any strength.",
                minStrength == -1); 

        System.err
                .println("Minimum strength ("+minStrength+") to differentiate trailing nul character is: "
                        + (minStrength == Collator.PRIMARY ? "PRIMARY"
                                : (minStrength == Collator.SECONDARY ? "SECONDARY"
                                        : (minStrength == Collator.TERTIARY ? "TERTIARY"
                                                : (minStrength == Collator.QUATERNARY ? "QUARERNARY"
                                                        : (minStrength == Collator.IDENTICAL ? "IDENTICAL"
                                                                : ""
                                                                        + minStrength))))));
        
    }