List of usage examples for java.text Collator getInstance
public static Collator getInstance(Locale desiredLocale)
From source file:fr.gouv.culture.thesaurus.util.template.ThesaurusSorter.java
/** * Tri les chanes rgionalises par langue, puis par libell. * /*from w ww . ja v a2 s .co m*/ * @param strings * Chanes rgionalises trier (ou <code>null</code>) * @param prioritizedLanguages * Langues prioritaires (la valeur <code>null</code> reprsente * la langue neutre) * @return Chanes rgionalises tries, ou <code>null</code> si les chanes * en entres sont <code>null</code> */ public Collection<LocalizedString> sortStrings(final Collection<LocalizedString> strings, final String[] prioritizedLanguages) { Collection<LocalizedString> sortedStrings; if (strings == null) { sortedStrings = null; } else { final List<SortItemWrapper<LocalizedString>> wrappers = new ArrayList<SortItemWrapper<LocalizedString>>( strings.size()); final Iterator<LocalizedString> iterator = strings.iterator(); for (int wrapperId = 0; iterator.hasNext(); wrapperId++) { final LocalizedString localizedString = iterator.next(); final String language = localizedString.getLanguage(); final Collator collator = language == null ? null : Collator.getInstance(getLocale(language)); wrappers.add(wrapperId, new SortItemWrapper<LocalizedString>(localizedString, localizedString, collator, prioritizedLanguages)); } Collections.sort(wrappers); sortedStrings = new ArrayList<LocalizedString>(wrappers.size()); for (final SortItemWrapper<LocalizedString> wrapper : wrappers) { sortedStrings.add(wrapper.getData()); } } return sortedStrings; }
From source file:org.nuclos.common2.LangUtils.java
/** * @return the default <code>Collator</code> for this platform, that is the default <code>Collator</code> * for the default <code>Locale</code>. For international applications, this is the collation of choice. * Note that this is locale dependent./*from w w w . j a v a 2s. c o m*/ */ public static Collator getDefaultCollator() { if (collator == null) { collator = Collator.getInstance(SpringLocaleDelegate.getInstance().getLocale()); collator.setStrength(Collator.SECONDARY);// a == A, a < } return collator; }
From source file:net.gcompris.GComprisActivity.java
public int localeCompare(String a, String b, String locale) { String[] parts = locale.split("[\\._]"); Locale l;//from w ww.j a v a2 s. co m if (parts.length == 1) l = new Locale(parts[0]); else if (parts.length == 2) l = new Locale(parts[0], parts[1]); else l = Locale.getDefault(); Collator collator = Collator.getInstance(l); // Note: This works only if the device supports the // passed locale. If it does not or if an invalid locale string has been // passed, the collator seems to sort according to Locale.getDefault() return collator.compare(a, b); }
From source file:org.apache.nifi.audit.UserGroupAuditor.java
/** * Extracts the values for the configured properties from the specified user group. *//*from w ww .j a v a 2s .c o m*/ private Map<String, String> extractConfiguredPropertyValues(Group group, UserGroupDTO userGroupDTO) { Map<String, String> values = new HashMap<>(); if (userGroupDTO.getIdentity() != null) { values.put(NAME, group.getName()); } if (userGroupDTO.getUsers() != null) { // get each of the auto terminated relationship names final List<String> currentUsers = new ArrayList<>(group.getUsers()); // sort them and include in the configuration Collections.sort(currentUsers, Collator.getInstance(Locale.US)); values.put(USERS, StringUtils.join(currentUsers, ", ")); } return values; }
From source file:org.nuclos.common2.LangUtils.java
/** * @return the default <code>Collator</code> for <code>Locale.GERMANY</code>. * This "modern" collation is compatible with DIN 5007 (which is very similar to the collation proposed by the "Duden"). * This can be used wherever <code>String</code>s must be sorted according to German rules. * For name directories (eg. address books or phonebooks), the traditional german collation can be used as an alternative. * @see #getTraditionalGermanCollator()// www . j a v a2s .c o m */ public static Collator getModernGermanCollator() { return Collator.getInstance(Locale.GERMANY); }
From source file:org.olat.modules.fo.ForumController.java
/** * @param forum//from w ww . j a v a2s .c o m * @param focallback * @param ureq * @param wControl */ ForumController(final Forum forum, final ForumCallback focallback, final UserRequest ureq, final WindowControl wControl) { super(ureq, wControl); this.forum = forum; this.focallback = focallback; addLoggingResourceable(LoggingResourceable.wrap(forum)); forumOres = OresHelper.createOLATResourceableInstance(Forum.class, forum.getKey()); f = Formatter.getInstance(ureq.getLocale()); fm = ForumManager.getInstance(); msgs = fm.getMessagesByForum(forum); collator = Collator.getInstance(ureq.getLocale()); collator.setStrength(Collator.PRIMARY); forumPanel = new Panel("forumPanel"); forumPanel.addListener(this); // create page vcListTitles = createVelocityContainer("list_titles"); msgCreateButton = LinkFactory.createButtonSmall("msg.create", vcListTitles, this); archiveForumButton = LinkFactory.createButtonSmall("archive.forum", vcListTitles, this); filterForUserButton = LinkFactory.createButtonSmall("filter", vcListTitles, this); if (!this.isGuestOnly(ureq)) { final SearchServiceUIFactory searchServiceUIFactory = (SearchServiceUIFactory) CoreSpringFactory .getBean(SearchServiceUIFactory.class); searchController = searchServiceUIFactory.createInputController(ureq, wControl, DisplayOption.STANDARD, null); listenTo(searchController); vcListTitles.put("search_input", searchController.getInitialComponent()); } // a list of titles of all messages in all threads vcListTitles.contextPut("security", focallback); // --- subscription --- subsContext = focallback.getSubscriptionContext(); // if sc is null, then no subscription is desired if (subsContext != null) { // FIXME fj: implement subscription callback for group forums final String businessPath = wControl.getBusinessControl().getAsString(); final String data = String.valueOf(forum.getKey()); final PublisherData pdata = new PublisherData(OresHelper.calculateTypeName(Forum.class), data, businessPath); csc = new ContextualSubscriptionController(ureq, getWindowControl(), subsContext, pdata); listenTo(csc); vcListTitles.put("subscription", csc.getInitialComponent()); } final TableGuiConfiguration tableConfig = new TableGuiConfiguration(); tableConfig.setCustomCssClass("o_forum"); tableConfig.setSelectedRowUnselectable(true); tableConfig.setDownloadOffered(false); tableConfig.setTableEmptyMessage(translate("forum.emtpy")); allThreadTableCtr = new TableController(tableConfig, ureq, getWindowControl(), getTranslator()); listenTo(allThreadTableCtr); allThreadTableCtr.addColumnDescriptor(new CustomRenderColumnDescriptor("table.header.typeimg", 0, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new MessageIconRenderer())); allThreadTableCtr.addColumnDescriptor(new StickyRenderColumnDescriptor("table.thread", 1, CMD_SHOWDETAIL, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new StickyThreadCellRenderer())); allThreadTableCtr.addColumnDescriptor( new StickyColumnDescriptor("table.userfriendlyname", 2, null, ureq.getLocale())); allThreadTableCtr.addColumnDescriptor(new StickyColumnDescriptor("table.lastModified", 3, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_CENTER)); allThreadTableCtr.addColumnDescriptor(new StickyColumnDescriptor("table.marked", 4, CMD_SHOWMARKED, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_RIGHT)); allThreadTableCtr.addColumnDescriptor(new StickyColumnDescriptor("table.unread", 5, CMD_SHOWNEW, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_RIGHT)); allThreadTableCtr.addColumnDescriptor(new StickyColumnDescriptor("table.total", 6, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_RIGHT)); singleThreadTableCtr = new TableController(tableConfig, ureq, getWindowControl(), getTranslator()); listenTo(singleThreadTableCtr); singleThreadTableCtr.addColumnDescriptor(new ThreadColumnDescriptor("table.title", 0, CMD_SHOWDETAIL)); singleThreadTableCtr.addColumnDescriptor( new DefaultColumnDescriptor("table.userfriendlyname", 1, null, ureq.getLocale())); singleThreadTableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.modified", 2, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_CENTER)); singleThreadTableCtr.addColumnDescriptor( new BooleanColumnDescriptor("table.header.state", 3, "", translate("table.row.new"))); rms = getReadSet(ureq.getIdentity()); // here we fetch which messages had // been read by the user threadList = prepareListTitles(msgs); // precalulate message deepness precalcMessageDeepness(msgs); // Default view forumPanel = putInitialPanel(vcListTitles); // jump to either the forum or the folder if the business-launch-path says so. final BusinessControl bc = getWindowControl().getBusinessControl(); final ContextEntry ce = bc.popLauncherContextEntry(); if (ce != null) { // a context path is left for me if (isLogDebugEnabled()) { logDebug("businesscontrol (for further jumps) would be: ", bc.toString()); } final OLATResourceable ores = ce.getOLATResourceable(); if (isLogDebugEnabled()) { logDebug("OLATResourceable= ", ores.toString()); } final Long resId = ores.getResourceableId(); if (resId.longValue() != 0) { if (isLogDebugEnabled()) { logDebug("messageId=", ores.getResourceableId().toString()); } currentMsg = fm.findMessage(ores.getResourceableId()); if (currentMsg != null) { showThreadView(ureq, currentMsg, null); scrollToCurrentMessage(); } else { // message not found, do nothing. Load normal start screen logDebug("Invalid messageId=", ores.getResourceableId().toString()); } } else { // FIXME:chg: Should not happen, occurs when course-node are called if (isLogDebugEnabled()) { logDebug("Invalid messageId=", ores.getResourceableId().toString()); } } } // Register for forum events CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, ureq.getIdentity(), forum); // filter for user vcFilterView = createVelocityContainer("filter_view"); }
From source file:org.apache.nifi.audit.AccessPolicyAuditor.java
/** * Extracts the values for the configured properties from the specified policy. *//*from w w w . ja v a 2 s .co m*/ private Map<String, String> extractConfiguredPropertyValues(AccessPolicy policy, AccessPolicyDTO policyDTO) { Map<String, String> values = new HashMap<>(); if (policyDTO.getUsers() != null) { // get each of the auto terminated relationship names final List<String> currentUsers = new ArrayList<>(policy.getUsers()); // sort them and include in the configuration Collections.sort(currentUsers, Collator.getInstance(Locale.US)); values.put(USERS, StringUtils.join(currentUsers, ", ")); } if (policyDTO.getUserGroups() != null) { // get each of the auto terminated relationship names final List<String> currentUserGroups = new ArrayList<>(policy.getGroups()); // sort them and include in the configuration Collections.sort(currentUserGroups, Collator.getInstance(Locale.US)); values.put(USER_GROUPS, StringUtils.join(currentUserGroups, ", ")); } return values; }
From source file:com.evolveum.midpoint.web.component.prism.ContainerValueWrapper.java
public void sort() { Locale locale = WebModelServiceUtils.getLocale(); if (locale == null) { locale = Locale.getDefault(); }//from w w w .j a v a 2 s .co m Collator collator = Collator.getInstance(locale); if (isSorted()) { collator.setStrength(Collator.SECONDARY); // e.g. "a" should be different from "" collator.setDecomposition(Collator.FULL_DECOMPOSITION); // slower but more precise Collections.sort(properties, new Comparator<ItemWrapper>() { @Override public int compare(ItemWrapper pw1, ItemWrapper pw2) { if (pw1 instanceof ContainerWrapper) { ((ContainerWrapper) pw1).sort(); } if (pw2 instanceof ContainerWrapper) { ((ContainerWrapper) pw2).sort(); } if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw1.getClass()) && pw2 instanceof ContainerWrapper) { return -1; } if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw2.getClass()) && pw1 instanceof ContainerWrapper) { return 1; } // return compareByDisplayNames(pw1, pw2, collator); } }); } else { Collections.sort(properties, new Comparator<ItemWrapper>() { @Override public int compare(ItemWrapper pw1, ItemWrapper pw2) { if (pw1 instanceof ContainerWrapper) { ((ContainerWrapper) pw1).sort(); } if (pw2 instanceof ContainerWrapper) { ((ContainerWrapper) pw2).sort(); } if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw1.getClass()) && pw2 instanceof ContainerWrapper) { return -1; } if (PropertyOrReferenceWrapper.class.isAssignableFrom(pw2.getClass()) && pw1 instanceof ContainerWrapper) { return 1; } ItemDefinition id1 = pw1.getItemDefinition(); ItemDefinition id2 = pw2.getItemDefinition(); int displayOrder1 = (id1 == null || id1.getDisplayOrder() == null) ? Integer.MAX_VALUE : id1.getDisplayOrder(); int displayOrder2 = (id2 == null || id2.getDisplayOrder() == null) ? Integer.MAX_VALUE : id2.getDisplayOrder(); if (displayOrder1 == displayOrder2) { return compareByDisplayNames(pw1, pw2, collator); } else { return Integer.compare(displayOrder1, displayOrder2); } } }); } }
From source file:nl.inl.util.StringUtil.java
/** * Get a Dutch, case-insensitive collator. * * @return the Dutch, case-insensitive collator. */// w w w . ja v a 2 s . c o m public static Collator getDutchInsensitiveCollator() { if (dutchInsensitiveCollator == null) { dutchInsensitiveCollator = Collator.getInstance(dutchLocale); dutchInsensitiveCollator.setStrength(Collator.SECONDARY); } return dutchInsensitiveCollator; }
From source file:com.all.client.model.predicate.BaseCollatorPredicate.java
private void initialize() { rules = ((RuleBasedCollator) Collator.getInstance(Locale.US)).getRules(); refineRules();//from w w w . ja v a 2 s. com try { collator = new RuleBasedCollator(rules); collator.setStrength(Collator.PRIMARY); } catch (ParseException e) { log.error("Error while parsing collator rules [" + rules + "]", e); } }