Example usage for java.text Collator getInstance

List of usage examples for java.text Collator getInstance

Introduction

In this page you can find the example usage for java.text Collator getInstance.

Prototype

public static Collator getInstance(Locale desiredLocale) 

Source Link

Document

Gets the Collator for the desired locale.

Usage

From source file:uk.q3c.krail.core.navigate.sitemap.DefaultFileSitemapLoader.java

@Inject
public DefaultFileSitemapLoader(CurrentLocale currentLocale, Translate translate, MasterSitemap sitemap) {
    super();/*ww  w . j  av  a2 s.  c  o m*/
    this.collator = Collator.getInstance(currentLocale.getLocale());
    this.translate = translate;
    this.sitemap = sitemap;

}

From source file:com.powers.wsexplorer.gui.GUIUtil.java

/**
 * Takes the map and returns the keys as a sorted list.
 * Sorted by using the Collator. /*from   ww  w.  ja  va 2  s . c  om*/
 * 
 * @see Collator
 * @param map
 * @return List of sorted keys
 */
public static List<String> sortKeys(Map<String, ?> map) {

    Set<String> keys = map.keySet();
    List<String> listToSort = new LinkedList<String>();
    listToSort.addAll(keys);
    Collections.sort(listToSort, Collator.getInstance(Locale.getDefault()));

    return listToSort;
}

From source file:org.jboss.dashboard.ui.formatters.FileNavigationTreeFormatter.java

protected void sortDirectories(List childDirectories) {
    final Collator collator = Collator.getInstance(getLocale());
    Collections.sort(childDirectories, new Comparator() {
        public int compare(Object o1, Object o2) {
            return collator.compare(((FileObject) o1).getName().getBaseName(),
                    ((FileObject) o2).getName().getBaseName());
        }/*from  ww  w .  j  av a 2 s.co m*/
    });
}

From source file:de.cosmocode.palava.ipc.legacy.LegacyHttpSessionAdapter.java

@Override
public Collator getCollator() {
    touch();
    if (collator == null) {
        collator = Collator.getInstance(getLocale());
    }
    return collator;
}

From source file:com.powers.wsexplorer.gui.GUIUtil.java

public static Listener createTextSortListener(final Table table, final List<String> list) {
    Listener sortListener = new Listener() {
        public void handleEvent(Event e) {

            final int direction = table.getSortDirection();

            Collator collator = Collator.getInstance(Locale.getDefault());
            TableColumn column = (TableColumn) e.widget;

            Collections.sort(list, collator);

            if (direction == SWT.DOWN) {
                Collections.reverse(list);
                table.setSortDirection(SWT.UP);
            } else {
                table.setSortDirection(SWT.DOWN);
            }/*from  w  ww . j  a v  a2 s. c  om*/

            table.removeAll();

            Iterator<String> itr = list.iterator();
            while (itr.hasNext()) {
                String value = itr.next();
                if (StringUtils.isNotBlank(value)) {
                    TableItem ti = new TableItem(table, SWT.BORDER);
                    ti.setText(0, value);
                }
            }

            table.setSortColumn(column);
        }
    };

    return sortListener;
}

From source file:com.cloudbees.plugins.credentials.CredentialsNameComparator.java

/**
 * {@inheritDoc}//  w  ww.  j  a v a2 s . c  o  m
 */
@Override
public int compare(Credentials c1, Credentials c2) {
    final String n1 = StringUtils.defaultString(CredentialsNameProvider.name(c1));
    final String n2 = StringUtils.defaultString(CredentialsNameProvider.name(c2));
    if (collator == null) {
        // in the event of a race condition this will be effectively idempotent so no need for synchronization.
        collator = Collator.getInstance(locale);
    }
    return ignoreCase ? collator.compare(n1.toLowerCase(locale), n2.toLowerCase(locale))
            : collator.compare(n1, n2);
}

From source file:de.uni_tuebingen.ub.ixTheo.handler.component.FacetPrefixSortComponent.java

/**
 * Choose the collator according to the selected language
 *///from   w  ww .j av a 2 s . c om

private void setCollator(final String langCode) {

    Locale locale = Locale.GERMAN;
    String transformedLangCode = "";

    // Rewrite lang parameter to required layout
    Matcher m = LANG_CODE_TRANSFORMATION_PATTERN.matcher(langCode);
    StringBuffer sb = new StringBuffer(langCode.length());
    while (m.find()) {
        if (m.group(1) != null)
            sb.append(m.group(1).toLowerCase());

        if (m.group(2) != null)
            sb.append(m.group(2).equals("-") ? "_" : "");

        if (m.group(3) != null)
            sb.append(m.group(3).toUpperCase());

        transformedLangCode = sb.toString();
    }

    try {
        locale = LocaleUtils.toLocale(transformedLangCode);
    } catch (IllegalArgumentException e) {
    }

    if (LocaleUtils.isAvailableLocale(locale))
        collator = Collator.getInstance(locale);
    else
        collator = Collator.getInstance(Locale.GERMAN);
}

From source file:uk.co.q3c.v7.base.navigate.TextReaderSitemapProvider.java

@Inject
public TextReaderSitemapProvider(StandardPageBuilder standardPageBuilder, CurrentLocale currentLocale) {
    super();/*w  ww .  ja  v a 2 s  .  c o  m*/
    this.standardPageBuilder = standardPageBuilder;
    this.currentLocale = currentLocale;
    this.collator = Collator.getInstance(currentLocale.getLocale());

}

From source file:org.jboss.dashboard.ui.formatters.FileNavigationFileListFormatter.java

protected void sortFiles(List files) {
    final Collator collator = Collator.getInstance(getLocale());
    Collections.sort(files, new Comparator() {
        public int compare(Object o1, Object o2) {
            return collator.compare(((FileObject) o1).getName().getBaseName(),
                    ((FileObject) o2).getName().getBaseName());
        }//from w  ww  .j a  v  a  2 s.c o  m
    });
}

From source file:com.powers.wsexplorer.gui.GUIUtil.java

public static Listener createTextSortListener(final Table table, final Map<String, String> map) {

    Listener sortListener = new Listener() {
        public void handleEvent(Event e) {

            final int direction = table.getSortDirection();

            Collator collator = Collator.getInstance(Locale.getDefault());
            TableColumn column = (TableColumn) e.widget;

            Set<String> keys = map.keySet();
            List<String> l = new LinkedList<String>();
            l.addAll(keys);/*w  w w .j  a  va 2 s  . c o  m*/

            Collections.sort(l, collator);

            if (direction == SWT.DOWN) {
                Collections.reverse(l);
                table.setSortDirection(SWT.UP);
            } else {
                table.setSortDirection(SWT.DOWN);
            }

            table.removeAll();

            Iterator<String> itr = l.iterator();
            String key = null;
            String value = null;

            while (itr.hasNext()) {
                key = itr.next();
                if (StringUtils.isNotBlank(key)) {
                    TableItem ti = new TableItem(table, SWT.BORDER);
                    ti.setText(0, key);
                    value = map.get(key);
                    if (StringUtils.isNotBlank(value)) {
                        ti.setText(1, value);
                    }
                }

            }

            table.setSortColumn(column);
        }
    };

    return sortListener;
}