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
78a8d5b6
Commit
78a8d5b6
authored
12 years ago
by
Jean Chalard
Committed by
Android (Google) Code Review
12 years ago
Browse files
Options
Downloads
Plain Diff
Merge "Implement a comparator for SuggestedWordInfos."
parents
30447239
9da0027b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/src/com/android/inputmethod/latin/Suggest.java
+18
-4
18 additions, 4 deletions
java/src/com/android/inputmethod/latin/Suggest.java
with
18 additions
and
4 deletions
java/src/com/android/inputmethod/latin/Suggest.java
+
18
−
4
View file @
78a8d5b6
...
...
@@ -26,6 +26,8 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Locale
;
...
...
@@ -384,6 +386,21 @@ public class Suggest {
return
suggestionsList
;
}
private
static
class
SuggestedWordInfoComparator
implements
Comparator
<
SuggestedWordInfo
>
{
// This comparator ranks the word info with the higher frequency first. That's because
// that's the order we want our elements in.
@Override
public
int
compare
(
final
SuggestedWordInfo
o1
,
final
SuggestedWordInfo
o2
)
{
if
(
o1
.
mScore
>
o2
.
mScore
)
return
-
1
;
if
(
o1
.
mScore
<
o2
.
mScore
)
return
1
;
if
(
o1
.
mCodePointCount
<
o2
.
mCodePointCount
)
return
-
1
;
if
(
o1
.
mCodePointCount
>
o2
.
mCodePointCount
)
return
1
;
return
o1
.
mWord
.
toString
().
compareTo
(
o2
.
mWord
.
toString
());
}
}
private
static
final
SuggestedWordInfoComparator
sSuggestedWordInfoComparator
=
new
SuggestedWordInfoComparator
();
public
boolean
addWord
(
final
SuggestedWordInfo
wordInfo
,
final
int
dicTypeId
,
final
int
dataType
,
final
ArrayList
<
SuggestedWordInfo
>
suggestions
,
final
String
consideredWord
)
{
...
...
@@ -399,11 +416,8 @@ public class Suggest {
&&
suggestions
.
get
(
prefMaxSuggestions
-
1
).
mScore
>=
score
)
return
true
;
final
int
length
=
wordInfo
.
mCodePointCount
;
while
(
pos
<
suggestions
.
size
())
{
final
int
curScore
=
suggestions
.
get
(
pos
).
mScore
;
if
(
curScore
<
score
||
(
curScore
==
score
&&
length
<
suggestions
.
get
(
pos
).
mCodePointCount
))
{
if
(
sSuggestedWordInfoComparator
.
compare
(
wordInfo
,
suggestions
.
get
(
pos
))
<
0
)
break
;
}
pos
++;
}
if
(
pos
>=
prefMaxSuggestions
)
{
...
...
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