use of java.text.Collator in project OpenAM by OpenRock.
the class DirectoryServicesImpl method search.
// RENAME from searchUsingSearchControl => search()
/**
* Search the Directory
*
* @param token
* SSOToken
* @param entryDN
* DN of the entry to start the search with
* @param searchFilter
* search filter
* @param searchControl
* search control defining the VLV indexes and search scope
* @param attrNames
* name of attributes
* @return Set set of matching DNs
*/
public AMSearchResults search(SSOToken token, String entryDN, String searchFilter, SearchControl searchControl, String[] attrNames) throws AMException {
AMSearchResults amResults = null;
try {
SortKey[] skeys = searchControl.getSortKeys();
SortKey skey = null;
if (skeys != null && skeys.length > 0 && skeys[0].attributeName != null) {
skey = skeys[0];
}
String userLocale = CommonUtils.getUserLocale(token);
if (debug.messageEnabled()) {
debug.message("DirectoryServicesImpl.search() search with " + "searchcontrol locale = " + userLocale);
}
Collator collator = Collator.getInstance(Locale.getLocale(userLocale));
SearchControl sc;
if (skey != null) {
sc = new SearchControl();
sc.setMaxResults(searchControl.getMaxResults());
sc.setSearchScope(searchControl.getSearchScope());
sc.setTimeOut(searchControl.getTimeOut());
} else {
sc = searchControl;
}
PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
SearchResults results;
if (attrNames == null) {
if (skey == null) {
results = po.search(searchFilter, sc);
} else {
String[] tmpAttrNames = { skey.attributeName };
results = po.search(searchFilter, tmpAttrNames, sc);
}
} else {
if (skey == null) {
results = po.search(searchFilter, attrNames, sc);
} else {
String[] tmpAttrNames = new String[attrNames.length + 1];
System.arraycopy(attrNames, 0, tmpAttrNames, 0, attrNames.length);
tmpAttrNames[attrNames.length] = skey.attributeName;
results = po.search(searchFilter, tmpAttrNames, sc);
}
}
amResults = getSearchResults(results, skey, attrNames, collator, sc.isGetAllReturnAttributesEnabled());
} catch (UMSException ue) {
if (debug.warningEnabled()) {
debug.warning("DirectoryServicesImpl.search() with search " + "control entryDN: " + entryDN + " Search Filter: " + searchFilter + " Error occurred: ", ue);
}
processInternalException(token, ue, "341");
}
return amResults;
}
use of java.text.Collator in project pcgen by PCGen.
the class TempBonusFacadeImpl method compareTo.
@Override
public int compareTo(TempBonusFacadeImpl o) {
final Collator collator = Collator.getInstance();
// Check sort keys first
String key1 = this.getOriginObj().get(StringKey.SORT_KEY);
if (key1 == null) {
key1 = this.getOriginObj().getDisplayName();
}
String key2 = o.getOriginObj().get(StringKey.SORT_KEY);
if (key2 == null) {
key2 = o.getOriginObj().getDisplayName();
}
if (!key1.equals(key2)) {
return collator.compare(key1, key2);
}
return collator.compare(this.getOriginObj().getDisplayName(), o.getOriginObj().getDisplayName());
}
use of java.text.Collator in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class InputMethodAndLanguageSettings method updateInputMethodPreferenceViews.
private void updateInputMethodPreferenceViews() {
if (mKeyboardSettingsCategory == null) {
return;
}
synchronized (mInputMethodPreferenceList) {
// Clear existing "InputMethodPreference"s
for (final InputMethodPreference pref : mInputMethodPreferenceList) {
mKeyboardSettingsCategory.removePreference(pref);
}
mInputMethodPreferenceList.clear();
List<String> permittedList = mDpm.getPermittedInputMethodsForCurrentUser();
final Context context = getPrefContext();
final List<InputMethodInfo> imis = mShowsOnlyFullImeAndKeyboardList ? mInputMethodSettingValues.getInputMethodList() : mImm.getEnabledInputMethodList();
final int N = (imis == null ? 0 : imis.size());
for (int i = 0; i < N; ++i) {
final InputMethodInfo imi = imis.get(i);
final boolean isAllowedByOrganization = permittedList == null || permittedList.contains(imi.getPackageName());
final InputMethodPreference pref = new InputMethodPreference(context, imi, mShowsOnlyFullImeAndKeyboardList, /* hasSwitch */
isAllowedByOrganization, this);
mInputMethodPreferenceList.add(pref);
}
final Collator collator = Collator.getInstance();
Collections.sort(mInputMethodPreferenceList, new Comparator<InputMethodPreference>() {
@Override
public int compare(InputMethodPreference lhs, InputMethodPreference rhs) {
return lhs.compareTo(rhs, collator);
}
});
for (int i = 0; i < N; ++i) {
final InputMethodPreference pref = mInputMethodPreferenceList.get(i);
mKeyboardSettingsCategory.addPreference(pref);
InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
pref.updatePreferenceViews();
}
}
updateCurrentImeName();
// TODO: Consolidate the logic with InputMethodSettingsWrapper
// CAVEAT: The preference class here does not know about the default value - that is
// managed by the Input Method Manager Service, so in this case it could save the wrong
// value. Hence we must update the checkboxes here.
InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(this, getContentResolver(), mInputMethodSettingValues.getInputMethodList(), null);
}
use of java.text.Collator in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class VirtualKeyboardFragment method updateInputMethodPreferenceViews.
private void updateInputMethodPreferenceViews() {
// Clear existing "InputMethodPreference"s
mInputMethodPreferenceList.clear();
List<String> permittedList = mDpm.getPermittedInputMethodsForCurrentUser();
final Context context = getPrefContext();
final List<InputMethodInfo> imis = mImm.getEnabledInputMethodList();
final int N = (imis == null ? 0 : imis.size());
for (int i = 0; i < N; ++i) {
final InputMethodInfo imi = imis.get(i);
final boolean isAllowedByOrganization = permittedList == null || permittedList.contains(imi.getPackageName());
Drawable icon;
try {
// TODO: Consider other ways to retrieve an icon to show here.
icon = getActivity().getPackageManager().getApplicationIcon(imi.getPackageName());
} catch (Exception e) {
// TODO: Consider handling the error differently perhaps by showing default icons.
icon = NO_ICON;
}
final InputMethodPreference pref = new InputMethodPreference(context, imi, false, /* isImeEnabler */
isAllowedByOrganization, null);
pref.setIcon(icon);
mInputMethodPreferenceList.add(pref);
}
final Collator collator = Collator.getInstance();
Collections.sort(mInputMethodPreferenceList, new Comparator<InputMethodPreference>() {
@Override
public int compare(InputMethodPreference lhs, InputMethodPreference rhs) {
return lhs.compareTo(rhs, collator);
}
});
getPreferenceScreen().removeAll();
for (int i = 0; i < N; ++i) {
final InputMethodPreference pref = mInputMethodPreferenceList.get(i);
pref.setOrder(i);
getPreferenceScreen().addPreference(pref);
InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
pref.updatePreferenceViews();
}
mAddVirtualKeyboardScreen.setIcon(R.drawable.ic_add_24dp);
mAddVirtualKeyboardScreen.setOrder(N);
getPreferenceScreen().addPreference(mAddVirtualKeyboardScreen);
}
use of java.text.Collator in project zm-mailbox by Zimbra.
the class Entry method sortByDisplayName.
/**
* Sort a collection of Entries by locale-sensitive String comparison on
* each entry's displayName. If there is no display name, use entry.getLabel()
* as the key.
*/
public static List<Entry> sortByDisplayName(Collection<? extends Entry> entries, Locale locale) {
List<Entry> sorted = Lists.newArrayList();
// short-circuit if there is only one entry or no entry
if (entries.size() <= 1) {
sorted.addAll(entries);
} else {
Collator collator = Collator.getInstance(locale);
TreeMultimap<CollationKey, Entry> map = TreeMultimap.create(Ordering.natural(), new SortByLabelAsc());
for (Entry entry : entries) {
String key = entry.getAttr(Provisioning.A_displayName);
if (key == null) {
key = entry.getLabel();
}
CollationKey collationKey = collator.getCollationKey(key);
map.put(collationKey, entry);
}
sorted.addAll(map.values());
}
return sorted;
}
Aggregations