diff options
author | 2013-04-17 21:25:27 -0700 | |
---|---|---|
committer | 2013-04-17 21:25:27 -0700 | |
commit | 8acab80a8680956038b45912d3e00a1d6a5e3cdb (patch) | |
tree | 3c8587228fa91ea280e8d87675705a171d0164a1 /java/src/com/android/inputmethod/research/FixedLogBuffer.java | |
parent | 0163591de1e71df966bfd7a2203dc1a30dc19477 (diff) | |
parent | 56f35a10cde1beeea51d99427992d832fa2de2bb (diff) | |
download | latinime-8acab80a8680956038b45912d3e00a1d6a5e3cdb.tar.gz latinime-8acab80a8680956038b45912d3e00a1d6a5e3cdb.tar.xz latinime-8acab80a8680956038b45912d3e00a1d6a5e3cdb.zip |
am 56f35a10: Merge "Fix bug in counting words between samples"
* commit '56f35a10cde1beeea51d99427992d832fa2de2bb':
Fix bug in counting words between samples
Diffstat (limited to 'java/src/com/android/inputmethod/research/FixedLogBuffer.java')
-rw-r--r-- | java/src/com/android/inputmethod/research/FixedLogBuffer.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/research/FixedLogBuffer.java b/java/src/com/android/inputmethod/research/FixedLogBuffer.java index 78dc59562..641bf7eae 100644 --- a/java/src/com/android/inputmethod/research/FixedLogBuffer.java +++ b/java/src/com/android/inputmethod/research/FixedLogBuffer.java @@ -51,10 +51,6 @@ public class FixedLogBuffer extends LogBuffer { mNumActualWords = 0; } - protected int getNumActualWords() { - return mNumActualWords; - } - /** * Adds a new LogUnit to the front of the LIFO queue, evicting existing LogUnit's * (oldest first) if word capacity is reached. @@ -119,12 +115,24 @@ public class FixedLogBuffer extends LogBuffer { return logUnit; } - protected void shiftOutWords(final int numWords) { - final int targetNumWords = mNumActualWords - numWords; - final LinkedList<LogUnit> logUnits = getLogUnits(); - while (mNumActualWords > targetNumWords && !logUnits.isEmpty()) { - shiftOut(); + /** + * Remove LogUnits from the front of the LogBuffer until {@code numWords} have been removed. + * + * If there are less than {@code numWords} word-containing {@link LogUnit}s, shifts out + * all {@code LogUnit}s in the buffer. + * + * @param numWords the number of word-containing {@link LogUnit}s to shift out + * @return the number of actual {@code LogUnit}s shifted out + */ + protected int shiftOutWords(final int numWords) { + int numWordContainingLogUnitsShiftedOut = 0; + for (LogUnit logUnit = shiftOut(); logUnit != null + && numWordContainingLogUnitsShiftedOut < numWords; logUnit = shiftOut()) { + if (logUnit.hasWord()) { + numWordContainingLogUnitsShiftedOut++; + } } + return numWordContainingLogUnitsShiftedOut; } public void shiftOutAll() { |