package org.beanmaker.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Names {

    public static <B extends NamedDbBean> List<String> getList(final Collection<B> beans) {
        final List<String> names = new ArrayList<String>();

        for (B bean: beans)
            names.add(bean.getDisplayName());

        return names;
    }

    public static <B extends NamedDbBean> List<String> getSortedList(final Collection<B> beans) {
        final List<String> names = getList(beans);
        Collections.sort(names);
        return names;
    }

    public static <B extends MultiLingualNamedDbBean> List<String> getList(
            final Collection<B> beans,
            final DbBeanLanguage dbBeanLanguage)
    {
        final List<String> names = new ArrayList<String>();

        for (B bean: beans)
            names.add(bean.getDisplayName(dbBeanLanguage));

        return names;
    }

    public static <B extends MultiLingualNamedDbBean> List<String> getSortedList(
            final Collection<B> beans,
            final DbBeanLanguage dbBeanLanguage)
    {
        final List<String> names = getList(beans, dbBeanLanguage);
        Collections.sort(names);
        return names;
    }

    public static <B extends DbBeanMultilingual> List<String> getListFromMultilingualBeans(
            final Collection<B> beans,
            final DbBeanLanguage dbBeanLanguage)
    {
        final List<String> names = new ArrayList<String>();

        for (B bean: beans)
            names.add(bean.getLabel(dbBeanLanguage));

        return names;
    }

    public static <B extends DbBeanMultilingual> List<String> getSortedListFromMultilingualBeans(
            final Collection<B> beans,
            final DbBeanLanguage dbBeanLanguage)
    {
        final List<String> names = getListFromMultilingualBeans(beans, dbBeanLanguage);
        Collections.sort(names);
        return names;
    }
}

@@ -22,16 +22,44 @@
 .util;%0A%0A
+import java.text.Collator;%0A%0A
 import j
@@ -154,20 +154,74 @@
 va.util.
-List
+Comparator;%0Aimport java.util.List;%0Aimport java.util.Locale
 ;%0A%0Apubli
@@ -697,32 +697,807 @@
 n names;%0A    %7D%0A%0A
+    public static %3CB extends NamedDbBean%3E void sortList(final List%3CB%3E beans) %7B%0A        Collections.sort(beans, new Comparator%3CB%3E() %7B%0A            @Override%0A            public int compare(B bean1, B bean2) %7B%0A                return bean1.getDisplayName().compareTo(bean2.getDisplayName());%0A            %7D%0A        %7D);%0A    %7D%0A%0A    public static %3CB extends NamedDbBean%3E void sortList(final List%3CB%3E beans, Locale locale) %7B%0A        final Collator collator = Collator.getInstance(locale);%0A        collator.setStrength(Collator.PRIMARY);%0A        Collections.sort(beans, new Comparator%3CB%3E() %7B%0A            @Override%0A            public int compare(B bean1, B bean2) %7B%0A                return collator.compare(bean1.getDisplayName(), bean2.getDisplayName());%0A            %7D%0A        %7D);%0A    %7D%0A%0A
     public stati
@@ -2126,32 +2126,598 @@
 n names;%0A    %7D%0A%0A
+    public static %3CB extends MultiLingualNamedDbBean%3E void sortList(%0A            final List%3CB%3E beans,%0A            final DbBeanLanguage dbBeanLanguage)%0A    %7B%0A        final Collator collator = Collator.getInstance(dbBeanLanguage.getLocale());%0A        collator.setStrength(Collator.PRIMARY);%0A        Collections.sort(beans, new Comparator%3CB%3E() %7B%0A            @Override%0A            public int compare(B bean1, B bean2) %7B%0A                return collator.compare(bean1.getDisplayName(dbBeanLanguage), bean2.getDisplayName(dbBeanLanguage));%0A            %7D%0A        %7D);%0A    %7D%0A%0A
     public stati

Add support for sorting named beans according to a Locale collation order