ArrayUtils: rename concatElements() to concat() am: 96abd9452d
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2429552 Change-Id: I40242554249df84807bbd0ff54732d7701b4b6be Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -349,7 +349,7 @@ public class ArrayUtils {
|
|||||||
* @return A single array containing all the elements of the parameter arrays.
|
* @return A single array containing all the elements of the parameter arrays.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static @NonNull <T> T[] concatElements(Class<T> kind, @Nullable T[]... arrays) {
|
public static @NonNull <T> T[] concat(Class<T> kind, @Nullable T[]... arrays) {
|
||||||
if (arrays == null || arrays.length == 0) {
|
if (arrays == null || arrays.length == 0) {
|
||||||
return createEmptyArray(kind);
|
return createEmptyArray(kind);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.internal.util;
|
package com.android.internal.util;
|
||||||
|
|
||||||
import static com.android.internal.util.ArrayUtils.concatElements;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@@ -156,61 +154,57 @@ public class ArrayUtilsTest extends TestCase {
|
|||||||
ArrayUtils.removeLong(new long[] { 1, 2, 3, 1 }, 1));
|
ArrayUtils.removeLong(new long[] { 1, 2, 3, 1 }, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConcatEmpty() throws Exception {
|
public void testConcat_zeroObjectArrays() {
|
||||||
assertArrayEquals(new Long[] {},
|
// empty varargs array
|
||||||
concatElements(Long.class, null, null));
|
assertArrayEquals(new String[] {}, ArrayUtils.concat(String.class));
|
||||||
assertArrayEquals(new Long[] {},
|
// null varargs array
|
||||||
concatElements(Long.class, new Long[] {}, null));
|
assertArrayEquals(new String[] {}, ArrayUtils.concat(String.class, (String[][]) null));
|
||||||
assertArrayEquals(new Long[] {},
|
|
||||||
concatElements(Long.class, null, new Long[] {}));
|
|
||||||
assertArrayEquals(new Long[] {},
|
|
||||||
concatElements(Long.class, new Long[] {}, new Long[] {}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testconcatElements() throws Exception {
|
public void testConcat_oneObjectArray() {
|
||||||
|
assertArrayEquals(new String[] { "1", "2" },
|
||||||
|
ArrayUtils.concat(String.class, new String[] { "1", "2" }));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testConcat_oneEmptyObjectArray() {
|
||||||
|
assertArrayEquals(new String[] {}, ArrayUtils.concat(String.class, (String[]) null));
|
||||||
|
assertArrayEquals(new String[] {}, ArrayUtils.concat(String.class, new String[] {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testConcat_twoObjectArrays() {
|
||||||
assertArrayEquals(new Long[] { 1L },
|
assertArrayEquals(new Long[] { 1L },
|
||||||
concatElements(Long.class, new Long[] { 1L }, new Long[] {}));
|
ArrayUtils.concat(Long.class, new Long[] { 1L }, new Long[] {}));
|
||||||
assertArrayEquals(new Long[] { 1L },
|
assertArrayEquals(new Long[] { 1L },
|
||||||
concatElements(Long.class, new Long[] {}, new Long[] { 1L }));
|
ArrayUtils.concat(Long.class, new Long[] {}, new Long[] { 1L }));
|
||||||
assertArrayEquals(new Long[] { 1L, 2L },
|
assertArrayEquals(new Long[] { 1L, 2L },
|
||||||
concatElements(Long.class, new Long[] { 1L }, new Long[] { 2L }));
|
ArrayUtils.concat(Long.class, new Long[] { 1L }, new Long[] { 2L }));
|
||||||
assertArrayEquals(new Long[] { 1L, 2L, 3L, 4L },
|
assertArrayEquals(new Long[] { 1L, 2L, 3L, 4L },
|
||||||
concatElements(Long.class, new Long[] { 1L, 2L }, new Long[] { 3L, 4L }));
|
ArrayUtils.concat(Long.class, new Long[] { 1L, 2L }, new Long[] { 3L, 4L }));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConcatElements_threeWay() {
|
public void testConcat_twoEmptyObjectArrays() {
|
||||||
|
assertArrayEquals(new Long[] {}, ArrayUtils.concat(Long.class, null, null));
|
||||||
|
assertArrayEquals(new Long[] {}, ArrayUtils.concat(Long.class, new Long[] {}, null));
|
||||||
|
assertArrayEquals(new Long[] {}, ArrayUtils.concat(Long.class, null, new Long[] {}));
|
||||||
|
assertArrayEquals(new Long[] {},
|
||||||
|
ArrayUtils.concat(Long.class, new Long[] {}, new Long[] {}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testConcat_threeObjectArrays() {
|
||||||
String[] array1 = { "1", "2" };
|
String[] array1 = { "1", "2" };
|
||||||
String[] array2 = { "3", "4" };
|
String[] array2 = { "3", "4" };
|
||||||
String[] array3 = { "5", "6" };
|
String[] array3 = { "5", "6" };
|
||||||
String[] expectation = { "1", "2", "3", "4", "5", "6" };
|
String[] expectation = { "1", "2", "3", "4", "5", "6" };
|
||||||
|
|
||||||
String[] concatResult = ArrayUtils.concatElements(String.class, array1, array2, array3);
|
assertArrayEquals(expectation, ArrayUtils.concat(String.class, array1, array2, array3));
|
||||||
assertArrayEquals(expectation, concatResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testConcat_threeObjectArraysWithNull() {
|
||||||
public void testConcatElements_threeWayWithNull() {
|
|
||||||
String[] array1 = { "1", "2" };
|
String[] array1 = { "1", "2" };
|
||||||
String[] array2 = null;
|
String[] array2 = null;
|
||||||
String[] array3 = { "5", "6" };
|
String[] array3 = { "5", "6" };
|
||||||
String[] expectation = { "1", "2", "5", "6" };
|
String[] expectation = { "1", "2", "5", "6" };
|
||||||
|
|
||||||
String[] concatResult = ArrayUtils.concatElements(String.class, array1, array2, array3);
|
assertArrayEquals(expectation, ArrayUtils.concat(String.class, array1, array2, array3));
|
||||||
assertArrayEquals(expectation, concatResult);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConcatElements_zeroElements() {
|
|
||||||
String[] expectation = new String[0];
|
|
||||||
|
|
||||||
String[] concatResult = ArrayUtils.concatElements(String.class);
|
|
||||||
assertArrayEquals(expectation, concatResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testConcatElements_oneNullElement() {
|
|
||||||
String[] expectation = new String[0];
|
|
||||||
|
|
||||||
String[] concatResult = ArrayUtils.concatElements(String.class, null);
|
|
||||||
assertArrayEquals(expectation, concatResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -875,16 +875,16 @@ public class SettingsBackupAgent extends BackupAgentHelper {
|
|||||||
String[] whitelist;
|
String[] whitelist;
|
||||||
Map<String, Validator> validators = null;
|
Map<String, Validator> validators = null;
|
||||||
if (contentUri.equals(Settings.Secure.CONTENT_URI)) {
|
if (contentUri.equals(Settings.Secure.CONTENT_URI)) {
|
||||||
whitelist = ArrayUtils.concatElements(String.class, SecureSettings.SETTINGS_TO_BACKUP,
|
whitelist = ArrayUtils.concat(String.class, SecureSettings.SETTINGS_TO_BACKUP,
|
||||||
Settings.Secure.LEGACY_RESTORE_SETTINGS,
|
Settings.Secure.LEGACY_RESTORE_SETTINGS,
|
||||||
DeviceSpecificSettings.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
|
DeviceSpecificSettings.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
|
||||||
validators = SecureSettingsValidators.VALIDATORS;
|
validators = SecureSettingsValidators.VALIDATORS;
|
||||||
} else if (contentUri.equals(Settings.System.CONTENT_URI)) {
|
} else if (contentUri.equals(Settings.System.CONTENT_URI)) {
|
||||||
whitelist = ArrayUtils.concatElements(String.class, SystemSettings.SETTINGS_TO_BACKUP,
|
whitelist = ArrayUtils.concat(String.class, SystemSettings.SETTINGS_TO_BACKUP,
|
||||||
Settings.System.LEGACY_RESTORE_SETTINGS);
|
Settings.System.LEGACY_RESTORE_SETTINGS);
|
||||||
validators = SystemSettingsValidators.VALIDATORS;
|
validators = SystemSettingsValidators.VALIDATORS;
|
||||||
} else if (contentUri.equals(Settings.Global.CONTENT_URI)) {
|
} else if (contentUri.equals(Settings.Global.CONTENT_URI)) {
|
||||||
whitelist = ArrayUtils.concatElements(String.class, GlobalSettings.SETTINGS_TO_BACKUP,
|
whitelist = ArrayUtils.concat(String.class, GlobalSettings.SETTINGS_TO_BACKUP,
|
||||||
Settings.Global.LEGACY_RESTORE_SETTINGS);
|
Settings.Global.LEGACY_RESTORE_SETTINGS);
|
||||||
validators = GlobalSettingsValidators.VALIDATORS;
|
validators = GlobalSettingsValidators.VALIDATORS;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user