Example usage for com.liferay.portal.kernel.util NaturalOrderStringComparator NaturalOrderStringComparator

List of usage examples for com.liferay.portal.kernel.util NaturalOrderStringComparator NaturalOrderStringComparator

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util NaturalOrderStringComparator NaturalOrderStringComparator.

Prototype

public NaturalOrderStringComparator() 

Source Link

Usage

From source file:com.liferay.message.boards.web.internal.portlet.action.MBAdminConfigurationAction.java

License:Open Source License

protected void updateUserRanks(ActionRequest actionRequest) {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    for (Locale locale : LanguageUtil.getAvailableLocales(themeDisplay.getSiteGroupId())) {

        String languageId = LocaleUtil.toLanguageId(locale);

        String[] ranks = StringUtil.splitLines(ParamUtil.getString(actionRequest, "ranks_" + languageId));

        Map<String, String> map = new TreeMap<>(new NaturalOrderStringComparator());

        for (String rank : ranks) {
            if (!isValidUserRank(rank)) {
                SessionErrors.add(actionRequest, "userRank");

                return;
            }//from   www.  j av  a 2  s  .  c  om

            String[] kvp = StringUtil.split(rank, CharPool.EQUAL);

            String kvpName = kvp[0];
            String kvpValue = kvp[1];

            map.put(kvpValue, kvpName);
        }

        ranks = new String[map.size()];

        int count = 0;

        for (Map.Entry<String, String> entry : map.entrySet()) {
            String kvpValue = entry.getKey();
            String kvpName = entry.getValue();

            ranks[count++] = kvpName + StringPool.EQUAL + kvpValue;
        }

        String preferenceName = LocalizationUtil.getLocalizedName("ranks", languageId);

        setPreference(actionRequest, preferenceName, ranks);
    }
}