Replace HashMap by SparseArray
Bug:6013599
Change-Id: Ia3592bf4a4e348bdee822e4f34180b4f64807d11
diff --git a/src/com/android/contacts/model/EntityModifier.java b/src/com/android/contacts/model/EntityModifier.java
index ef5d304..2d87ff0 100644
--- a/src/com/android/contacts/model/EntityModifier.java
+++ b/src/com/android/contacts/model/EntityModifier.java
@@ -53,6 +53,7 @@
import android.provider.ContactsContract.RawContacts;
import android.text.TextUtils;
import android.util.Log;
+import android.util.SparseArray;
import android.util.SparseIntArray;
import java.text.ParsePosition;
@@ -60,12 +61,10 @@
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
import java.util.Set;
/**
@@ -1237,7 +1236,7 @@
return;
}
- final Map<Integer, EventEditType> allowedTypes = new HashMap<Integer, EventEditType>();
+ final SparseArray<EventEditType> allowedTypes = new SparseArray<EventEditType>();
for (EditType editType : newDataKind.typeList) {
allowedTypes.put(editType.rawValue, (EventEditType) editType);
}
@@ -1248,7 +1247,8 @@
}
final String dateString = values.getAsString(Event.START_DATE);
final Integer type = values.getAsInteger(Event.TYPE);
- if (type != null && allowedTypes.containsKey(type) && !TextUtils.isEmpty(dateString)) {
+ if (type != null && (allowedTypes.indexOfKey(type) >= 0)
+ && !TextUtils.isEmpty(dateString)) {
EventEditType suitableType = allowedTypes.get(type);
final ParsePosition position = new ParsePosition(0);
@@ -1332,7 +1332,7 @@
}
final Set<Integer> allowedTypes = new HashSet<Integer>();
// key: type, value: the number of entries allowed for the type (specificMax)
- final Map<Integer, Integer> typeSpecificMaxMap = new HashMap<Integer, Integer>();
+ final SparseIntArray typeSpecificMaxMap = new SparseIntArray();
if (defaultType != null) {
allowedTypes.add(defaultType);
typeSpecificMaxMap.put(defaultType, -1);
@@ -1359,7 +1359,7 @@
final int typeOverallMax = newDataKind.typeOverallMax;
// key: type, value: the number of current entries.
- final Map<Integer, Integer> currentEntryCount = new HashMap<Integer, Integer>();
+ final SparseIntArray currentEntryCount = new SparseIntArray();
int totalCount = 0;
for (ValuesDelta entry : mimeEntries) {
@@ -1390,11 +1390,9 @@
typeForNewAccount = oldType;
}
if (typeForNewAccount != null) {
- final int specificMax = (typeSpecificMaxMap.containsKey(typeForNewAccount) ?
- typeSpecificMaxMap.get(typeForNewAccount) : 0);
+ final int specificMax = typeSpecificMaxMap.get(typeForNewAccount, 0);
if (specificMax >= 0) {
- final int currentCount = (currentEntryCount.get(typeForNewAccount) != null ?
- currentEntryCount.get(typeForNewAccount) : 0);
+ final int currentCount = currentEntryCount.get(typeForNewAccount, 0);
if (currentCount >= specificMax) {
continue;
}