Java Code Examples for java.text.RuleBasedCollator

The following examples show how to use java.text.RuleBasedCollator. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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;
	}
}
 
Example 2
/**
 * 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;
	}
}
 
Example 3
Source Project: TencentKona-8   Source File: SurrogatesTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example 4
Source Project: gemfirexd-oss   Source File: CollatorSQLChar.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example 5
Source Project: openjdk-jdk8u   Source File: SurrogatesTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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;
    }
}
 
Example 6
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;
}
 
Example 7
/**
 * Constructor for most general range lookup table 
 * 
 * @param id id
 * @param metadata metadata defining this lookup table
 * @param parser parser for reading defining records
 * @param collator collator for comparing string fields
 * @param startInclude indicates whether start points belong to the intervals or not
 * @param endInclude indicates whether end points belong to the intervals or not
 */
public RangeLookupTable(String id, DataRecordMetadata metadata, String[] startFields, 
		String[] endFields, Parser parser, RuleBasedCollator collator, boolean[] startInclude, boolean[] endInclude){
	super(id);
	this.metadata = metadata;
	this.startFields = startFields;
	this.endFields = endFields;
	this.dataParser = parser;
	this.collators = new RuleBasedCollator[metadata.getFields().length];
	Arrays.fill(collators, collator);
	if (startInclude.length != (metadata.getNumFields() - 1)/2) {
		throw new InvalidParameterException("startInclude parameter has wrong number " +
				"of elements: " + startInclude.length + " (should be " + 
				(metadata.getNumFields() - 1)/2 + ")");
	}
	this.startInclude = startInclude;
	if (endInclude.length != (metadata.getNumFields() - 1)/2) {
		throw new InvalidParameterException("endInclude parameter has wrong number " +
				"of elements: " + endInclude.length + " (should be " + 
				(metadata.getNumFields() - 1)/2 + ")");
	}
	this.endInclude = endInclude;
}
 
Example 8
Source Project: gemfirexd-oss   Source File: DataValueFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
/** @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;    	
 }
 
Example 9
Source Project: gemfirexd-oss   Source File: DataValueFactoryImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
   * 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;
  }
 
Example 10
/**
 * 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;
	}
}
 
Example 11
/**
   * 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;
  }
 
Example 12
/**
 * Compares this object with the specified object for order -
 * respecting i18n particularities - e.g. "e" versus "??".<br>
 * Using this method requires lots of resources and is therefore
 * much slower than simple compareTo(Object obj) method.
 *
 * @param  obj  Any object implementing CharSequence interface
 * @param collator Collator which should be used to compare
 * string representations respecting i18n particularities
 * @return      -1;0;1 based on comparison result
 */
public int compareTo(Object obj,RuleBasedCollator collator) {
    CharSequence strObj;
    
    if (isNull) return -1;
    if (obj == null) return 1;
    
    if (obj instanceof StringDataField) {
        if (((StringDataField) obj).isNull())
            return 1;
        strObj=((StringDataField) obj).value;
    }else if (obj instanceof CharSequence) {
        strObj = (CharSequence) obj;
    }else {
        throw new ClassCastException("Can't compare StringDataField to "
                + obj.getClass().getName());
    }

    return Compare.compare(value, strObj, collator);
}
 
Example 13
/**
   * 
   * @param metadata
   */
  public void updateCollators(DataRecordMetadata metadata) {
Locale[] metadataLocale = getLocaleFromMetadata(metadata, keyFields);
if (metadataLocale == null) return;
Integer[] iSensitivity = getSensitivityFromMetadata(metadata, keyFields);

if (collators == null) collators = new RuleBasedCollator[keyFields.length];
for (int i=0; i<keyFields.length; i++) {
	//collator was prepared from outside the comparator and this collator has higher priority
	if (collators[i] != null || metadataLocale[i] == null) continue;
	collators[i] = (RuleBasedCollator)Collator.getInstance(metadataLocale[i]);
	
	if (iSensitivity != null && iSensitivity[i] != null) collators[i].setStrength(iSensitivity[i].intValue());
	collators[i].setDecomposition(Collator.CANONICAL_DECOMPOSITION);
	useCollator = true;
}
  }
 
Example 14
Source Project: gemfirexd-oss   Source File: CollatorSQLVarchar.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example 15
Source Project: jdk8u_jdk   Source File: G7Test.java    License: GNU General Public License v2.0 6 votes vote down vote up
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");
    }
}
 
Example 16
Source Project: jdk1.8-source-analysis   Source File: StringComparable.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 17
Source Project: spliceengine   Source File: SQLChar.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/** @see StringDataValue#getValue(RuleBasedCollator) */
public StringDataValue getValue(RuleBasedCollator collatorForComparison)
{
    if (collatorForComparison == null)
    {//null collatorForComparison means use UCS_BASIC for collation
        return this;
    } else {
        //non-null collatorForComparison means use collator sensitive
        //implementation of SQLChar
         CollatorSQLChar s = new CollatorSQLChar(collatorForComparison);
         s.copyState(this);
         return s;
    }
}
 
Example 18
/**
 * Constructs a RecordComparator based on particular metadata and settings
 * 
 * @param metaData
 * @return
 */
private RecordOrderedKey buildRecordOrderedKey(String joiners[], DataRecordMetadata metaData) {
	boolean[] ordering = new boolean[joiners.length]; 
	Arrays.fill(ordering, true);//TODO change the key dialog

	if (locale != null) {
		RuleBasedCollator col = (RuleBasedCollator)Collator.getInstance(MiscUtils.createLocale(locale));
		col.setStrength(caseSensitive ? Collator.TERTIARY : Collator.SECONDARY);
		col.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
		return new RecordOrderedKey(joiners, ordering, metaData, col);
	} else {
		return new RecordOrderedKey(joiners, ordering, metaData);
	}
}
 
Example 19
/**
 * RESOLVE - unfinished LIKE test with dataset of all unicode characters
 **/
private static final void printRuleBasedCollator()
{
    // get en_US Collator rules
    RuleBasedCollator en_USCollator = 
        (RuleBasedCollator)Collator.getInstance(Locale.US);
    String en_rules = en_USCollator.getRules();

    System.out.println("ENGLISH RULES: " + en_rules);
    System.out.println("ENGLISH RULES: " + formatString(en_rules, true));
    System.out.println("ENGLISH RULES: " + formatString(en_rules, false));
}
 
Example 20
Source Project: jdk8u60   Source File: StringComparable.java    License: GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example 21
Source Project: jdk8u60   Source File: StringComparable.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 22
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());
}
 
Example 23
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);
    }
}
 
Example 24
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());
}
 
Example 25
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);
    }
}
 
Example 26
Source Project: spliceengine   Source File: Like.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static Boolean like(char[] value, int valueLength, char[] pattern, 
		int patternLength, RuleBasedCollator collator) 
throws StandardException { 
	if (value == null || pattern == null) return null;
	return like(value, valueLength, pattern, patternLength, null, 0, 
			collator);
}
 
Example 27
Source Project: sakai   Source File: SectionBean.java    License: Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
 SelectItem i1 = (SelectItem)o1;
 SelectItem i2 = (SelectItem)o2;
try{
	RuleBasedCollator r_collator= new RuleBasedCollator(((RuleBasedCollator)Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
	return r_collator.compare(i1.getLabel(), i2.getLabel());
}catch(ParseException e){
	  return Collator.getInstance().compare(i1.getLabel(),i2.getLabel());
}
}
 
Example 28
Source Project: sakai   Source File: FacadeUtils.java    License: Educational Community License v2.0 5 votes vote down vote up
public int compare(Object o1, Object o2) {
	try{
		RuleBasedCollator r_collator= new RuleBasedCollator(((RuleBasedCollator)Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'"));
		return r_collator.compare(((EnrollmentRecord)o1).getUser().getSortName(),((EnrollmentRecord)o2).getUser().getSortName());
	}catch(ParseException e){
		  return Collator.getInstance().compare(((EnrollmentRecord)o1).getUser().getSortName(),((EnrollmentRecord)o2).getUser().getSortName());
	}
}
 
Example 29
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());
}
 
Example 30
Source Project: hottub   Source File: StringComparable.java    License: GNU General Public License v2.0 5 votes vote down vote up
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());
}