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