Java Code Examples for java.text.RuleBasedCollator#setStrength()
The following examples show how to use
java.text.RuleBasedCollator#setStrength() .
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: 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 2
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 3
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 4
Source File: UserIdComparator.java From sakai with Educational Community License v2.0 | 5 votes |
public UserIdComparator(UserDirectoryService userDirectoryService) { this.userDirectoryService = userDirectoryService; // TODO this should be in a service and should repect the current user's locale 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("{} UserIdComparator cannot init RuleBasedCollator. Will use the default Collator instead. {}", this, e); } // This is to ignore case of the values collator.setStrength(Collator.SECONDARY); }
Example 5
Source File: AproxMergeJoin.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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 6
Source File: UserIdComparator.java From sakai with Educational Community License v2.0 | 5 votes |
public UserIdComparator(UserDirectoryService userDirectoryService) { this.userDirectoryService = userDirectoryService; // TODO this should be in a service and should repect the current user's locale 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("{} UserIdComparator cannot init RuleBasedCollator. Will use the default Collator instead. {}", this, e); } // This is to ignore case of the values collator.setStrength(Collator.SECONDARY); }
Example 7
Source File: SiteComparator.java From sakai with Educational Community License v2.0 | 4 votes |
public SiteComparator(String criterion, String asc, Locale locale) { this(criterion, asc); m_loc = locale; try { RuleBasedCollator defaultCollator = (RuleBasedCollator) Collator.getInstance(locale); String rules = defaultCollator.getRules(); localeCollator = new RuleBasedCollator(rules.replaceAll("<'\u005f'", "<' '<'\u005f'")); localeCollator.setStrength(Collator.TERTIARY); } catch (Exception e) { log.warn("SiteComparator failed to create RuleBasedCollator for locale " + locale.toString(), e); localeCollator = null; } }
Example 8
Source File: MergeJoin.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
/** * Constructs a RecordComparator based on particular metadata and settings * * @param metaData * @return * @throws ComponentNotReadyException */ private RecordOrderedKey buildRecordKey(OrderedKey joiners[], DataRecordMetadata metaData) throws ComponentNotReadyException { boolean[] ordering = new boolean[joiners.length]; Arrays.fill(ordering, ascendingInputs); String metadataLocale = metaData.getLocaleStr(); int[] fields = new int[joiners.length]; boolean[] aOrdering = new boolean[joiners.length]; for (int i = 0; i < fields.length; i++) { fields[i] = metaData.getFieldPosition(joiners[i].getKeyName()); if (joiners[i].getOrdering() == OrderEnum.ASC) { aOrdering[i] = true; } else if (joiners[i].getOrdering() == null) { boolean isAsc; if (driverKey != null && driverKey.getKeyOrderings().length > i) { // set the same ordering as the master has isAsc = driverKey.getKeyOrderings()[i]; } else { // old fashion - field name without ordering - use global setting isAsc = ascendingInputs; } joiners[i].setOrdering(isAsc ? OrderEnum.ASC : OrderEnum.DESC); aOrdering[i] = isAsc; } else if (joiners[i].getOrdering() != OrderEnum.DESC) { throw new ComponentNotReadyException("Wrong order definition in join key: " + joiners[i].getOrdering()); } if (metadataLocale == null) metadataLocale = metaData.getField(fields[i]).getLocaleStr(); } if (metadataLocale != null || locale != null) { metadataLocale = metadataLocale != null ? metadataLocale : locale; RuleBasedCollator col = (RuleBasedCollator)Collator.getInstance(MiscUtils.createLocale(metadataLocale)); col.setStrength(caseSensitive ? Collator.TERTIARY : Collator.SECONDARY); col.setDecomposition(Collator.CANONICAL_DECOMPOSITION); RecordOrderedKey recordKey = new RecordOrderedKey(fields, aOrdering, metaData); recordKey.setCollator(col); return recordKey; } else { return new RecordOrderedKey(fields, aOrdering, metaData); } }
Example 9
Source File: CollatorHelper.java From ph-commons with Apache License 2.0 | 4 votes |
public CollatorCache () { super (aLocale -> { if (aLocale == null) { LOGGER.error ("Very weird: no locale passed in. Falling back to system locale."); return Collator.getInstance (SystemHelper.getSystemLocale ()); } // Collator.getInstance is synchronized and therefore extremely slow -> // that's why we put a cache around it! final Collator aCollator = Collator.getInstance (aLocale); if (!(aCollator instanceof RuleBasedCollator)) { LOGGER.warn ("Collator.getInstance did not return a RulleBasedCollator but a " + aCollator.getClass ().getName ()); return aCollator; } try { final String sRules = ((RuleBasedCollator) aCollator).getRules (); if (!sRules.contains ("<'.'<")) { // Nothing to replace - use collator as it is LOGGER.warn ("Failed to identify the Collator rule part to be replaced. Locale used: " + aLocale); return aCollator; } final String sNewRules = StringHelper.replaceAll (sRules, "<'.'<", "<' '<'.'<"); final RuleBasedCollator aNewCollator = new RuleBasedCollator (sNewRules); aNewCollator.setStrength (Collator.TERTIARY); aNewCollator.setDecomposition (Collator.FULL_DECOMPOSITION); return aNewCollator; } catch (final ParseException ex) { throw new IllegalStateException ("Failed to parse collator rule set for locale " + aLocale, ex); } }, 500, CollatorHelper.class.getName ()); }
Example 10
Source File: SiteComparator.java From sakai with Educational Community License v2.0 | 4 votes |
public SiteComparator(String criterion, String asc, Locale locale) { this(criterion, asc); m_loc = locale; try { RuleBasedCollator defaultCollator = (RuleBasedCollator) Collator.getInstance(locale); String rules = defaultCollator.getRules(); localeCollator = new RuleBasedCollator(rules.replaceAll("<'\u005f'", "<' '<'\u005f'")); localeCollator.setStrength(Collator.TERTIARY); } catch (Exception e) { log.warn("SiteComparator failed to create RuleBasedCollator for locale " + locale.toString(), e); localeCollator = null; } }