aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/research/LogUnit.java
diff options
context:
space:
mode:
authorKurt Partridge <kep@google.com>2012-08-09 15:58:25 -0700
committerKurt Partridge <kep@google.com>2012-12-13 18:44:10 -0800
commit5e854e281a525f0c2dcdb753db2fac3eb810470f (patch)
tree6ea7267ffaa0262fb6dccd1542ee069191da38ec /java/src/com/android/inputmethod/research/LogUnit.java
parent082507e1da56c6cefe575ec3d6a334e9b717e3fa (diff)
downloadlatinime-5e854e281a525f0c2dcdb753db2fac3eb810470f.tar.gz
latinime-5e854e281a525f0c2dcdb753db2fac3eb810470f.tar.xz
latinime-5e854e281a525f0c2dcdb753db2fac3eb810470f.zip
[Rlog1] Track time of log statements
Log statements are now recorded with a timestamp. This is important for filtering out statements not part of words that are sampled when spaces are inserted automatically. multi-project commit with Change-Id: I68221a2528045d25632aef4bb716f92a4f4a56a4 Change-Id: I46ac9b3b1dcbb08425160d0109028cb64445139c
Diffstat (limited to 'java/src/com/android/inputmethod/research/LogUnit.java')
-rw-r--r--java/src/com/android/inputmethod/research/LogUnit.java67
1 files changed, 56 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/research/LogUnit.java b/java/src/com/android/inputmethod/research/LogUnit.java
index d8b3a29ff..0aec80a40 100644
--- a/java/src/com/android/inputmethod/research/LogUnit.java
+++ b/java/src/com/android/inputmethod/research/LogUnit.java
@@ -18,7 +18,7 @@ package com.android.inputmethod.research;
import com.android.inputmethod.latin.CollectionUtils;
-import java.util.ArrayList;
+import java.util.List;
/**
* A group of log statements related to each other.
@@ -35,16 +35,39 @@ import java.util.ArrayList;
* been published recently, or whether the LogUnit contains numbers, etc.
*/
/* package */ class LogUnit {
- private final ArrayList<String[]> mKeysList = CollectionUtils.newArrayList();
- private final ArrayList<Object[]> mValuesList = CollectionUtils.newArrayList();
- private final ArrayList<Boolean> mIsPotentiallyPrivate = CollectionUtils.newArrayList();
+ private final List<String[]> mKeysList;
+ private final List<Object[]> mValuesList;
+ // Assume that mTimeList is sorted in increasing order. Do not insert null values into
+ // mTimeList.
+ private final List<Long> mTimeList;
+ private final List<Boolean> mIsPotentiallyPrivate;
private String mWord;
- private boolean mContainsDigit;
+ private boolean mMayContainDigit;
+ public LogUnit() {
+ mKeysList = CollectionUtils.newArrayList();
+ mValuesList = CollectionUtils.newArrayList();
+ mTimeList = CollectionUtils.newArrayList();
+ mIsPotentiallyPrivate = CollectionUtils.newArrayList();
+ }
+
+ private LogUnit(final List<String[]> keysList, final List<Object[]> valuesList,
+ final List<Long> timeList, final List<Boolean> isPotentiallyPrivate) {
+ mKeysList = keysList;
+ mValuesList = valuesList;
+ mTimeList = timeList;
+ mIsPotentiallyPrivate = isPotentiallyPrivate;
+ }
+
+ /**
+ * Adds a new log statement. The time parameter in successive calls to this method must be
+ * monotonically increasing, or splitByTime() will not work.
+ */
public void addLogStatement(final String[] keys, final Object[] values,
- final Boolean isPotentiallyPrivate) {
+ final long time, final boolean isPotentiallyPrivate) {
mKeysList.add(keys);
mValuesList.add(values);
+ mTimeList.add(time);
mIsPotentiallyPrivate.add(isPotentiallyPrivate);
}
@@ -52,7 +75,7 @@ import java.util.ArrayList;
final int size = mKeysList.size();
for (int i = 0; i < size; i++) {
if (!mIsPotentiallyPrivate.get(i) || isIncludingPrivateData) {
- researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i));
+ researchLog.outputEvent(mKeysList.get(i), mValuesList.get(i), mTimeList.get(i));
}
}
}
@@ -69,15 +92,37 @@ import java.util.ArrayList;
return mWord != null;
}
- public void setContainsDigit() {
- mContainsDigit = true;
+ public void setMayContainDigit() {
+ mMayContainDigit = true;
}
- public boolean hasDigit() {
- return mContainsDigit;
+ public boolean mayContainDigit() {
+ return mMayContainDigit;
}
public boolean isEmpty() {
return mKeysList.isEmpty();
}
+
+ /**
+ * Split this logUnit, with all events before maxTime staying in the current logUnit, and all
+ * events after maxTime going into a new LogUnit that is returned.
+ */
+ public LogUnit splitByTime(final long maxTime) {
+ // Assume that mTimeList is in sorted order.
+ final int length = mTimeList.size();
+ for (int index = 0; index < length; index++) {
+ if (mTimeList.get(index) >= maxTime) {
+ final LogUnit newLogUnit = new LogUnit(
+ mKeysList.subList(index, length),
+ mValuesList.subList(index, length),
+ mTimeList.subList(index, length),
+ mIsPotentiallyPrivate.subList(index, length));
+ newLogUnit.mWord = null;
+ newLogUnit.mMayContainDigit = mMayContainDigit;
+ return newLogUnit;
+ }
+ }
+ return new LogUnit();
+ }
}