微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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"
                                 + ",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,-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,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,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,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",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.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,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,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,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,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 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);
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。