No need to specify dimensions for AbstractKeyboardBuilder
Bug: 13017434
Change-Id: I1cce6d9f072dff8ce2a53b8089f09105ba812a2b
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java b/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java
index f17c59d..4070837 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/Qwerty.java
@@ -35,7 +35,7 @@
@Override
ExpectedKey[][] getCommonAlphabetLayout(final boolean isPhone) { return ALPHABET_COMMON; }
- private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder(10, 9, 7, 3)
+ private static final ExpectedKey[][] ALPHABET_COMMON = new ExpectedKeyboardBuilder()
.setLabelsOfRow(1, "q", "w", "e", "r", "t", "y", "u", "i", "o", "p")
.setMoreKeysOf("q", "1")
.setMoreKeysOf("w", "2")
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java b/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java
index 3edf041..127d81a 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/Symbols.java
@@ -114,7 +114,7 @@
public static ExpectedKey[] SINGLE_ANGLE_QUOTES_RL = { SAQUOTE_RIGHT, SAQUOTE_LEFT };
// Common symbols keyboard layout.
- private static final ExpectedKey[][] SYMBOLS_COMMON = new ExpectedKeyboardBuilder(10, 9, 7, 5)
+ private static final ExpectedKey[][] SYMBOLS_COMMON = new ExpectedKeyboardBuilder()
.setKeysOfRow(1,
// U+00B9: "¹" SUPERSCRIPT ONE
// U+00BD: "½" VULGAR FRACTION ONE HALF
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java b/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java
index 2403f0f..7cbd2fb 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/SymbolsShifted.java
@@ -70,8 +70,7 @@
};
// Common symbols shifted keyboard layout.
- private static final ExpectedKey[][] SYMBOLS_SHIFTED_COMMON = new ExpectedKeyboardBuilder(
- 10, 1 /* other_currencies */+ 5, 7, 5)
+ private static final ExpectedKey[][] SYMBOLS_SHIFTED_COMMON = new ExpectedKeyboardBuilder()
.setKeysOfRow(1,
key("~"),
// U+0060: "`" GRAVE ACCENT
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java
index 682ac20..3365b92 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/AbstractKeyboardBuilder.java
@@ -29,7 +29,7 @@
*/
abstract class AbstractKeyboardBuilder<E> {
// A building array of rows.
- private final E[][] mRows;
+ private E[][] mRows;
// Returns an instance of default element.
abstract E defaultElement();
@@ -42,12 +42,8 @@
* Construct a builder filled with the default element.
* @param dimensions the integer array of each row's size.
*/
- AbstractKeyboardBuilder(final int ... dimensions) {
- mRows = newArrayOfArray(dimensions.length);
- for (int rowIndex = 0; rowIndex < dimensions.length; rowIndex++) {
- mRows[rowIndex] = newArray(dimensions[rowIndex]);
- Arrays.fill(mRows[rowIndex], defaultElement());
- }
+ AbstractKeyboardBuilder() {
+ mRows = newArrayOfArray(0);
}
/**
@@ -102,10 +98,13 @@
*/
void setRowAt(final int row, final E[] elements) {
final int rowIndex = row - 1;
- if (rowIndex < 0 || rowIndex >= mRows.length) {
+ if (rowIndex < 0) {
throw new RuntimeException("Illegal row number: " + row);
}
- mRows[rowIndex] = elements;
+ final E[][] newRows = (rowIndex < mRows.length) ? mRows
+ : Arrays.copyOf(mRows, rowIndex + 1);
+ newRows[rowIndex] = elements;
+ mRows = newRows;
}
/**
@@ -120,8 +119,11 @@
void setElementAt(final int row, final int column, final E element, final boolean insert) {
final E[] elements = getRowAt(row);
final int columnIndex = column - 1;
+ if (columnIndex < 0) {
+ throw new RuntimeException("Illegal column number: " + column);
+ }
if (insert) {
- if (columnIndex < 0 || columnIndex >= elements.length + 1) {
+ if (columnIndex >= elements.length + 1) {
throw new RuntimeException("Illegal column number: " + column);
}
final E[] newElements = Arrays.copyOf(elements, elements.length + 1);
@@ -134,9 +136,9 @@
setRowAt(row, newElements);
return;
}
- if (columnIndex < 0 || columnIndex >= elements.length) {
- throw new RuntimeException("Illegal column number: " + column);
- }
- elements[columnIndex] = element;
+ final E[] newElements = (columnIndex < elements.length) ? elements
+ : Arrays.copyOf(elements, columnIndex + 1);
+ newElements[columnIndex] = element;
+ setRowAt(row, newElements);
}
}
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
index 577f43e..050bc4c 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ActualKeyboardBuilder.java
@@ -85,7 +85,7 @@
for (int rowIndex = 0; rowIndex < dimensions.length; rowIndex++) {
dimensions[rowIndex] = rows.get(rowIndex).size();
}
- final ActualKeyboardBuilder builder = new ActualKeyboardBuilder(dimensions);
+ final ActualKeyboardBuilder builder = new ActualKeyboardBuilder();
for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
final int row = rowIndex + 1;
@@ -95,10 +95,6 @@
return builder.build();
}
- private ActualKeyboardBuilder(final int ... dimensions) {
- super(dimensions);
- }
-
@Override
Key defaultElement() { return null; }
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
index 795bcb2..176e0eb 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/expected/ExpectedKeyboardBuilder.java
@@ -23,8 +23,8 @@
* This class builds an expected keyboard for unit test.
*/
public final class ExpectedKeyboardBuilder extends AbstractKeyboardBuilder<ExpectedKey> {
- public ExpectedKeyboardBuilder(final int ... dimensions) {
- super(dimensions);
+ public ExpectedKeyboardBuilder() {
+ super();
}
public ExpectedKeyboardBuilder(final ExpectedKey[][] rows) {