am 7ab112ef
: Merge "Add null analysis annotations to latinime-common"
* commit '7ab112ef4acf5a225fbb18f75698868168234297': Add null analysis annotations to latinime-common
This commit is contained in:
commit
87b33bda77
5 changed files with 50 additions and 19 deletions
|
@ -20,6 +20,8 @@ import com.android.inputmethod.annotations.UsedForTesting;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
// Utility methods related with code points used for tests.
|
||||
// TODO: Figure out where this class should be.
|
||||
@UsedForTesting
|
||||
|
@ -65,17 +67,23 @@ public class CodePointUtils {
|
|||
};
|
||||
|
||||
@UsedForTesting
|
||||
public static int[] generateCodePointSet(final int codePointSetSize, final Random random) {
|
||||
@Nonnull
|
||||
public static int[] generateCodePointSet(final int codePointSetSize,
|
||||
@Nonnull final Random random) {
|
||||
final int[] codePointSet = new int[codePointSetSize];
|
||||
for (int i = codePointSet.length - 1; i >= 0; ) {
|
||||
final int r = Math.abs(random.nextInt());
|
||||
if (r < 0) continue;
|
||||
if (r < 0) {
|
||||
continue;
|
||||
}
|
||||
// Don't insert 0~0x20, but insert any other code point.
|
||||
// Code points are in the range 0~0x10FFFF.
|
||||
final int candidateCodePoint = 0x20 + r % (Character.MAX_CODE_POINT - 0x20);
|
||||
// Code points between MIN_ and MAX_SURROGATE are not valid on their own.
|
||||
if (candidateCodePoint >= Character.MIN_SURROGATE
|
||||
&& candidateCodePoint <= Character.MAX_SURROGATE) continue;
|
||||
&& candidateCodePoint <= Character.MAX_SURROGATE) {
|
||||
continue;
|
||||
}
|
||||
codePointSet[i] = candidateCodePoint;
|
||||
--i;
|
||||
}
|
||||
|
@ -86,8 +94,10 @@ public class CodePointUtils {
|
|||
* Generates a random word.
|
||||
*/
|
||||
@UsedForTesting
|
||||
public static String generateWord(final Random random, final int[] codePointSet) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
@Nonnull
|
||||
public static String generateWord(@Nonnull final Random random,
|
||||
@Nonnull final int[] codePointSet) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
// 8 * 4 = 32 chars max, but we do it the following way so as to bias the random toward
|
||||
// longer words. This should be closer to natural language, and more importantly, it will
|
||||
// exercise the algorithms in dicttool much more.
|
||||
|
|
|
@ -16,15 +16,20 @@
|
|||
|
||||
package com.android.inputmethod.latin.common;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* An immutable class that encapsulates a snapshot of word composition data.
|
||||
*/
|
||||
public class ComposedData {
|
||||
@Nonnull
|
||||
public final InputPointers mInputPointers;
|
||||
public final boolean mIsBatchMode;
|
||||
@Nonnull
|
||||
public final String mTypedWord;
|
||||
public ComposedData(final InputPointers inputPointers, final boolean isBatchMode,
|
||||
final String typedWord) {
|
||||
|
||||
public ComposedData(@Nonnull final InputPointers inputPointers, final boolean isBatchMode,
|
||||
@Nonnull final String typedWord) {
|
||||
mInputPointers = inputPointers;
|
||||
mIsBatchMode = isBatchMode;
|
||||
mTypedWord = typedWord;
|
||||
|
@ -40,7 +45,7 @@ public class ComposedData {
|
|||
* @return the number of copied code points.
|
||||
*/
|
||||
public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(
|
||||
final int[] destination) {
|
||||
@Nonnull final int[] destination) {
|
||||
// lastIndex is exclusive
|
||||
final int lastIndex = mTypedWord.length()
|
||||
- StringUtils.getTrailingSingleQuotesCount(mTypedWord);
|
||||
|
|
|
@ -18,6 +18,8 @@ package com.android.inputmethod.latin.common;
|
|||
|
||||
import com.android.inputmethod.annotations.UsedForTesting;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class Constants {
|
||||
public static final class Color {
|
||||
/**
|
||||
|
@ -259,6 +261,7 @@ public final class Constants {
|
|||
return code >= CODE_SPACE;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String printableCode(final int code) {
|
||||
switch (code) {
|
||||
case CODE_SHIFT: return "shift";
|
||||
|
@ -286,7 +289,8 @@ public final class Constants {
|
|||
}
|
||||
}
|
||||
|
||||
public static String printableCodes(final int[] codes) {
|
||||
@Nonnull
|
||||
public static String printableCodes(@Nonnull final int[] codes) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
boolean addDelimiter = false;
|
||||
for (final int code : codes) {
|
||||
|
|
|
@ -18,6 +18,8 @@ package com.android.inputmethod.latin.common;
|
|||
|
||||
import com.android.inputmethod.annotations.UsedForTesting;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
// TODO: This class is not thread-safe.
|
||||
public final class InputPointers {
|
||||
private static final boolean DEBUG_TIME = false;
|
||||
|
@ -28,7 +30,7 @@ public final class InputPointers {
|
|||
private final ResizableIntArray mPointerIds;
|
||||
private final ResizableIntArray mTimes;
|
||||
|
||||
public InputPointers(int defaultCapacity) {
|
||||
public InputPointers(final int defaultCapacity) {
|
||||
mDefaultCapacity = defaultCapacity;
|
||||
mXCoordinates = new ResizableIntArray(defaultCapacity);
|
||||
mYCoordinates = new ResizableIntArray(defaultCapacity);
|
||||
|
@ -51,7 +53,8 @@ public final class InputPointers {
|
|||
mTimes.fill(lastTime, fromIndex, fillLength);
|
||||
}
|
||||
|
||||
public void addPointerAt(int index, int x, int y, int pointerId, int time) {
|
||||
public void addPointerAt(final int index, final int x, final int y, final int pointerId,
|
||||
final int time) {
|
||||
mXCoordinates.addAt(index, x);
|
||||
mYCoordinates.addAt(index, y);
|
||||
mPointerIds.addAt(index, pointerId);
|
||||
|
@ -62,21 +65,21 @@ public final class InputPointers {
|
|||
}
|
||||
|
||||
@UsedForTesting
|
||||
public void addPointer(int x, int y, int pointerId, int time) {
|
||||
public void addPointer(final int x, final int y, final int pointerId, final int time) {
|
||||
mXCoordinates.add(x);
|
||||
mYCoordinates.add(y);
|
||||
mPointerIds.add(pointerId);
|
||||
mTimes.add(time);
|
||||
}
|
||||
|
||||
public void set(InputPointers ip) {
|
||||
public void set(@Nonnull final InputPointers ip) {
|
||||
mXCoordinates.set(ip.mXCoordinates);
|
||||
mYCoordinates.set(ip.mYCoordinates);
|
||||
mPointerIds.set(ip.mPointerIds);
|
||||
mTimes.set(ip.mTimes);
|
||||
}
|
||||
|
||||
public void copy(InputPointers ip) {
|
||||
public void copy(@Nonnull final InputPointers ip) {
|
||||
mXCoordinates.copy(ip.mXCoordinates);
|
||||
mYCoordinates.copy(ip.mYCoordinates);
|
||||
mPointerIds.copy(ip.mPointerIds);
|
||||
|
@ -93,8 +96,9 @@ public final class InputPointers {
|
|||
* @param startPos the starting index of the data in {@code times} and etc.
|
||||
* @param length the number of data to be appended.
|
||||
*/
|
||||
public void append(int pointerId, ResizableIntArray times, ResizableIntArray xCoordinates,
|
||||
ResizableIntArray yCoordinates, int startPos, int length) {
|
||||
public void append(final int pointerId, @Nonnull final ResizableIntArray times,
|
||||
@Nonnull final ResizableIntArray xCoordinates,
|
||||
@Nonnull final ResizableIntArray yCoordinates, final int startPos, final int length) {
|
||||
if (length == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -127,14 +131,17 @@ public final class InputPointers {
|
|||
return mXCoordinates.getLength();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public int[] getXCoordinates() {
|
||||
return mXCoordinates.getPrimitiveArray();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public int[] getYCoordinates() {
|
||||
return mYCoordinates.getPrimitiveArray();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public int[] getPointerIds() {
|
||||
return mPointerIds.getPrimitiveArray();
|
||||
}
|
||||
|
@ -145,6 +152,7 @@ public final class InputPointers {
|
|||
* @return The time each point was registered, in milliseconds, relative to the first event in
|
||||
* the sequence.
|
||||
*/
|
||||
@Nonnull
|
||||
public int[] getTimes() {
|
||||
return mTimes.getPrimitiveArray();
|
||||
}
|
||||
|
|
|
@ -18,8 +18,11 @@ package com.android.inputmethod.latin.common;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
// TODO: This class is not thread-safe.
|
||||
public final class ResizableIntArray {
|
||||
@Nonnull
|
||||
private int[] mArray;
|
||||
private int mLength;
|
||||
|
||||
|
@ -89,17 +92,18 @@ public final class ResizableIntArray {
|
|||
mLength = 0;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public int[] getPrimitiveArray() {
|
||||
return mArray;
|
||||
}
|
||||
|
||||
public void set(final ResizableIntArray ip) {
|
||||
public void set(@Nonnull final ResizableIntArray ip) {
|
||||
// TODO: Implement primitive array pool.
|
||||
mArray = ip.mArray;
|
||||
mLength = ip.mLength;
|
||||
}
|
||||
|
||||
public void copy(final ResizableIntArray ip) {
|
||||
public void copy(@Nonnull final ResizableIntArray ip) {
|
||||
final int newCapacity = calculateCapacity(ip.mLength);
|
||||
if (newCapacity > 0) {
|
||||
// TODO: Implement primitive array pool.
|
||||
|
@ -109,7 +113,7 @@ public final class ResizableIntArray {
|
|||
mLength = ip.mLength;
|
||||
}
|
||||
|
||||
public void append(final ResizableIntArray src, final int startPos, final int length) {
|
||||
public void append(@Nonnull final ResizableIntArray src, final int startPos, final int length) {
|
||||
if (length == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue