001
014
015 package com.liferay.portlet.dynamicdatamapping.util.comparator;
016
017 import com.liferay.portal.kernel.util.LocaleThreadLocal;
018 import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
019
020 import java.text.Collator;
021
022 import java.util.Comparator;
023 import java.util.Locale;
024
025
029 public class DDMStructureNameComparator implements Comparator<DDMStructure> {
030
031 public DDMStructureNameComparator() {
032 this(true, LocaleThreadLocal.getSiteDefaultLocale());
033 }
034
035 public DDMStructureNameComparator(Locale locale) {
036 this(true, locale);
037 }
038
039 public DDMStructureNameComparator(boolean ascending, Locale locale) {
040 _ascending = ascending;
041 _locale = locale;
042 }
043
044 @Override
045 public int compare(DDMStructure DDMStructure1, DDMStructure DDMStructure2) {
046 Collator collator = Collator.getInstance(_locale);
047
048 int value = collator.compare(
049 DDMStructure1.getName(_locale), DDMStructure2.getName(_locale));
050
051 if (_ascending) {
052 return value;
053 }
054 else {
055 return - value;
056 }
057 }
058
059 private final boolean _ascending;
060 private final Locale _locale;
061
062 }