summaryrefslogtreecommitdiff
path: root/android/app/usage/TimeSparseArray.java
diff options
context:
space:
mode:
authorJustin Klaassen <justinklaassen@google.com>2018-04-03 23:21:57 -0400
committerJustin Klaassen <justinklaassen@google.com>2018-04-03 23:21:57 -0400
commit4d01eeaffaa720e4458a118baa137a11614f00f7 (patch)
tree66751893566986236788e3c796a7cc5e90d05f52 /android/app/usage/TimeSparseArray.java
parenta192cc2a132cb0ee8588e2df755563ec7008c179 (diff)
downloadandroid-28-4d01eeaffaa720e4458a118baa137a11614f00f7.tar.gz
Import Android SDK Platform P [4697573]
/google/data/ro/projects/android/fetch_artifact \ --bid 4697573 \ --target sdk_phone_armv7-win_sdk \ sdk-repo-linux-sources-4697573.zip AndroidVersion.ApiLevel has been modified to appear as 28 Change-Id: If80578c3c657366cc9cf75f8db13d46e2dd4e077
Diffstat (limited to 'android/app/usage/TimeSparseArray.java')
-rw-r--r--android/app/usage/TimeSparseArray.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/android/app/usage/TimeSparseArray.java b/android/app/usage/TimeSparseArray.java
index 7974fa70..9ef88e41 100644
--- a/android/app/usage/TimeSparseArray.java
+++ b/android/app/usage/TimeSparseArray.java
@@ -17,6 +17,7 @@
package android.app.usage;
import android.util.LongSparseArray;
+import android.util.Slog;
/**
* An array that indexes by a long timestamp, representing milliseconds since the epoch.
@@ -24,6 +25,8 @@ import android.util.LongSparseArray;
* {@hide}
*/
public class TimeSparseArray<E> extends LongSparseArray<E> {
+ private static final String TAG = TimeSparseArray.class.getSimpleName();
+
public TimeSparseArray() {
super();
}
@@ -70,6 +73,30 @@ public class TimeSparseArray<E> extends LongSparseArray<E> {
}
/**
+ * {@inheritDoc}
+ *
+ * Overridden to ensure no collisions. The key (time in milliseconds) is incremented till an
+ * empty place is found.
+ */
+ @Override
+ public void put(long key, E value) {
+ final long origKey = key;
+ int keyIndex = indexOfKey(key);
+ if (keyIndex >= 0) {
+ final long sz = size();
+ while (keyIndex < sz && keyAt(keyIndex) == key) {
+ key++;
+ keyIndex++;
+ }
+ if (key >= origKey + 10) {
+ Slog.w(TAG, "Value " + value + " supposed to be inserted at " + origKey
+ + " displaced to " + key);
+ }
+ }
+ super.put(key, value);
+ }
+
+ /**
* Finds the index of the first element whose timestamp is less than or equal to
* the given time.
*