java.text.RuleBasedCollator Java Examples
The following examples show how to use
java.text.RuleBasedCollator.
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: RangeLookupTable.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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 #2
Source File: CollatorSQLLongvarchar.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
/** * 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 File: CollatorSQLVarchar.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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 #4
Source File: G7Test.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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 #5
Source File: SurrogatesTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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
Source File: RecordComparator.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
/** * * @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 #7
Source File: CollatorSQLChar.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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 #8
Source File: StringDataField.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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 #9
Source File: DataValueFactoryImpl.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
/** * 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 #10
Source File: SurrogatesTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: AlfrescoCollator.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
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 #12
Source File: CollatorSQLVarchar.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
/** * 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 #13
Source File: DataValueFactoryImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * 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 #14
Source File: DataValueFactoryImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** @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 #15
Source File: CollatorSQLClob.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
/** * 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 #16
Source File: Like.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
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 #17
Source File: SQLClob.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** @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 SQLClob CollatorSQLClob s = new CollatorSQLClob(collatorForComparison); s.copyState(this); return s; } }
Example #18
Source File: AssignmentSubmissionComparator.java From sakai with Educational Community License v2.0 | 5 votes |
public AssignmentSubmissionComparator(AssignmentService assignmentService, SiteService siteService, UserDirectoryService userDirectoryService) { this.assignmentService = assignmentService; this.siteService = siteService; this.userDirectoryService = userDirectoryService; try { collator = new RuleBasedCollator(((RuleBasedCollator) Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'")); } catch (ParseException e) { // error with init RuleBasedCollator with rules // use the default Collator collator = Collator.getInstance(); log.warn("AssignmentComparator cannot init RuleBasedCollator. Will use the default Collator instead.", e); } }
Example #19
Source File: WorkHorseForCollatorDatatypes.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
WorkHorseForCollatorDatatypes( RuleBasedCollator collatorForCharacterDatatypes, SQLChar stringData) { this.collatorForCharacterDatatypes = collatorForCharacterDatatypes; this.stringData = stringData; }
Example #20
Source File: SQLChar.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** @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 #21
Source File: BeanSortComparator.java From sakai with Educational Community License v2.0 | 5 votes |
private int subCompare(String s1, String s2) { //we do not want to use null values for sorting if(s1 == null) { s1 = ""; } if(s2 == null) { s2 = ""; } // Deal with n/a case if (s1.toLowerCase().startsWith("n/a") && !s2.toLowerCase().startsWith("n/a")) return 1; if (s2.toLowerCase().startsWith("n/a") && !s1.toLowerCase().startsWith("n/a")) return -1; String finalS1 = s1.replaceAll("<.*?>", ""); String finalS2 = s2.replaceAll("<.*?>", ""); RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance(); try { RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'")); return collator.compare(finalS1.toLowerCase(), finalS2.toLowerCase()); } catch (ParseException e) {} return Collator.getInstance().compare(finalS1.toLowerCase(), finalS2.toLowerCase()); }
Example #22
Source File: AssignmentSubmissionComparator.java From sakai with Educational Community License v2.0 | 5 votes |
public AssignmentSubmissionComparator(AssignmentService assignmentService, SiteService siteService, UserDirectoryService userDirectoryService) { this.assignmentService = assignmentService; this.siteService = siteService; this.userDirectoryService = userDirectoryService; try { collator = new RuleBasedCollator(((RuleBasedCollator) Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'")); } catch (ParseException e) { // error with init RuleBasedCollator with rules // use the default Collator collator = Collator.getInstance(); log.warn("AssignmentComparator cannot init RuleBasedCollator. Will use the default Collator instead.", e); } }
Example #23
Source File: RecordOrderedKey.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
/** * Constructor for the RecordOrderedKey object * * @param keyFieldNames names of individual fields composing the key * @param keyOrderings ordering of columns for each key (true=ascending) * @param metadata metadata describing structure of DataRecord for which the key is built * @param collator language collator */ @Deprecated public RecordOrderedKey(String keyFieldNames[], boolean keyOrderings[], DataRecordMetadata metadata, RuleBasedCollator collator) { super(keyFieldNames, metadata); this.keyOrderings = keyOrderings; // if the collator could be used if (collators != null) { collators = new RuleBasedCollator[keyOrderings.length]; Arrays.fill(collators, collator); useCollator = true; } }
Example #24
Source File: ItemAuthorBean.java From sakai with Educational Community License v2.0 | 5 votes |
public int compare(Object o1, Object o2) { SelectItem i1 = (SelectItem) o1; SelectItem i2 = (SelectItem) o2; RuleBasedCollator collator_ini = (RuleBasedCollator)Collator.getInstance(); try { RuleBasedCollator collator= new RuleBasedCollator(collator_ini.getRules().replaceAll("<'\u005f'", "<' '<'\u005f'")); return collator.compare(i1.getLabel(), i2.getLabel()); } catch (ParseException e) {} return Collator.getInstance().compare(i1.getLabel(), i2.getLabel()); }
Example #25
Source File: SQLClob.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** @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 SQLClob CollatorSQLClob s = new CollatorSQLClob(collatorForComparison); s.copyState(this); return s; } }
Example #26
Source File: StringComparable.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
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 #27
Source File: AnonymousSubmissionComparator.java From sakai with Educational Community License v2.0 | 5 votes |
public AnonymousSubmissionComparator() { try { collator = new RuleBasedCollator(((RuleBasedCollator) Collator.getInstance()).getRules().replaceAll("<'\u005f'", "<' '<'\u005f'")); } catch (ParseException e) { // error with init RuleBasedCollator with rules // use the default Collator collator = Collator.getInstance(); log.warn("{} AssignmentComparator cannot init RuleBasedCollator. Will use the default Collator instead. {}", this, e); } }
Example #28
Source File: StringComparable.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 #29
Source File: StringComparable.java From hottub with GNU General Public License v2.0 | 5 votes |
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 #30
Source File: SQLVarchar.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** @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 SQLVarchar CollatorSQLVarchar s = new CollatorSQLVarchar(collatorForComparison); s.copyState(this); return s; } }