diff options
| author | George Lu <georgelu@google.com> | 2019-08-02 21:37:40 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-08-02 21:37:40 +0000 |
| commit | cf9d622edc10412ec8f2837f201c590271eee62b (patch) | |
| tree | 072f9f03547db708581836704a68c3d24bad2a43 /core/java | |
| parent | 0bfc4dc4c317d7e1e00e4427d1bda0c5956c5876 (diff) | |
| parent | bc2238ebcd318cf453bfea669ce3a1130b7c2106 (diff) | |
Merge "Fix RadioMetadata.hashCode()."
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/hardware/radio/RadioMetadata.java | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/core/java/android/hardware/radio/RadioMetadata.java b/core/java/android/hardware/radio/RadioMetadata.java index c135c8a73abc..76304bda05a1 100644 --- a/core/java/android/hardware/radio/RadioMetadata.java +++ b/core/java/android/hardware/radio/RadioMetadata.java @@ -26,6 +26,9 @@ import android.util.ArrayMap; import android.util.Log; import android.util.SparseArray; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Set; /** @@ -257,9 +260,22 @@ public final class RadioMetadata implements Parcelable { private final Bundle mBundle; + // Lazily computed hash code based upon the contents of mBundle. + private Integer mHashCode; + @Override public int hashCode() { - return mBundle.hashCode(); + if (mHashCode == null) { + List<String> keys = new ArrayList<String>(mBundle.keySet()); + keys.sort(null); + Object[] objs = new Object[2 * keys.size()]; + for (int i = 0; i < keys.size(); i++) { + objs[2 * i] = keys.get(i); + objs[2 * i + 1] = mBundle.get(keys.get(i)); + } + mHashCode = Arrays.hashCode(objs); + } + return mHashCode; } @Override @@ -626,6 +642,8 @@ public final class RadioMetadata implements Parcelable { String key = getKeyFromNativeKey(nativeKey); try { putInt(mBundle, key, value); + // Invalidate mHashCode to force it to be recomputed. + mHashCode = null; return 0; } catch (IllegalArgumentException ex) { return -1; @@ -639,6 +657,8 @@ public final class RadioMetadata implements Parcelable { return -1; } mBundle.putString(key, value); + // Invalidate mHashCode to force it to be recomputed. + mHashCode = null; return 0; } @@ -653,6 +673,8 @@ public final class RadioMetadata implements Parcelable { bmp = BitmapFactory.decodeByteArray(value, 0, value.length); if (bmp != null) { mBundle.putParcelable(key, bmp); + // Invalidate mHashCode to force it to be recomputed. + mHashCode = null; return 0; } } catch (Exception e) { @@ -668,6 +690,8 @@ public final class RadioMetadata implements Parcelable { } mBundle.putParcelable(key, new RadioMetadata.Clock( utcEpochSeconds, timezoneOffsetInMinutes)); + // Invalidate mHashCode to force it to be recomputed. + mHashCode = null; return 0; } } |
