aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/research/LogUnit.java
diff options
context:
space:
mode:
authorKurt Partridge <kep@google.com>2012-12-14 06:08:20 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-12-14 06:08:20 -0800
commit39b5396f8e70eaac73d4c5eaa2bfede32a3f1f49 (patch)
tree5f939354e363a52e5835d269bc801864ae57e1b6 /java/src/com/android/inputmethod/research/LogUnit.java
parentedbb65be3e5e391affbf47e134422ac1d1a4ae13 (diff)
parent5e854e281a525f0c2dcdb753db2fac3eb810470f (diff)
downloadlatinime-39b5396f8e70eaac73d4c5eaa2bfede32a3f1f49.tar.gz
latinime-39b5396f8e70eaac73d4c5eaa2bfede32a3f1f49.tar.xz
latinime-39b5396f8e70eaac73d4c5eaa2bfede32a3f1f49.zip
Merge "[Rlog1] Track time of log statements"
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();
+ }
}