Java 类java.text.RuleBasedCollator 实例源码

项目:alfresco-repository    文件:AlfrescoCollator.java   
private static synchronized Collator updateCollatorRules(Collator collator)
{
    if (collator instanceof RuleBasedCollator)
    {
        try
        {
            // get current collator rules
            String collatorRules = ((RuleBasedCollator)collator).getRules();
            // we shoudn't ignore space character in character comparison - put it before u0021 character
            String newCollatorRules = collatorRules.replaceAll("<'\u0021'", "<'\u0020'<'\u0021'");
            // create new collator with overridden rules
            return new RuleBasedCollator(newCollatorRules);
        }
        catch(ParseException e)
        {
            return collator;
        }
    }
    return collator;
}
项目:openjdk-jdk10    文件:SurrogatesTest.java   
private Collator getCollator() {
    RuleBasedCollator base = (RuleBasedCollator)Collator.getInstance();
    String rule = base.getRules();
    try {
        return new RuleBasedCollator(rule
                                 + "&B < \ud800\udc01 < \ud800\udc00"
                                 + ", \ud800\udc02, \ud800\udc03"
                                 + "; \ud800\udc04, \ud800\udc05"
                                 + "< \ud800\udc06 < \ud800\udc07"
                                 + "&FE < \ud800\udc08"
                                 + "&PE, \ud800\udc09"
                                 + "&Z < \ud800\udc0a < \ud800\udc0b < \ud800\udc0c"
                                 + "&\ud800\udc0a < x, X"
                                 + "&A < \ud800\udc04\ud800\udc05");
    } catch (Exception e) {
        errln("Failed to create new RulebasedCollator object");
        return null;
    }
}
项目:openjdk-jdk10    文件:G7Test.java   
public void TestDemoTest2() {
    final Collator myCollation = Collator.getInstance(Locale.US);
    final String defRules = ((RuleBasedCollator)myCollation).getRules();
    String newRules = defRules + "& C < ch , cH, Ch, CH";

    try {
        RuleBasedCollator tblColl = new RuleBasedCollator(newRules);
        for (int j = 0; j < TOTALTESTSET; j++) {
            for (int n = j+1; n < TOTALTESTSET; n++) {
                doTest(tblColl, testCases[Test2Results[j]],
                       testCases[Test2Results[n]], -1);
            }
        }
    } catch (Exception foo) {
        errln("Exception: " + foo.getMessage() +
              "\nDemo Test 2 Table Collation object creation failed.\n");
    }
}
项目:openjdk9    文件:SurrogatesTest.java   
private Collator getCollator() {
    RuleBasedCollator base = (RuleBasedCollator)Collator.getInstance();
    String rule = base.getRules();
    try {
        return new RuleBasedCollator(rule
                                 + "&B < \ud800\udc01 < \ud800\udc00"
                                 + ", \ud800\udc02, \ud800\udc03"
                                 + "; \ud800\udc04, \ud800\udc05"
                                 + "< \ud800\udc06 < \ud800\udc07"
                                 + "&FE < \ud800\udc08"
                                 + "&PE, \ud800\udc09"
                                 + "&Z < \ud800\udc0a < \ud800\udc0b < \ud800\udc0c"
                                 + "&\ud800\udc0a < x, X"
                                 + "&A < \ud800\udc04\ud800\udc05");
    } catch (Exception e) {
        errln("Failed to create new RulebasedCollator object");
        return null;
    }
}
项目:openjdk9    文件:G7Test.java   
public void TestDemoTest2() {
    final Collator myCollation = Collator.getInstance(Locale.US);
    final String defRules = ((RuleBasedCollator)myCollation).getRules();
    String newRules = defRules + "& C < ch , cH, Ch, CH";

    try {
        RuleBasedCollator tblColl = new RuleBasedCollator(newRules);
        for (int j = 0; j < TOTALTESTSET; j++) {
            for (int n = j+1; n < TOTALTESTSET; n++) {
                doTest(tblColl, testCases[Test2Results[j]],
                       testCases[Test2Results[n]], -1);
            }
        }
    } catch (Exception foo) {
        errln("Exception: " + foo.getMessage() +
              "\nDemo Test 2 Table Collation object creation failed.\n");
    }
}
项目:gemfirexd-oss    文件:DataValueFactoryImpl.java   
/** @see DataValueFactory#getCharacterCollator(int) */
 public RuleBasedCollator getCharacterCollator(int collationType) 
 throws StandardException {
    if (collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC)
        return (RuleBasedCollator)null;
    else if (collatorForCharacterTypes == null) {
        //This is the first access to Collator because otherwise
        //it will not be null. Verify that JVM has support for
        //the Collator for the database locale.
//  Calculate the collator strength. COLLATION_TYPE_TERRITORY_BASED use strength -1, i e unspecified.
int strength = collationType - StringDataValue.COLLATION_TYPE_TERRITORY_BASED_PRIMARY;
        collatorForCharacterTypes = verifyCollatorSupport(strength);
        return collatorForCharacterTypes;                   
    } else
        return collatorForCharacterTypes;       
 }
项目:gemfirexd-oss    文件:DataValueFactoryImpl.java   
/**
   * Verify that JVM has support for the Collator for the datbase's locale.
   *
* @param strength Collator strength or -1 for locale default.
   * @return Collator for database's locale
   * @throws StandardException if JVM does not have support for Collator
   */
  private RuleBasedCollator verifyCollatorSupport(int strength)
  throws StandardException {
    Locale[] availLocales =  Collator.getAvailableLocales();
    //Verify that Collator can be instantiated for the given locale.
    boolean localeFound = false;
    for (int i=0; i<availLocales.length;i++)
    {
        if (availLocales[i].equals(databaseLocale)) {
            localeFound = true;
            break;
        }
    }
    if (!localeFound)
    throw StandardException.newException(
            SQLState.COLLATOR_NOT_FOUND_FOR_LOCALE, 
            (databaseLocale != null ? databaseLocale.toString() : "null"));

    RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(databaseLocale);

if (strength != -1)
    collator.setStrength(strength);

return collator;
  }
项目:gemfirexd-oss    文件:CollatorSQLChar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLChar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLChar
        SQLChar s = new SQLChar();
        s.copyState(this);
        return s;
    }
}
项目:gemfirexd-oss    文件:CollatorSQLVarchar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLVarchar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLVarchar
        SQLVarchar s = new SQLVarchar();
        s.copyState(this);
        return s;
    }
}
项目:gemfirexd-oss    文件:CollatorSQLClob.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLClob
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLClob
        SQLClob s = new SQLClob();
        s.copyState(this);
        return s;
    }
}
项目:gemfirexd-oss    文件:CollatorSQLLongvarchar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLLongvarchar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLLongvarchar
        SQLLongvarchar s = new SQLLongvarchar();
        s.copyState(this);
        return s;
    }
}
项目:gemfirexd-oss    文件:DataTypeDescriptor.java   
/**
    Get a Null for this type.
*/
public DataValueDescriptor getNull() throws StandardException {
    DataValueDescriptor returnDVD = typeId.getNull();
    //If we are dealing with default collation, then we have got the
    //right DVD already. Just return it.
    if (typeDescriptor.getCollationType() == StringDataValue.COLLATION_TYPE_UCS_BASIC
        || returnDVD instanceof JSON) {
        return returnDVD;           
    }
    //If we are dealing with territory based collation and returnDVD is 
    //of type StringDataValue, then we need to return a StringDataValue   
    //with territory based collation.
    if (returnDVD instanceof StringDataValue) {
        try {
            RuleBasedCollator rbs = ConnectionUtil.getCurrentLCC().getDataValueFactory().
            getCharacterCollator(typeDescriptor.getCollationType());
            return ((StringDataValue)returnDVD).getValue(rbs);
        }
        catch( java.sql.SQLException sqle)
        {
            throw StandardException.plainWrapException( sqle);
        }
    }
    else
        return returnDVD;           
}
项目:gemfirexd-oss    文件:DataValueFactoryImpl.java   
/** @see DataValueFactory#getCharacterCollator(int) */
 public RuleBasedCollator getCharacterCollator(int collationType) 
 throws StandardException {
    if (collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC)
        return (RuleBasedCollator)null;
    else if (collatorForCharacterTypes == null) {
        //This is the first access to Collator because otherwise
        //it will not be null. Verify that JVM has support for
        //the Collator for the database locale.
//  Calculate the collator strength. COLLATION_TYPE_TERRITORY_BASED use strength -1, i e unspecified.
int strength = collationType - StringDataValue.COLLATION_TYPE_TERRITORY_BASED_PRIMARY;
        collatorForCharacterTypes = verifyCollatorSupport(strength);
        return collatorForCharacterTypes;                   
    } else
        return collatorForCharacterTypes;       
 }
项目:gemfirexd-oss    文件:DataValueFactoryImpl.java   
/**
   * Verify that JVM has support for the Collator for the datbase's locale.
   *
* @param strength Collator strength or -1 for locale default.
   * @return Collator for database's locale
   * @throws StandardException if JVM does not have support for Collator
   */
  private RuleBasedCollator verifyCollatorSupport(int strength)
  throws StandardException {
    Locale[] availLocales =  Collator.getAvailableLocales();
    //Verify that Collator can be instantiated for the given locale.
    boolean localeFound = false;
    for (int i=0; i<availLocales.length;i++)
    {
        if (availLocales[i].equals(databaseLocale)) {
            localeFound = true;
            break;
        }
    }
    if (!localeFound)
    throw StandardException.newException(
            SQLState.COLLATOR_NOT_FOUND_FOR_LOCALE, 
            (databaseLocale != null ? databaseLocale.toString() : "null"));

    RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(databaseLocale);

if (strength != -1)
    collator.setStrength(strength);

return collator;
  }
项目:gemfirexd-oss    文件:CollatorSQLChar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLChar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLChar
        SQLChar s = new SQLChar();
        s.copyState(this);
        return s;
    }
}
项目:gemfirexd-oss    文件:CollatorSQLVarchar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLVarchar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLVarchar
        SQLVarchar s = new SQLVarchar();
        s.copyState(this);
        return s;
    }
}
项目:gemfirexd-oss    文件:CollatorSQLClob.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLClob
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLClob
        SQLClob s = new SQLClob();
        s.copyState(this);
        return s;
    }
}
项目:gemfirexd-oss    文件:CollatorSQLLongvarchar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLLongvarchar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLLongvarchar
        SQLLongvarchar s = new SQLLongvarchar();
        s.copyState(this);
        return s;
    }
}
项目:gemfirexd-oss    文件:DataTypeDescriptor.java   
/**
    Get a Null for this type.
*/
public DataValueDescriptor getNull() throws StandardException {
    DataValueDescriptor returnDVD = typeId.getNull();
    //If we are dealing with default collation, then we have got the
    //right DVD already. Just return it.
    if (typeDescriptor.getCollationType() == StringDataValue.COLLATION_TYPE_UCS_BASIC
        || returnDVD instanceof JSON) {
        return returnDVD;           
    }
    //If we are dealing with territory based collation and returnDVD is 
    //of type StringDataValue, then we need to return a StringDataValue   
    //with territory based collation.
    if (returnDVD instanceof StringDataValue) {
        try {
            RuleBasedCollator rbs = ConnectionUtil.getCurrentLCC().getDataValueFactory().
            getCharacterCollator(typeDescriptor.getCollationType());
            return ((StringDataValue)returnDVD).getValue(rbs);
        }
        catch( java.sql.SQLException sqle)
        {
            throw StandardException.plainWrapException( sqle);
        }
    }
    else
        return returnDVD;           
}
项目:In-the-Box-Fork    文件:OldCollationElementIteratorTest.java   
public void testPrevious() {
    RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US);
    String text = "abc";
    CollationElementIterator iterator = coll
            .getCollationElementIterator(text);
    int[] orders = new int[text.length()];
    int order = iterator.next();
    int i = 0;
    while (order != CollationElementIterator.NULLORDER) {
        orders[i++] = order;
        order = iterator.next();
    }

    int offset = iterator.getOffset();
    assertEquals(text.length(), offset);
    order = iterator.previous();

    while (order != CollationElementIterator.NULLORDER) {
        assertEquals(orders[--i], order);
        order = iterator.previous();
    }

    assertEquals(0, iterator.getOffset());
}
项目:In-the-Box-Fork    文件:CollatorTest.java   
public void testEqualsObject() throws ParseException {
    String rule = "< a < b < c < d < e";
    RuleBasedCollator coll = new RuleBasedCollator(rule);

    assertEquals(Collator.TERTIARY, coll.getStrength());
    // This is a harmony test, but it assumes that RuleBasedCollators default to
    // NO_DECOMPOSITION, which isn't true on Android.
    // assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
    RuleBasedCollator other = new RuleBasedCollator(rule);
    assertTrue(coll.equals(other));

    coll.setStrength(Collator.PRIMARY);
    assertFalse(coll.equals(other));

    coll.setStrength(Collator.TERTIARY);
    coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    other.setDecomposition(Collator.NO_DECOMPOSITION); // See comment above.
    assertFalse(coll.equals(other));
}
项目:community-edition-old    文件:AlfrescoCollator.java   
private static synchronized Collator updateCollatorRules(Collator collator)
{
    if (collator instanceof RuleBasedCollator)
    {
        try
        {
            // get current collator rules
            String collatorRules = ((RuleBasedCollator)collator).getRules();
            // we shoudn't ignore space character in character comparison - put it before u0021 character
            String newCollatorRules = collatorRules.replaceAll("<'\u0021'", "<'\u0020'<'\u0021'");
            // create new collator with overridden rules
            return new RuleBasedCollator(newCollatorRules);
        }
        catch(ParseException e)
        {
            return collator;
        }
    }
    return collator;
}
项目:cn1    文件:CollationElementIteratorTest.java   
public void testTertiaryOrder() {
    RuleBasedCollator rbColl = (RuleBasedCollator) Collator
            .getInstance(new Locale("fr", "FR"));
    String text = "abAB";
    CollationElementIterator iterator = rbColl
            .getCollationElementIterator(text);
    int order = iterator.next();
    int tOrder1 = CollationElementIterator.tertiaryOrder(order);
    order = iterator.next();
    int tOrder2 = CollationElementIterator.tertiaryOrder(order);
    assertEquals(tOrder1, tOrder2);

    order = iterator.next();
    tOrder1 = CollationElementIterator.tertiaryOrder(order);
    order = iterator.next();
    tOrder2 = CollationElementIterator.tertiaryOrder(order);
    assertEquals(tOrder1, tOrder2);
}
项目:cn1    文件:RuleBasedCollatorTest.java   
public void testEqualsObject() throws ParseException {
    String rule = "< a < b < c < d < e";
    RuleBasedCollator coll = new RuleBasedCollator(rule);

    assertEquals(Collator.TERTIARY, coll.getStrength());
    assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
    RuleBasedCollator other = new RuleBasedCollator(rule);
    assertTrue(coll.equals(other));

    coll.setStrength(Collator.PRIMARY);
    assertFalse(coll.equals(other));

    coll.setStrength(Collator.TERTIARY);
    coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    assertFalse(coll.equals(other));
}
项目:freeVM    文件:CollationElementIteratorTest.java   
public void testTertiaryOrder() {
    RuleBasedCollator rbColl = (RuleBasedCollator) Collator
            .getInstance(new Locale("fr", "FR"));
    String text = "abAB";
    CollationElementIterator iterator = rbColl
            .getCollationElementIterator(text);
    int order = iterator.next();
    int tOrder1 = CollationElementIterator.tertiaryOrder(order);
    order = iterator.next();
    int tOrder2 = CollationElementIterator.tertiaryOrder(order);
    assertEquals(tOrder1, tOrder2);

    order = iterator.next();
    tOrder1 = CollationElementIterator.tertiaryOrder(order);
    order = iterator.next();
    tOrder2 = CollationElementIterator.tertiaryOrder(order);
    assertEquals(tOrder1, tOrder2);
}
项目:freeVM    文件:RuleBasedCollatorTest.java   
public void testEqualsObject() throws ParseException {
    String rule = "< a < b < c < d < e";
    RuleBasedCollator coll = new RuleBasedCollator(rule);

    assertEquals(Collator.TERTIARY, coll.getStrength());
    assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
    RuleBasedCollator other = new RuleBasedCollator(rule);
    assertTrue(coll.equals(other));

    coll.setStrength(Collator.PRIMARY);
    assertFalse(coll.equals(other));

    coll.setStrength(Collator.TERTIARY);
    coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    assertFalse(coll.equals(other));
}
项目:freeVM    文件:CollationElementIteratorTest.java   
public void testTertiaryOrder() {
    RuleBasedCollator rbColl = (RuleBasedCollator) Collator
            .getInstance(new Locale("fr", "FR"));
    String text = "abAB";
    CollationElementIterator iterator = rbColl
            .getCollationElementIterator(text);
    int order = iterator.next();
    int tOrder1 = CollationElementIterator.tertiaryOrder(order);
    order = iterator.next();
    int tOrder2 = CollationElementIterator.tertiaryOrder(order);
    assertEquals(tOrder1, tOrder2);

    order = iterator.next();
    tOrder1 = CollationElementIterator.tertiaryOrder(order);
    order = iterator.next();
    tOrder2 = CollationElementIterator.tertiaryOrder(order);
    assertEquals(tOrder1, tOrder2);
}
项目:freeVM    文件:RuleBasedCollatorTest.java   
public void testEqualsObject() throws ParseException {
    String rule = "< a < b < c < d < e";
    RuleBasedCollator coll = new RuleBasedCollator(rule);

    assertEquals(Collator.TERTIARY, coll.getStrength());
    assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
    RuleBasedCollator other = new RuleBasedCollator(rule);
    assertTrue(coll.equals(other));

    coll.setStrength(Collator.PRIMARY);
    assertFalse(coll.equals(other));

    coll.setStrength(Collator.TERTIARY);
    coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    assertFalse(coll.equals(other));
}
项目:spliceengine    文件:DataValueFactoryImpl.java   
/** @see DataValueFactory#getCharacterCollator(int) */
 public RuleBasedCollator getCharacterCollator(int collationType) 
 throws StandardException {
    if (collationType == StringDataValue.COLLATION_TYPE_UCS_BASIC)
        return (RuleBasedCollator)null;
    else if (collatorForCharacterTypes == null) {
        //This is the first access to Collator because otherwise
        //it will not be null. Verify that JVM has support for
        //the Collator for the database locale.
//  Calculate the collator strength. COLLATION_TYPE_TERRITORY_BASED use strength -1, i e unspecified.
int strength = collationType - StringDataValue.COLLATION_TYPE_TERRITORY_BASED_PRIMARY;
        collatorForCharacterTypes = verifyCollatorSupport(strength);
        return collatorForCharacterTypes;                   
    } else
        return collatorForCharacterTypes;       
 }
项目:spliceengine    文件:DataValueFactoryImpl.java   
/**
   * Verify that JVM has support for the Collator for the datbase's locale.
   *
* @param strength Collator strength or -1 for locale default.
   * @return Collator for database's locale
   * @throws StandardException if JVM does not have support for Collator
   */
  private RuleBasedCollator verifyCollatorSupport(int strength)
  throws StandardException {
    Locale[] availLocales =  Collator.getAvailableLocales();
    //Verify that Collator can be instantiated for the given locale.
    boolean localeFound = false;
      for (Locale availLocale : availLocales) {
          if (availLocale.equals(databaseLocale)) {
              localeFound = true;
              break;
          }
      }
    if (!localeFound)
    throw StandardException.newException(
            SQLState.COLLATOR_NOT_FOUND_FOR_LOCALE, 
            databaseLocale.toString());

    RuleBasedCollator collator = (RuleBasedCollator)Collator.getInstance(databaseLocale);

if (strength != -1)
    collator.setStrength(strength);

return collator;
  }
项目:spliceengine    文件:CollatorSQLChar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLChar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLChar
        SQLChar s = new SQLChar();
        s.copyState(this);
        return s;
    }
}
项目:spliceengine    文件:CollatorSQLVarchar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLVarchar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLVarchar
        SQLVarchar s = new SQLVarchar();
        s.copyState(this);
        return s;
    }
}
项目:spliceengine    文件:CollatorSQLClob.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLClob
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLClob
        SQLClob s = new SQLClob();
        s.copyState(this);
        return s;
    }
}
项目:spliceengine    文件:CollatorSQLLongvarchar.java   
/**
 * We do not anticipate this method on collation sensitive DVD to be
 * ever called in Derby 10.3 In future, when Derby will start supporting
 * SQL standard COLLATE clause, this method might get called on the
 * collation sensitive DVDs.
 *  
 * @see StringDataValue#getValue(RuleBasedCollator) 
 */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison != null)
    {
        //non-null collatorForComparison means use this collator sensitive
        //implementation of SQLLongvarchar
        setCollator(collatorForComparison);
        return this;            
    } else {
        //null collatorForComparison means use UCS_BASIC for collation.
        //For that, we need to use the base class SQLLongvarchar
        SQLLongvarchar s = new SQLLongvarchar();
        s.copyState(this);
        return s;
    }
}
项目:bananapeel    文件:Collators.java   
public static Collator rfc1459()
{
    try
    {
        RuleBasedCollator collator = new RuleBasedCollator(RFC1459_RULES);
        collator.setStrength(Collator.SECONDARY);
        return collator;
    }
    catch(ParseException e)
    {
        throw new RuntimeException(e);
    }
}
项目:bananapeel    文件:Collators.java   
public static Collator ascii()
{
    try
    {
        RuleBasedCollator collator = new RuleBasedCollator(ASCII_RULES);
        collator.setStrength(Collator.SECONDARY);
        return collator;
    }
    catch(ParseException e)
    {
        throw new RuntimeException(e);
    }
}
项目:lams    文件:CollationKeyFilterFactory.java   
private Collator createFromRules(String fileName, ResourceLoader loader) throws IOException {
  InputStream input = null;
  try {
   input = loader.openResource(fileName);
   String rules = toUTF8String(input);
   return new RuleBasedCollator(rules);
  } catch (ParseException e) {
    // invalid rules
    throw new IOException("ParseException thrown while parsing rules", e);
  } finally {
    IOUtils.closeWhileHandlingException(input);
  }
}
项目:ramus    文件:RowFactory.java   
public static void sortByTitle(final Stream[] streams) {
    Arrays.sort(streams, new Comparator<Object>() {

        private final RuleBasedCollator collator = RowNameComparator
                .getRowSorter();

        public int compare(final Object arg0, final Object arg1) {
            final Stream a = (Stream) arg0;
            final Stream b = (Stream) arg1;
            return collator.compare(a.getName(), b.getName());
        }

    });
}
项目:OpenJSharp    文件:StringComparable.java   
public StringComparable(final String text, final Locale locale, final Collator collator, final String caseOrder){
     m_text =  text;
     m_locale = locale;
     m_collator = (RuleBasedCollator)collator;
     m_caseOrder = caseOrder;
     m_mask = getMask(m_collator.getStrength());
}
项目:OpenJSharp    文件:StringComparable.java   
public final static Comparable getComparator( final String text, final Locale locale, final Collator collator, final String caseOrder){
    if((caseOrder == null) ||(caseOrder.length() == 0)){// no case-order specified
         return  ((RuleBasedCollator)collator).getCollationKey(text);
    }else{
         return new StringComparable(text, locale, collator, caseOrder);
    }
}