am 1b467387: Rename "csv" in StringUtils to "commaConcatenatedText"
* commit '1b46738796eafa2dc062f4a93b0ea42023945737': Rename "csv" in StringUtils to "commaConcatenatedText"main
commit
cc496f42ac
|
@ -49,13 +49,14 @@ public final class AdditionalSubtype {
|
||||||
&& SubtypeLocale.isExceptionalLocale(localeString)) {
|
&& SubtypeLocale.isExceptionalLocale(localeString)) {
|
||||||
final String layoutDisplayName = SubtypeLocale.getKeyboardLayoutSetDisplayName(
|
final String layoutDisplayName = SubtypeLocale.getKeyboardLayoutSetDisplayName(
|
||||||
keyboardLayoutSetName);
|
keyboardLayoutSetName);
|
||||||
layoutDisplayNameExtraValue = StringUtils.appendToCsvIfNotExists(
|
layoutDisplayNameExtraValue = StringUtils.appendToCommaConcatenatedTextIfNotExists(
|
||||||
UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME + "=" + layoutDisplayName, extraValue);
|
UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME + "=" + layoutDisplayName, extraValue);
|
||||||
} else {
|
} else {
|
||||||
layoutDisplayNameExtraValue = extraValue;
|
layoutDisplayNameExtraValue = extraValue;
|
||||||
}
|
}
|
||||||
final String additionalSubtypeExtraValue = StringUtils.appendToCsvIfNotExists(
|
final String additionalSubtypeExtraValue =
|
||||||
IS_ADDITIONAL_SUBTYPE, layoutDisplayNameExtraValue);
|
StringUtils.appendToCommaConcatenatedTextIfNotExists(
|
||||||
|
IS_ADDITIONAL_SUBTYPE, layoutDisplayNameExtraValue);
|
||||||
final int nameId = SubtypeLocale.getSubtypeNameId(localeString, keyboardLayoutSetName);
|
final int nameId = SubtypeLocale.getSubtypeNameId(localeString, keyboardLayoutSetName);
|
||||||
return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
|
return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
|
||||||
localeString, KEYBOARD_MODE,
|
localeString, KEYBOARD_MODE,
|
||||||
|
@ -66,8 +67,9 @@ public final class AdditionalSubtype {
|
||||||
final String localeString = subtype.getLocale();
|
final String localeString = subtype.getLocale();
|
||||||
final String keyboardLayoutSetName = SubtypeLocale.getKeyboardLayoutSetName(subtype);
|
final String keyboardLayoutSetName = SubtypeLocale.getKeyboardLayoutSetName(subtype);
|
||||||
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
|
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
|
||||||
final String extraValue = StringUtils.removeFromCsvIfExists(layoutExtraValue,
|
final String extraValue = StringUtils.removeFromCommaConcatenatedTextIfExists(
|
||||||
StringUtils.removeFromCsvIfExists(IS_ADDITIONAL_SUBTYPE, subtype.getExtraValue()));
|
layoutExtraValue, StringUtils.removeFromCommaConcatenatedTextIfExists(
|
||||||
|
IS_ADDITIONAL_SUBTYPE, subtype.getExtraValue()));
|
||||||
final String basePrefSubtype = localeString + LOCALE_AND_LAYOUT_SEPARATOR
|
final String basePrefSubtype = localeString + LOCALE_AND_LAYOUT_SEPARATOR
|
||||||
+ keyboardLayoutSetName;
|
+ keyboardLayoutSetName;
|
||||||
return extraValue.isEmpty() ? basePrefSubtype
|
return extraValue.isEmpty() ? basePrefSubtype
|
||||||
|
|
|
@ -199,6 +199,7 @@ public final class InputAttributes {
|
||||||
if (editorInfo == null) return false;
|
if (editorInfo == null) return false;
|
||||||
final String findingKey = (packageName != null) ? packageName + "." + key
|
final String findingKey = (packageName != null) ? packageName + "." + key
|
||||||
: key;
|
: key;
|
||||||
return StringUtils.containsInCsv(findingKey, editorInfo.privateImeOptions);
|
return StringUtils.containsInCommaConcatenatedText(
|
||||||
|
findingKey, editorInfo.privateImeOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,33 +35,50 @@ public final class StringUtils {
|
||||||
return text.codePointCount(0, text.length());
|
return text.codePointCount(0, text.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsInArray(final String key, final String[] array) {
|
public static boolean containsInArray(final String text, final String[] array) {
|
||||||
for (final String element : array) {
|
for (final String element : array) {
|
||||||
if (key.equals(element)) return true;
|
if (text.equals(element)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean containsInCsv(final String key, final String csv) {
|
private static final String SEPARATOR_FOR_COMMA_CONCATENATED_TEXT = ",";
|
||||||
if (TextUtils.isEmpty(csv)) return false;
|
|
||||||
return containsInArray(key, csv.split(","));
|
public static boolean containsInCommaConcatenatedText(final String text,
|
||||||
|
final String extraValues) {
|
||||||
|
if (TextUtils.isEmpty(extraValues)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return containsInArray(text, extraValues.split(SEPARATOR_FOR_COMMA_CONCATENATED_TEXT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String appendToCsvIfNotExists(final String key, final String csv) {
|
public static String appendToCommaConcatenatedTextIfNotExists(final String text,
|
||||||
if (TextUtils.isEmpty(csv)) return key;
|
final String extraValues) {
|
||||||
if (containsInCsv(key, csv)) return csv;
|
if (TextUtils.isEmpty(extraValues)) {
|
||||||
return csv + "," + key;
|
return text;
|
||||||
|
}
|
||||||
|
if (containsInCommaConcatenatedText(text, extraValues)) {
|
||||||
|
return extraValues;
|
||||||
|
}
|
||||||
|
return extraValues + SEPARATOR_FOR_COMMA_CONCATENATED_TEXT + text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String removeFromCsvIfExists(final String key, final String csv) {
|
public static String removeFromCommaConcatenatedTextIfExists(final String text,
|
||||||
if (TextUtils.isEmpty(csv)) return "";
|
final String extraValues) {
|
||||||
final String[] elements = csv.split(",");
|
if (TextUtils.isEmpty(extraValues)) {
|
||||||
if (!containsInArray(key, elements)) return csv;
|
return "";
|
||||||
|
}
|
||||||
|
final String[] elements = extraValues.split(SEPARATOR_FOR_COMMA_CONCATENATED_TEXT);
|
||||||
|
if (!containsInArray(text, elements)) {
|
||||||
|
return extraValues;
|
||||||
|
}
|
||||||
final ArrayList<String> result = CollectionUtils.newArrayList(elements.length - 1);
|
final ArrayList<String> result = CollectionUtils.newArrayList(elements.length - 1);
|
||||||
for (final String element : elements) {
|
for (final String element : elements) {
|
||||||
if (!key.equals(element)) result.add(element);
|
if (!text.equals(element)) {
|
||||||
|
result.add(element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return TextUtils.join(",", result);
|
return TextUtils.join(SEPARATOR_FOR_COMMA_CONCATENATED_TEXT, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,57 +40,62 @@ public class StringUtilsTests extends AndroidTestCase {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testContainsInCsv() {
|
public void testContainsInExtraValues() {
|
||||||
assertFalse("null", StringUtils.containsInCsv("key", null));
|
assertFalse("null", StringUtils.containsInCommaConcatenatedText("key", null));
|
||||||
assertFalse("empty", StringUtils.containsInCsv("key", ""));
|
assertFalse("empty", StringUtils.containsInCommaConcatenatedText("key", ""));
|
||||||
assertFalse("not in 1 element", StringUtils.containsInCsv("key", "key1"));
|
assertFalse("not in 1 element",
|
||||||
assertFalse("not in 2 elements", StringUtils.containsInCsv("key", "key1,key2"));
|
StringUtils.containsInCommaConcatenatedText("key", "key1"));
|
||||||
|
assertFalse("not in 2 elements",
|
||||||
|
StringUtils.containsInCommaConcatenatedText("key", "key1,key2"));
|
||||||
|
|
||||||
assertTrue("in 1 element", StringUtils.containsInCsv("key", "key"));
|
assertTrue("in 1 element", StringUtils.containsInCommaConcatenatedText("key", "key"));
|
||||||
assertTrue("in 2 elements", StringUtils.containsInCsv("key", "key1,key"));
|
assertTrue("in 2 elements", StringUtils.containsInCommaConcatenatedText("key", "key1,key"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAppendToCsvIfNotExists() {
|
public void testAppendToExtraValuesIfNotExists() {
|
||||||
assertEquals("null", "key", StringUtils.appendToCsvIfNotExists("key", null));
|
assertEquals("null", "key",
|
||||||
assertEquals("empty", "key", StringUtils.appendToCsvIfNotExists("key", ""));
|
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", null));
|
||||||
|
assertEquals("empty", "key",
|
||||||
|
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", ""));
|
||||||
|
|
||||||
assertEquals("not in 1 element", "key1,key",
|
assertEquals("not in 1 element", "key1,key",
|
||||||
StringUtils.appendToCsvIfNotExists("key", "key1"));
|
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key1"));
|
||||||
assertEquals("not in 2 elements", "key1,key2,key",
|
assertEquals("not in 2 elements", "key1,key2,key",
|
||||||
StringUtils.appendToCsvIfNotExists("key", "key1,key2"));
|
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key1,key2"));
|
||||||
|
|
||||||
assertEquals("in 1 element", "key",
|
assertEquals("in 1 element", "key",
|
||||||
StringUtils.appendToCsvIfNotExists("key", "key"));
|
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key"));
|
||||||
assertEquals("in 2 elements at position 1", "key,key2",
|
assertEquals("in 2 elements at position 1", "key,key2",
|
||||||
StringUtils.appendToCsvIfNotExists("key", "key,key2"));
|
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key,key2"));
|
||||||
assertEquals("in 2 elements at position 2", "key1,key",
|
assertEquals("in 2 elements at position 2", "key1,key",
|
||||||
StringUtils.appendToCsvIfNotExists("key", "key1,key"));
|
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key1,key"));
|
||||||
assertEquals("in 3 elements at position 2", "key1,key,key3",
|
assertEquals("in 3 elements at position 2", "key1,key,key3",
|
||||||
StringUtils.appendToCsvIfNotExists("key", "key1,key,key3"));
|
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key1,key,key3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveFromCsvIfExists() {
|
public void testRemoveFromExtraValuesIfExists() {
|
||||||
assertEquals("null", "", StringUtils.removeFromCsvIfExists("key", null));
|
assertEquals("null", "", StringUtils.removeFromCommaConcatenatedTextIfExists("key", null));
|
||||||
assertEquals("empty", "", StringUtils.removeFromCsvIfExists("key", ""));
|
assertEquals("empty", "", StringUtils.removeFromCommaConcatenatedTextIfExists("key", ""));
|
||||||
|
|
||||||
assertEquals("not in 1 element", "key1",
|
assertEquals("not in 1 element", "key1",
|
||||||
StringUtils.removeFromCsvIfExists("key", "key1"));
|
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key1"));
|
||||||
assertEquals("not in 2 elements", "key1,key2",
|
assertEquals("not in 2 elements", "key1,key2",
|
||||||
StringUtils.removeFromCsvIfExists("key", "key1,key2"));
|
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key1,key2"));
|
||||||
|
|
||||||
assertEquals("in 1 element", "",
|
assertEquals("in 1 element", "",
|
||||||
StringUtils.removeFromCsvIfExists("key", "key"));
|
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key"));
|
||||||
assertEquals("in 2 elements at position 1", "key2",
|
assertEquals("in 2 elements at position 1", "key2",
|
||||||
StringUtils.removeFromCsvIfExists("key", "key,key2"));
|
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key,key2"));
|
||||||
assertEquals("in 2 elements at position 2", "key1",
|
assertEquals("in 2 elements at position 2", "key1",
|
||||||
StringUtils.removeFromCsvIfExists("key", "key1,key"));
|
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key1,key"));
|
||||||
assertEquals("in 3 elements at position 2", "key1,key3",
|
assertEquals("in 3 elements at position 2", "key1,key3",
|
||||||
StringUtils.removeFromCsvIfExists("key", "key1,key,key3"));
|
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key1,key,key3"));
|
||||||
|
|
||||||
assertEquals("in 3 elements at position 1,2,3", "",
|
assertEquals("in 3 elements at position 1,2,3", "",
|
||||||
StringUtils.removeFromCsvIfExists("key", "key,key,key"));
|
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key,key,key"));
|
||||||
assertEquals("in 5 elements at position 2,4", "key1,key3,key5",
|
assertEquals("in 5 elements at position 2,4", "key1,key3,key5",
|
||||||
StringUtils.removeFromCsvIfExists("key", "key1,key,key3,key,key5"));
|
StringUtils.removeFromCommaConcatenatedTextIfExists(
|
||||||
|
"key", "key1,key,key3,key,key5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue