use of java.text.Collator in project XPrivacy by M66B.
the class PrivacyManager method getRestrictions.
public static TreeMap<String, String> getRestrictions(Context context) {
Collator collator = Collator.getInstance(Locale.getDefault());
TreeMap<String, String> tmRestriction = new TreeMap<String, String>(collator);
for (String restrictionName : getRestrictions()) {
int stringId = context.getResources().getIdentifier("restrict_" + restrictionName, "string", context.getPackageName());
tmRestriction.put(stringId == 0 ? restrictionName : context.getString(stringId), restrictionName);
}
return tmRestriction;
}
use of java.text.Collator in project openkit-android by OpenKit.
the class GraphObjectAdapter method rebuildSections.
private void rebuildSections() {
sectionKeys = new ArrayList<String>();
graphObjectsBySection = new HashMap<String, ArrayList<T>>();
graphObjectsById = new HashMap<String, T>();
displaySections = false;
if (cursor == null || cursor.getCount() == 0) {
return;
}
int objectsAdded = 0;
cursor.moveToFirst();
do {
T graphObject = cursor.getGraphObject();
if (!filterIncludesItem(graphObject)) {
continue;
}
objectsAdded++;
String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject);
if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) {
sectionKeys.add(sectionKeyOfItem);
graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<T>());
}
List<T> section = graphObjectsBySection.get(sectionKeyOfItem);
section.add(graphObject);
graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject);
} while (cursor.moveToNext());
if (sortFields != null) {
final Collator collator = Collator.getInstance();
for (List<T> section : graphObjectsBySection.values()) {
Collections.sort(section, new Comparator<GraphObject>() {
@Override
public int compare(GraphObject a, GraphObject b) {
return compareGraphObjects(a, b, sortFields, collator);
}
});
}
}
Collections.sort(sectionKeys, Collator.getInstance());
displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD;
}
use of java.text.Collator in project hudson-2.x by hudson.
the class Hudson method getComputers.
/**
* Gets the read-only list of all {@link Computer}s.
*/
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;
}
use of java.text.Collator in project robovm by robovm.
the class CollatorTest method test_collationKeySize.
public void test_collationKeySize() throws Exception {
// Test to verify that very large collation keys are not truncated.
StringBuilder b = new StringBuilder();
for (int i = 0; i < 1024; i++) {
b.append("0123456789ABCDEF");
}
String sixteen = b.toString();
b.append("_THE_END");
String sixteenplus = b.toString();
Collator mColl = Collator.getInstance();
mColl.setStrength(Collator.PRIMARY);
byte[] arr = mColl.getCollationKey(sixteen).toByteArray();
int len = arr.length;
assertTrue("Collation key not 0 terminated", arr[arr.length - 1] == 0);
len--;
String foo = new String(arr, 0, len, "iso8859-1");
arr = mColl.getCollationKey(sixteen).toByteArray();
len = arr.length;
assertTrue("Collation key not 0 terminated", arr[arr.length - 1] == 0);
len--;
String bar = new String(arr, 0, len, "iso8859-1");
assertTrue("Collation keys should differ", foo.equals(bar));
}
use of java.text.Collator in project robovm by robovm.
the class CollatorTest method test_decompositionCompatibility.
public void test_decompositionCompatibility() throws Exception {
Collator myCollator = Collator.getInstance();
myCollator.setDecomposition(Collator.NO_DECOMPOSITION);
assertFalse("Error: ḁ̀ should not equal to ḁ̀ without decomposition", myCollator.compare("ḁ̀", "ḁ̀") == 0);
myCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
assertTrue("Error: ḁ̀ should equal to ḁ̀ with decomposition", myCollator.compare("ḁ̀", "ḁ̀") == 0);
}
Aggregations