Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LatinIME
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
keyboard
LatinIME
Commits
7247bff6
Commit
7247bff6
authored
12 years ago
by
Tadashi G. Takaoka
Browse files
Options
Downloads
Patches
Plain Diff
Fix InputPointers.append
Change-Id: I6995f9b2ed00b9f948e1299e576a5e24725d58f8
parent
fa2287f8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
java/src/com/android/inputmethod/latin/InputPointers.java
+25
-22
25 additions, 22 deletions
java/src/com/android/inputmethod/latin/InputPointers.java
tests/src/com/android/inputmethod/latin/InputPointersTests.java
+34
-31
34 additions, 31 deletions
...src/com/android/inputmethod/latin/InputPointersTests.java
with
59 additions
and
53 deletions
java/src/com/android/inputmethod/latin/InputPointers.java
+
25
−
22
View file @
7247bff6
...
...
@@ -16,6 +16,9 @@
package
com.android.inputmethod.latin
;
import
java.util.Arrays
;
// TODO: This class is not thread-safe.
public
class
InputPointers
{
private
final
ScalableIntArray
mXCoordinates
=
new
ScalableIntArray
();
private
final
ScalableIntArray
mYCoordinates
=
new
ScalableIntArray
();
...
...
@@ -52,21 +55,15 @@ public class InputPointers {
/**
* Append the pointers in the specified {@link InputPointers} to the end of this.
* @param src the source {@link InputPointers} to
appen
d the
pointers
.
* @param src the source {@link InputPointers} to
rea
d the
data from
.
* @param startPos the starting index of the pointers in {@code src}.
* @param length the number of pointers to be appended.
*/
public
void
append
(
InputPointers
src
,
int
startPos
,
int
length
)
{
final
int
currentLength
=
getPointerSize
();
final
int
newLength
=
currentLength
+
length
;
mXCoordinates
.
ensureCapacity
(
newLength
);
mYCoordinates
.
ensureCapacity
(
newLength
);
mPointerIds
.
ensureCapacity
(
newLength
);
mTimes
.
ensureCapacity
(
newLength
);
System
.
arraycopy
(
src
.
getXCoordinates
(),
startPos
,
getXCoordinates
(),
currentLength
,
length
);
System
.
arraycopy
(
src
.
getYCoordinates
(),
startPos
,
getYCoordinates
(),
currentLength
,
length
);
System
.
arraycopy
(
src
.
getPointerIds
(),
startPos
,
getPointerIds
(),
currentLength
,
length
);
System
.
arraycopy
(
src
.
getTimes
(),
startPos
,
getTimes
(),
currentLength
,
length
);
mXCoordinates
.
append
(
src
.
mXCoordinates
,
startPos
,
length
);
mYCoordinates
.
append
(
src
.
mYCoordinates
,
startPos
,
length
);
mPointerIds
.
append
(
src
.
mPointerIds
,
startPos
,
length
);
mTimes
.
append
(
src
.
mTimes
,
startPos
,
length
);
}
public
void
reset
()
{
...
...
@@ -121,19 +118,17 @@ public class InputPointers {
mLength
=
nextLength
;
}
p
ublic
void
ensureCapacity
(
int
minimumCapacity
)
{
p
rivate
void
ensureCapacity
(
int
minimumCapacity
)
{
if
(
mArray
.
length
<
minimumCapacity
)
{
final
int
nextCapacity
=
mArray
.
length
*
2
;
grow
(
minimumCapacity
>
nextCapacity
?
minimumCapacity
:
nextCapacity
);
// The following is the same as newLength = Math.max(minimumCapacity, nextCapacity);
final
int
newLength
=
minimumCapacity
>
nextCapacity
?
minimumCapacity
:
nextCapacity
;
mArray
=
Arrays
.
copyOf
(
mArray
,
newLength
);
}
}
private
void
grow
(
int
newCapacity
)
{
final
int
[]
newArray
=
new
int
[
newCapacity
];
System
.
arraycopy
(
mArray
,
0
,
newArray
,
0
,
mArray
.
length
);
mArray
=
newArray
;
}
public
int
getLength
()
{
return
mLength
;
}
...
...
@@ -147,15 +142,23 @@ public class InputPointers {
return
mArray
;
}
public
void
set
(
ScalableIntArray
ip
)
{
mArray
=
ip
.
mArray
;
mLength
=
ip
.
mLength
;
}
public
void
copy
(
ScalableIntArray
ip
)
{
ensureCapacity
(
ip
.
mLength
);
System
.
arraycopy
(
ip
.
mArray
,
0
,
mArray
,
0
,
ip
.
mLength
);
mLength
=
ip
.
mLength
;
}
public
void
set
(
ScalableIntArray
ip
)
{
mArray
=
ip
.
mArray
;
mLength
=
ip
.
mLength
;
public
void
append
(
ScalableIntArray
src
,
int
startPos
,
int
length
)
{
final
int
currentLength
=
mLength
;
final
int
newLength
=
currentLength
+
length
;
ensureCapacity
(
newLength
);
System
.
arraycopy
(
src
.
mArray
,
startPos
,
mArray
,
currentLength
,
length
);
mLength
=
newLength
;
}
}
}
This diff is collapsed.
Click to expand it.
tests/src/com/android/inputmethod/latin/InputPointersTests.java
+
34
−
31
View file @
7247bff6
...
...
@@ -114,47 +114,50 @@ public class InputPointersTests extends AndroidTestCase {
public
void
testAppend
()
{
final
InputPointers
src
=
new
InputPointers
();
final
int
limit
=
100
;
for
(
int
i
=
0
;
i
<
limit
;
i
++)
{
final
int
srcLen
=
100
;
for
(
int
i
=
0
;
i
<
srcLen
;
i
++)
{
src
.
addPointer
(
i
,
i
*
2
,
i
*
3
,
i
*
4
);
}
final
int
dstLen
=
50
;
final
InputPointers
dst
=
new
InputPointers
();
for
(
int
i
=
0
;
i
<
limit
;
i
++)
{
final
int
value
=
limit
-
i
;
for
(
int
i
=
0
;
i
<
dstLen
;
i
++)
{
final
int
value
=
-
i
-
1
;
dst
.
addPointer
(
value
*
4
,
value
*
3
,
value
*
2
,
value
);
}
final
InputPointers
dstCopy
=
new
InputPointers
();
dstCopy
.
copy
(
dst
);
dst
.
append
(
src
,
0
,
0
);
assertEquals
(
"after append zero size"
,
limit
,
dst
.
getPointerSize
());
assertArrayEquals
(
"af
f
er append zero xCoordinates"
,
dstCopy
.
getXCoordinates
(),
0
,
dst
.
getXCoordinates
(),
0
,
limit
);
assertArrayEquals
(
"af
f
er append zero yCoordinates"
,
dstCopy
.
getYCoordinates
(),
0
,
dst
.
getYCoordinates
(),
0
,
limit
);
assertArrayEquals
(
"af
f
er append zero pointerIds"
,
dstCopy
.
getPointerIds
(),
0
,
dst
.
getPointerIds
(),
0
,
limit
);
assertArrayEquals
(
"af
f
er append zero times"
,
dstCopy
.
getTimes
(),
0
,
dst
.
getTimes
(),
0
,
limit
);
assertEquals
(
"after append zero size"
,
dstLen
,
dst
.
getPointerSize
());
assertArrayEquals
(
"af
t
er append zero xCoordinates"
,
dstCopy
.
getXCoordinates
(),
0
,
dst
.
getXCoordinates
(),
0
,
dstLen
);
assertArrayEquals
(
"af
t
er append zero yCoordinates"
,
dstCopy
.
getYCoordinates
(),
0
,
dst
.
getYCoordinates
(),
0
,
dstLen
);
assertArrayEquals
(
"af
t
er append zero pointerIds"
,
dstCopy
.
getPointerIds
(),
0
,
dst
.
getPointerIds
(),
0
,
dstLen
);
assertArrayEquals
(
"af
t
er append zero times"
,
dstCopy
.
getTimes
(),
0
,
dst
.
getTimes
(),
0
,
dstLen
);
dst
.
append
(
src
,
0
,
src
.
getPointerSize
());
assertEquals
(
"after append size"
,
limit
*
2
,
dst
.
getPointerSize
()
+
src
.
getPointerSize
());
assertArrayEquals
(
"affer append xCoordinates"
,
dstCopy
.
getXCoordinates
(),
0
,
dst
.
getXCoordinates
(),
0
,
limit
);
assertArrayEquals
(
"affer append yCoordinates"
,
dstCopy
.
getYCoordinates
(),
0
,
dst
.
getYCoordinates
(),
0
,
limit
);
assertArrayEquals
(
"affer append pointerIds"
,
dstCopy
.
getPointerIds
(),
0
,
dst
.
getPointerIds
(),
0
,
limit
);
assertArrayEquals
(
"affer append times"
,
dstCopy
.
getTimes
(),
0
,
dst
.
getTimes
(),
0
,
limit
);
assertArrayEquals
(
"after append xCoordinates"
,
dst
.
getXCoordinates
(),
limit
,
src
.
getXCoordinates
(),
0
,
limit
);
assertArrayEquals
(
"after append yCoordinates"
,
dst
.
getYCoordinates
(),
limit
,
src
.
getYCoordinates
(),
0
,
limit
);
assertArrayEquals
(
"after append pointerIds"
,
dst
.
getPointerIds
(),
limit
,
src
.
getPointerIds
(),
0
,
limit
);
assertArrayEquals
(
"after append times"
,
dst
.
getTimes
(),
limit
,
src
.
getTimes
(),
0
,
limit
);
dst
.
append
(
src
,
0
,
srcLen
);
assertEquals
(
"after append size"
,
dstLen
+
srcLen
,
dst
.
getPointerSize
());
assertTrue
(
"after append size primitive length"
,
dst
.
getPointerIds
().
length
>=
dstLen
+
srcLen
);
assertArrayEquals
(
"after append xCoordinates"
,
dstCopy
.
getXCoordinates
(),
0
,
dst
.
getXCoordinates
(),
0
,
dstLen
);
assertArrayEquals
(
"after append yCoordinates"
,
dstCopy
.
getYCoordinates
(),
0
,
dst
.
getYCoordinates
(),
0
,
dstLen
);
assertArrayEquals
(
"after append pointerIds"
,
dstCopy
.
getPointerIds
(),
0
,
dst
.
getPointerIds
(),
0
,
dstLen
);
assertArrayEquals
(
"after append times"
,
dstCopy
.
getTimes
(),
0
,
dst
.
getTimes
(),
0
,
dstLen
);
assertArrayEquals
(
"after append xCoordinates"
,
dst
.
getXCoordinates
(),
dstLen
,
src
.
getXCoordinates
(),
0
,
srcLen
);
assertArrayEquals
(
"after append yCoordinates"
,
dst
.
getYCoordinates
(),
dstLen
,
src
.
getYCoordinates
(),
0
,
srcLen
);
assertArrayEquals
(
"after append pointerIds"
,
dst
.
getPointerIds
(),
dstLen
,
src
.
getPointerIds
(),
0
,
srcLen
);
assertArrayEquals
(
"after append times"
,
dst
.
getTimes
(),
dstLen
,
src
.
getTimes
(),
0
,
srcLen
);
}
private
static
void
assertArrayEquals
(
String
message
,
int
[]
expecteds
,
int
expectedPos
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment