Rename commaConcatinatedText to commaSplittableText

This is a follow up of I5a32882a08.

Change-Id: I9f0cda2167811f6bba2af042fbde0a821b4cfecd
main
Tadashi G. Takaoka 2013-05-28 19:12:12 +09:00
parent 6d77ae9d81
commit c47bc30db8
4 changed files with 43 additions and 39 deletions

View File

@ -49,13 +49,13 @@ public final class AdditionalSubtype {
&& SubtypeLocale.isExceptionalLocale(localeString)) {
final String layoutDisplayName = SubtypeLocale.getKeyboardLayoutSetDisplayName(
keyboardLayoutSetName);
layoutDisplayNameExtraValue = StringUtils.appendToCommaConcatenatedTextIfNotExists(
layoutDisplayNameExtraValue = StringUtils.appendToCommaSplittableTextIfNotExists(
UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME + "=" + layoutDisplayName, extraValue);
} else {
layoutDisplayNameExtraValue = extraValue;
}
final String additionalSubtypeExtraValue =
StringUtils.appendToCommaConcatenatedTextIfNotExists(
StringUtils.appendToCommaSplittableTextIfNotExists(
IS_ADDITIONAL_SUBTYPE, layoutDisplayNameExtraValue);
final int nameId = SubtypeLocale.getSubtypeNameId(localeString, keyboardLayoutSetName);
return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
@ -67,8 +67,8 @@ public final class AdditionalSubtype {
final String localeString = subtype.getLocale();
final String keyboardLayoutSetName = SubtypeLocale.getKeyboardLayoutSetName(subtype);
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
final String extraValue = StringUtils.removeFromCommaConcatenatedTextIfExists(
layoutExtraValue, StringUtils.removeFromCommaConcatenatedTextIfExists(
final String extraValue = StringUtils.removeFromCommaSplittableTextIfExists(
layoutExtraValue, StringUtils.removeFromCommaSplittableTextIfExists(
IS_ADDITIONAL_SUBTYPE, subtype.getExtraValue()));
final String basePrefSubtype = localeString + LOCALE_AND_LAYOUT_SEPARATOR
+ keyboardLayoutSetName;

View File

@ -199,7 +199,6 @@ public final class InputAttributes {
if (editorInfo == null) return false;
final String findingKey = (packageName != null) ? packageName + "." + key
: key;
return StringUtils.containsInCommaConcatenatedText(
findingKey, editorInfo.privateImeOptions);
return StringUtils.containsInCommaSplittableText(findingKey, editorInfo.privateImeOptions);
}
}

View File

@ -42,33 +42,38 @@ public final class StringUtils {
return false;
}
private static final String SEPARATOR_FOR_COMMA_CONCATENATED_TEXT = ",";
/**
* Comma-Splittable Text is similar to Comma-Separated Values (CSV) but has much simpler syntax.
* Unlike CSV, Comma-Splittable Text has no escaping mechanism, so that the text can't contain
* a comma character in it.
*/
private static final String SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT = ",";
public static boolean containsInCommaConcatenatedText(final String text,
public static boolean containsInCommaSplittableText(final String text,
final String extraValues) {
if (TextUtils.isEmpty(extraValues)) {
return false;
}
return containsInArray(text, extraValues.split(SEPARATOR_FOR_COMMA_CONCATENATED_TEXT));
return containsInArray(text, extraValues.split(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT));
}
public static String appendToCommaConcatenatedTextIfNotExists(final String text,
public static String appendToCommaSplittableTextIfNotExists(final String text,
final String extraValues) {
if (TextUtils.isEmpty(extraValues)) {
return text;
}
if (containsInCommaConcatenatedText(text, extraValues)) {
if (containsInCommaSplittableText(text, extraValues)) {
return extraValues;
}
return extraValues + SEPARATOR_FOR_COMMA_CONCATENATED_TEXT + text;
return extraValues + SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT + text;
}
public static String removeFromCommaConcatenatedTextIfExists(final String text,
public static String removeFromCommaSplittableTextIfExists(final String text,
final String extraValues) {
if (TextUtils.isEmpty(extraValues)) {
return "";
}
final String[] elements = extraValues.split(SEPARATOR_FOR_COMMA_CONCATENATED_TEXT);
final String[] elements = extraValues.split(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT);
if (!containsInArray(text, elements)) {
return extraValues;
}
@ -78,7 +83,7 @@ public final class StringUtils {
result.add(element);
}
}
return TextUtils.join(SEPARATOR_FOR_COMMA_CONCATENATED_TEXT, result);
return TextUtils.join(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT, result);
}
/**

View File

@ -41,60 +41,60 @@ public class StringUtilsTests extends AndroidTestCase {
}
public void testContainsInExtraValues() {
assertFalse("null", StringUtils.containsInCommaConcatenatedText("key", null));
assertFalse("empty", StringUtils.containsInCommaConcatenatedText("key", ""));
assertFalse("null", StringUtils.containsInCommaSplittableText("key", null));
assertFalse("empty", StringUtils.containsInCommaSplittableText("key", ""));
assertFalse("not in 1 element",
StringUtils.containsInCommaConcatenatedText("key", "key1"));
StringUtils.containsInCommaSplittableText("key", "key1"));
assertFalse("not in 2 elements",
StringUtils.containsInCommaConcatenatedText("key", "key1,key2"));
StringUtils.containsInCommaSplittableText("key", "key1,key2"));
assertTrue("in 1 element", StringUtils.containsInCommaConcatenatedText("key", "key"));
assertTrue("in 2 elements", StringUtils.containsInCommaConcatenatedText("key", "key1,key"));
assertTrue("in 1 element", StringUtils.containsInCommaSplittableText("key", "key"));
assertTrue("in 2 elements", StringUtils.containsInCommaSplittableText("key", "key1,key"));
}
public void testAppendToExtraValuesIfNotExists() {
assertEquals("null", "key",
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", null));
StringUtils.appendToCommaSplittableTextIfNotExists("key", null));
assertEquals("empty", "key",
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", ""));
StringUtils.appendToCommaSplittableTextIfNotExists("key", ""));
assertEquals("not in 1 element", "key1,key",
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key1"));
StringUtils.appendToCommaSplittableTextIfNotExists("key", "key1"));
assertEquals("not in 2 elements", "key1,key2,key",
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key1,key2"));
StringUtils.appendToCommaSplittableTextIfNotExists("key", "key1,key2"));
assertEquals("in 1 element", "key",
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key"));
StringUtils.appendToCommaSplittableTextIfNotExists("key", "key"));
assertEquals("in 2 elements at position 1", "key,key2",
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key,key2"));
StringUtils.appendToCommaSplittableTextIfNotExists("key", "key,key2"));
assertEquals("in 2 elements at position 2", "key1,key",
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key1,key"));
StringUtils.appendToCommaSplittableTextIfNotExists("key", "key1,key"));
assertEquals("in 3 elements at position 2", "key1,key,key3",
StringUtils.appendToCommaConcatenatedTextIfNotExists("key", "key1,key,key3"));
StringUtils.appendToCommaSplittableTextIfNotExists("key", "key1,key,key3"));
}
public void testRemoveFromExtraValuesIfExists() {
assertEquals("null", "", StringUtils.removeFromCommaConcatenatedTextIfExists("key", null));
assertEquals("empty", "", StringUtils.removeFromCommaConcatenatedTextIfExists("key", ""));
assertEquals("null", "", StringUtils.removeFromCommaSplittableTextIfExists("key", null));
assertEquals("empty", "", StringUtils.removeFromCommaSplittableTextIfExists("key", ""));
assertEquals("not in 1 element", "key1",
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key1"));
StringUtils.removeFromCommaSplittableTextIfExists("key", "key1"));
assertEquals("not in 2 elements", "key1,key2",
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key1,key2"));
StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key2"));
assertEquals("in 1 element", "",
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key"));
StringUtils.removeFromCommaSplittableTextIfExists("key", "key"));
assertEquals("in 2 elements at position 1", "key2",
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key,key2"));
StringUtils.removeFromCommaSplittableTextIfExists("key", "key,key2"));
assertEquals("in 2 elements at position 2", "key1",
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key1,key"));
StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key"));
assertEquals("in 3 elements at position 2", "key1,key3",
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key1,key,key3"));
StringUtils.removeFromCommaSplittableTextIfExists("key", "key1,key,key3"));
assertEquals("in 3 elements at position 1,2,3", "",
StringUtils.removeFromCommaConcatenatedTextIfExists("key", "key,key,key"));
StringUtils.removeFromCommaSplittableTextIfExists("key", "key,key,key"));
assertEquals("in 5 elements at position 2,4", "key1,key3,key5",
StringUtils.removeFromCommaConcatenatedTextIfExists(
StringUtils.removeFromCommaSplittableTextIfExists(
"key", "key1,key,key3,key,key5"));
}