diff options
author | 2012-07-20 12:01:33 +0900 | |
---|---|---|
committer | 2012-07-20 12:02:38 +0900 | |
commit | c49c85f835ecd14d09abb6d88c85a3303c566741 (patch) | |
tree | 07d593d4895c754ffdf23407d89aa33f4be85e16 /java | |
parent | 721fd573f0f375b745df6b785bd31ae087da0f57 (diff) | |
download | latinime-c49c85f835ecd14d09abb6d88c85a3303c566741.tar.gz latinime-c49c85f835ecd14d09abb6d88c85a3303c566741.tar.xz latinime-c49c85f835ecd14d09abb6d88c85a3303c566741.zip |
Implement ResizableIntArray.setLength and .get
This change revises ResizableIntArrayTests as well.
Diffstat (limited to 'java')
-rw-r--r-- | java/proguard.flags | 4 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/ResizableIntArray.java | 28 |
2 files changed, 23 insertions, 9 deletions
diff --git a/java/proguard.flags b/java/proguard.flags index 163352287..1711b99df 100644 --- a/java/proguard.flags +++ b/java/proguard.flags @@ -24,6 +24,10 @@ *; } +-keep class com.android.inputmethod.latin.ResizableIntArray { + *; +} + -keep class com.android.inputmethod.latin.spellcheck.SpellCheckerSettingsFragment { *; } diff --git a/java/src/com/android/inputmethod/latin/ResizableIntArray.java b/java/src/com/android/inputmethod/latin/ResizableIntArray.java index 2079c0e99..6feae9c5a 100644 --- a/java/src/com/android/inputmethod/latin/ResizableIntArray.java +++ b/java/src/com/android/inputmethod/latin/ResizableIntArray.java @@ -23,11 +23,18 @@ public class ResizableIntArray { private int[] mArray; private int mLength; - public ResizableIntArray(int capacity) { + public ResizableIntArray(final int capacity) { reset(capacity); } - public void add(int index, int val) { + public int get(final int index) { + if (index < 0 || index >= mLength) { + throw new ArrayIndexOutOfBoundsException("length=" + mLength + "; index=" + index); + } + return mArray[index]; + } + + public void add(final int index, final int val) { if (mLength < index + 1) { mLength = index; add(val); @@ -36,14 +43,14 @@ public class ResizableIntArray { } } - public void add(int val) { + public void add(final int val) { final int nextLength = mLength + 1; ensureCapacity(nextLength); mArray[mLength] = val; mLength = nextLength; } - private void ensureCapacity(int minimumCapacity) { + private void ensureCapacity(final int minimumCapacity) { if (mArray.length < minimumCapacity) { final int nextCapacity = mArray.length * 2; // The following is the same as newLength = @@ -60,9 +67,12 @@ public class ResizableIntArray { return mLength; } - // TODO: Implement setLength(int). + public void setLength(final int newLength) { + ensureCapacity(newLength); + mLength = newLength; + } - public void reset(int capacity) { + public void reset(final int capacity) { // TODO: Implement primitive array pool. mArray = new int[capacity]; mLength = 0; @@ -72,20 +82,20 @@ public class ResizableIntArray { return mArray; } - public void set(ResizableIntArray ip) { + public void set(final ResizableIntArray ip) { // TODO: Implement primitive array pool. mArray = ip.mArray; mLength = ip.mLength; } - public void copy(ResizableIntArray ip) { + public void copy(final ResizableIntArray ip) { // TODO: Avoid useless coping of values. ensureCapacity(ip.mLength); System.arraycopy(ip.mArray, 0, mArray, 0, ip.mLength); mLength = ip.mLength; } - public void append(ResizableIntArray src, int startPos, int length) { + public void append(final ResizableIntArray src, final int startPos, final int length) { final int currentLength = mLength; final int newLength = currentLength + length; ensureCapacity(newLength); |