From d245f6c9e2ba1d2cee64a0ecf886907e94aa4b3f Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 31 Jan 2014 15:26:05 +0900 Subject: [PATCH] Move arrayAsList method to CollectionUtils Change-Id: If7c1eb7c802490f19c5d3b81d714362408daf376 --- .../keyboard/internal/KeySpecParser.java | 23 ++++--------------- .../latin/utils/CollectionUtils.java | 15 ++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index e9e2f4254..5c288c8e7 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -265,21 +265,6 @@ public final class KeySpecParser { return KeyboardIconsSet.ICON_UNDEFINED; } - private static ArrayList arrayAsList(final T[] array, final int start, final int end) { - if (array == null) { - throw new NullPointerException(); - } - if (start < 0 || start > end || end > array.length) { - throw new IllegalArgumentException(); - } - - final ArrayList list = CollectionUtils.newArrayList(end - start); - for (int i = start; i < end; i++) { - list.add(array[i]); - } - return list; - } - private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static String[] filterOutEmptyString(final String[] array) { @@ -291,7 +276,7 @@ public final class KeySpecParser { final String entry = array[i]; if (TextUtils.isEmpty(entry)) { if (out == null) { - out = arrayAsList(array, 0, i); + out = CollectionUtils.arrayAsList(array, 0, i); } } else if (out != null) { out.add(entry); @@ -326,7 +311,7 @@ public final class KeySpecParser { } else { // Filter out excessive '%' marker. if (out == null) { - out = arrayAsList(moreKeys, 0, moreKeyIndex); + out = CollectionUtils.arrayAsList(moreKeys, 0, moreKeyIndex); } } } else { @@ -343,7 +328,7 @@ public final class KeySpecParser { + " moreKeys=" + Arrays.toString(moreKeys) + " additionalMoreKeys=" + Arrays.toString(additionalMoreKeys)); } - out = arrayAsList(additionalMoreKeys, additionalIndex, additionalCount); + out = CollectionUtils.arrayAsList(additionalMoreKeys, additionalIndex, additionalCount); for (int i = 0; i < moreKeysCount; i++) { out.add(moreKeys[i]); } @@ -355,7 +340,7 @@ public final class KeySpecParser { + " moreKeys=" + Arrays.toString(moreKeys) + " additionalMoreKeys=" + Arrays.toString(additionalMoreKeys)); } - out = arrayAsList(moreKeys, 0, moreKeysCount); + out = CollectionUtils.arrayAsList(moreKeys, 0, moreKeysCount); for (int i = additionalIndex; i < additionalCount; i++) { out.add(additionalMoreKeys[additionalIndex]); } diff --git a/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java b/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java index cc25102ce..bbfa0f091 100644 --- a/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/CollectionUtils.java @@ -102,4 +102,19 @@ public final class CollectionUtils { public static SparseArray newSparseArray() { return new SparseArray(); } + + public static ArrayList arrayAsList(final E[] array, final int start, final int end) { + if (array == null) { + throw new NullPointerException(); + } + if (start < 0 || start > end || end > array.length) { + throw new IllegalArgumentException(); + } + + final ArrayList list = newArrayList(end - start); + for (int i = start; i < end; i++) { + list.add(array[i]); + } + return list; + } }