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 synchronized Collator getInstance() 

Source Link

Document

Gets the Collator for the current default locale.

Usage

From source file:org.sakaiproject.search.tool.SearchBeanImpl.java

public List<SearchTerm> getTerms() {
    if (termList == null) {
        mergeTerms();/*from  ww w .j a v a2  s  . c  om*/
        finalTermList = null;
    }
    if (termList == null) {
        return new ArrayList<SearchTerm>();
    }
    if (finalTermList != null) {
        return finalTermList;
    }
    finalTermList = new ArrayList<SearchTerm>();
    List<TermHolder> l = termList.subList(0, Math.min(nTerms, termList.size()));
    int j = 0;
    for (Iterator li = l.iterator(); li.hasNext();) {
        TermHolder t = (TermHolder) li.next();
        t.position = j;
        j++;
    }

    Collections.sort(l, new Comparator<TermHolder>() {
        Collator c = Collator.getInstance();

        public int compare(TermHolder a, TermHolder b) {
            return c.compare(a.term, b.term);
        }

    });
    int factor = 1;
    j = l.size();
    for (Iterator li = l.iterator(); li.hasNext();) {
        TermHolder t = (TermHolder) li.next();
        factor = Math.max(t.frequency, factor);
    }

    for (Iterator li = l.iterator(); li.hasNext();) {
        final TermHolder t = (TermHolder) li.next();
        float f = (float) (topTerms * t.frequency) / factor;
        if (relativeTerms) {
            f = (float) (topTerms * (l.size() - t.position)) / l.size();
        }
        f = f / divisorTerms;
        j--;
        final String weight = String.valueOf(f);
        final String searchScope = this.scope.name();
        finalTermList.add(new SearchTerm() {

            public String getName() {
                return FormattedText.escapeHtml(t.term, false);
            }

            public String getUrl() {
                try {
                    return FormattedText.escapeHtml("?panel=Main&search=" + URLEncoder.encode(t.term, "UTF-8")
                            + "&scope=" + searchScope, false);
                } catch (UnsupportedEncodingException e) {
                    return FormattedText.escapeHtml("?panel=Main&search=" + URLEncoder.encode(t.term), false);

                }
            }

            public String getWeight() {
                return weight;
            }
        });
    }
    return finalTermList;
}

From source file:org.alfresco.rest.api.impl.SitesImpl.java

private PagingResults<SiteInfo> getFavouriteSites(String userName, PagingRequest pagingRequest) {
    final Collator collator = Collator.getInstance();

    final Set<SiteInfo> sortedFavouriteSites = new TreeSet<SiteInfo>(new Comparator<SiteInfo>() {
        @Override//from  ww w  . j a v  a  2s . com
        public int compare(SiteInfo o1, SiteInfo o2) {
            return collator.compare(o1.getTitle(), o2.getTitle());
        }
    });

    Map<String, Serializable> prefs = preferenceService.getPreferences(userName, FAVOURITE_SITES_PREFIX);
    for (Entry<String, Serializable> entry : prefs.entrySet()) {
        boolean isFavourite = false;
        Serializable s = entry.getValue();
        if (s instanceof Boolean) {
            isFavourite = (Boolean) s;
        }
        if (isFavourite) {
            String siteShortName = entry.getKey().substring(FAVOURITE_SITES_PREFIX_LENGTH)
                    .replace(".favourited", "");
            SiteInfo siteInfo = siteService.getSite(siteShortName);
            if (siteInfo != null) {
                sortedFavouriteSites.add(siteInfo);
            }
        }
    }

    int totalSize = sortedFavouriteSites.size();
    final PageDetails pageDetails = PageDetails.getPageDetails(pagingRequest, totalSize);

    final List<SiteInfo> page = new ArrayList<SiteInfo>(pageDetails.getPageSize());
    Iterator<SiteInfo> it = sortedFavouriteSites.iterator();
    for (int counter = 0; counter < pageDetails.getEnd() && it.hasNext(); counter++) {
        SiteInfo favouriteSite = it.next();

        if (counter < pageDetails.getSkipCount()) {
            continue;
        }

        if (counter > pageDetails.getEnd() - 1) {
            break;
        }

        page.add(favouriteSite);
    }

    return new PagingResults<SiteInfo>() {
        @Override
        public List<SiteInfo> getPage() {
            return page;
        }

        @Override
        public boolean hasMoreItems() {
            return pageDetails.hasMoreItems();
        }

        @Override
        public Pair<Integer, Integer> getTotalResultCount() {
            Integer total = Integer.valueOf(sortedFavouriteSites.size());
            return new Pair<Integer, Integer>(total, total);
        }

        @Override
        public String getQueryExecutionId() {
            return null;
        }
    };
}

From source file:com.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java

private void setQueryString(String queryString) {
    if (!Collator.getInstance().equals(mQueryString, queryString)) {
        mQueryString = queryString;/*from ww w.ja va 2 s .c  om*/
        getSupportLoaderManager().restartLoader(0, null, this);
    }
}

From source file:org.alfresco.rest.api.tests.RepoService.java

private PagingResults<SiteInfo> getFavouriteSites(String userName, PagingRequest pagingRequest) {
    final Collator collator = Collator.getInstance();

    final Set<SiteInfo> sortedFavouriteSites = new TreeSet<SiteInfo>(new Comparator<SiteInfo>() {
        @Override/*from   w w w  .j  a  v  a 2  s.  c o m*/
        public int compare(SiteInfo o1, SiteInfo o2) {
            return collator.compare(o1.getTitle(), o2.getTitle());
        }
    });

    Map<String, Serializable> prefs = preferenceService.getPreferences(userName, FAVOURITE_SITES_PREFIX);
    for (String key : prefs.keySet()) {
        boolean isFavourite = false;
        Serializable s = prefs.get(key);
        if (s instanceof Boolean) {
            isFavourite = (Boolean) s;
        }
        if (isFavourite) {
            String siteShortName = key.substring(FAVOURITE_SITES_PREFIX_LENGTH);
            SiteInfo siteInfo = siteService.getSite(siteShortName);
            if (siteInfo != null) {
                sortedFavouriteSites.add(siteInfo);
            }
        }
    }

    int totalSize = sortedFavouriteSites.size();
    final PageDetails pageDetails = PageDetails.getPageDetails(pagingRequest, totalSize);

    final List<SiteInfo> page = new ArrayList<SiteInfo>(pageDetails.getPageSize());
    Iterator<SiteInfo> it = sortedFavouriteSites.iterator();
    for (int counter = 0; counter < pageDetails.getEnd() && it.hasNext(); counter++) {
        SiteInfo favouriteSite = it.next();

        if (counter < pageDetails.getSkipCount()) {
            continue;
        }

        if (counter > pageDetails.getEnd() - 1) {
            break;
        }

        page.add(favouriteSite);
    }

    return new PagingResults<SiteInfo>() {
        @Override
        public List<SiteInfo> getPage() {
            return page;
        }

        @Override
        public boolean hasMoreItems() {
            return pageDetails.hasMoreItems();
        }

        @Override
        public Pair<Integer, Integer> getTotalResultCount() {
            Integer total = Integer.valueOf(sortedFavouriteSites.size());
            return new Pair<Integer, Integer>(total, total);
        }

        @Override
        public String getQueryExecutionId() {
            return null;
        }
    };
}

From source file:hudson.model.Hudson.java

/**
 * Gets the read-only list of all {@link Computer}s.
 *//*from   ww  w .  j  a va  2s.c o  m*/
public Computer[] getComputers() {
    Computer[] r = computers.values().toArray(new Computer[computers.size()]);
    Arrays.sort(r, new Comparator<Computer>() {
        final Collator collator = Collator.getInstance();

        public int compare(Computer lhs, Computer rhs) {
            if (lhs.getNode() == Hudson.this)
                return -1;
            if (rhs.getNode() == Hudson.this)
                return 1;
            return collator.compare(lhs.getDisplayName(), rhs.getDisplayName());
        }
    });
    return r;
}

From source file:com.cnaude.purpleirc.PurpleIRC.java

/**
 *
 * @param ircBot/*from   w  ww .ja va2s.  c o  m*/
 * @param channelName
 * @return
 */
public PlayerList getMCPlayerList(PurpleBot ircBot, String channelName) {
    PlayerList pl = new PlayerList();

    Map<String, String> playerList = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    for (Player player : getServer().getOnlinePlayers()) {
        if (ircBot.hideListWhenVanished.get(channelName)) {
            logDebug("List: Checking if player " + player.getName() + " is vanished.");
            if (vanishHook.isVanished(player)) {
                logDebug("Not adding player to list command" + player.getName() + " due to being vanished.");
                continue;
            }
        }
        String pName = tokenizer.playerTokenizer(player, listPlayer);
        playerList.put(player.getName(), pName);
    }

    String pList;
    if (!listSortByName) {
        // sort as before
        ArrayList<String> tmp = new ArrayList<>(playerList.values());
        Collections.sort(tmp, Collator.getInstance());
        pList = Joiner.on(listSeparator).join(tmp);
    } else {
        // sort without nick prefixes
        pList = Joiner.on(listSeparator).join(playerList.values());
    }

    pl.count = playerList.size();
    pl.max = getServer().getMaxPlayers();
    pl.list = pList;

    return pl;

}

From source file:com.jaspersoft.studio.utils.ModelUtils.java

@SuppressWarnings("deprecation")
public static String[] getQueryLanguagesOnly(JasperReportsConfiguration context) {
    Set<String> langs = new HashSet<String>();
    List<JRQueryExecuterFactoryBundle> bundles = context.getExtensions(JRQueryExecuterFactoryBundle.class);

    ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
    try {/*from w w  w  . j  av a 2 s .  c  o  m*/
        Thread.currentThread().setContextClassLoader(context.getClassLoader());
        for (JRQueryExecuterFactoryBundle bundle : bundles) {
            String[] languages = bundle.getLanguages();
            for (String l : languages) {
                // check for depricated languages
                if (deprecatedLanguages.contains(l.toLowerCase()))
                    continue;
                if (!langs.contains(l)) {
                    boolean exists = false;
                    for (String item : langs) {
                        if (item.equalsIgnoreCase(l.trim())) {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                        langs.add(l);
                }
            }
        }
        List<QueryExecuterFactoryBundle> oldbundles = context.getExtensions(QueryExecuterFactoryBundle.class);
        for (QueryExecuterFactoryBundle bundle : oldbundles) {
            String[] languages = bundle.getLanguages();
            for (String l : languages) {
                // check for depricated languages
                if (deprecatedLanguages.contains(l.toLowerCase()))
                    continue;
                if (!langs.contains(l)) {
                    boolean exists = false;
                    for (String item : langs) {
                        if (item.equalsIgnoreCase(l.trim())) {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                        langs.add(l);
                }
            }
        }
    } finally {
        Thread.currentThread().setContextClassLoader(oldCL);
    }
    String[] languages = langs.toArray(new String[langs.size()]);
    Arrays.sort(languages, Collator.getInstance());
    return languages;
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

public void addDataSource(String name) {
    DBBrowserNode node = searchNode(DBNodeExpander.CONNECTIONS);

    // possibly node was not expanded, give it a chance to load children
    if (node.getChildCount() == 0) {
        startExpandingTree(node, false, null);
    }/*from ww w  . j  a v a  2 s. co  m*/

    DBBrowserNode dsNode = new DBBrowserNode(new DBObject(name, null, DBObject.DATABASE));
    dsNode.setAllowsChildren(true);

    DBBrowserNode foundNode = searchNode(name, DBObject.DATABASE);
    if (foundNode == null) {
        TreePath path = instance.getSelectionPath();
        Enumeration<TreePath> expandedPath = instance.getExpandedDescendants(path);

        int size = node.getChildCount();
        int insertedIndex = size;
        for (int i = 0; i < size; i++) {
            DBBrowserNode child = (DBBrowserNode) node.getChildAt(i);
            if (Collator.getInstance().compare(name, child.getDBObject().getName()) < 0) {
                insertedIndex = i;
                break;
            }
        }
        node.insert(dsNode, insertedIndex);
        model.nodeStructureChanged(node);
        // keep expanded path
        if (expandedPath != null) {
            while (expandedPath.hasMoreElements()) {
                instance.expandPath(expandedPath.nextElement());
            }
        }
    }

}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void insertFolder(DBBrowserNode parentNode, DBBrowserNode folderNode) {
    int count = parentNode.getChildCount();
    int index = 0;
    for (int i = 0; i < count; i++) {
        DBBrowserNode node = (DBBrowserNode) parentNode.getChildAt(i);
        if (node.getDBObject().isFolder()) {
            int compare = Collator.getInstance().compare(node.getDBObject().getName(),
                    folderNode.getDBObject().getName());
            if (compare < 0) {
                index++;/*from w  w  w .  j a va 2  s .co  m*/
            } else {
                break;
            }
        } else {
            break;
        }
    }
    parentNode.insert(folderNode, index);
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void insertFile(DBBrowserNode parentNode, DBBrowserNode fileNode) {
    int count = parentNode.getChildCount();
    int index = 0;
    for (int i = 0; i < count; i++) {
        DBBrowserNode node = (DBBrowserNode) parentNode.getChildAt(i);
        if (node.getDBObject().isFolder()) {
            index++;// ww w  . j  a va2 s .  c om
        } else {
            int compare = Collator.getInstance().compare(node.getDBObject().getName(),
                    fileNode.getDBObject().getName());
            if (compare < 0) {
                index++;
            } else {
                break;
            }
        }
    }
    parentNode.insert(fileNode, index);
}