Skip to content
This repository was archived by the owner on Jul 14, 2021. It is now read-only.

Commit 10f45e9

Browse files
committed
Use ConcurrentHashMap instead of ArrayMap to avoid thread safe problem.
1 parent 81ab78d commit 10f45e9

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

gradle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ org.gradle.jvmargs=-Xmx2048m
4545
GROUP=com.alibaba.android
4646
ARTIFACT=virtualview
4747
VERSION=1
48-
VERSION_NAME=1.3.8.1
48+
VERSION_NAME=1.3.8.3
4949
PACKAGING_TYPE=aar
5050
systemProp.compileSdkVersion=26
5151
systemProp.targetSdkVersion=26
5252
systemProp.buildToolsVersion=26.0.1
53+

virtualview/src/main/java/com/tmall/wireless/vaf/virtualview/core/ViewCache.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@
2525
package com.tmall.wireless.vaf.virtualview.core;
2626

2727
import java.util.ArrayList;
28+
import java.util.HashMap;
2829
import java.util.LinkedList;
2930
import java.util.List;
31+
import java.util.Map;
32+
import java.util.concurrent.ConcurrentHashMap;
3033

3134
import android.support.v4.app.ShareCompat.IntentBuilder;
3235
import android.support.v4.util.ArrayMap;
3336
import android.util.Log;
3437
import android.view.View;
38+
3539
import com.libra.TextUtils;
3640
import com.libra.Utils;
3741
import com.libra.virtualview.common.TextBaseCommon;
3842
import com.libra.virtualview.common.ViewBaseCommon;
43+
3944
import org.json.JSONArray;
4045
import org.json.JSONObject;
4146

@@ -49,7 +54,7 @@ public class ViewCache {
4954

5055
private List<ViewBase> mCacheView = new ArrayList<>();
5156

52-
private ArrayMap<ViewBase, List<Item>> mCacheItem = new ArrayMap<>();
57+
private ConcurrentHashMap<ViewBase, List<Item>> mCacheItem = new ConcurrentHashMap<>();
5358

5459
private Object mComponentData;
5560

@@ -244,7 +249,6 @@ public void bind(Object jsonObject, boolean isAppend) {
244249
}
245250

246251

247-
248252
break;
249253
case TYPE_STRING:
250254
mView.setAttribute(mKey, Utils.toString(value));
@@ -314,8 +318,8 @@ public void destroy() {
314318
mCacheView = null;
315319
}
316320
if (mCacheItem != null) {
317-
for (int i = 0, size = mCacheItem.size(); i < size; i++) {
318-
List<Item> items = mCacheItem.valueAt(i);
321+
for (Map.Entry<ViewBase, List<Item>> entry : mCacheItem.entrySet()) {
322+
List<Item> items = entry.getValue();
319323
if (items != null) {
320324
for (int j = 0, length = items.size(); j < length; j++) {
321325
Item item = items.get(j);
@@ -481,14 +485,14 @@ public Object getValueFromEL(Object jsonObject) {
481485
result = jsonObject;
482486
} else {
483487
if (jsonObject instanceof JSONObject) {
484-
result = ((JSONObject)jsonObject).opt(key);
488+
result = ((JSONObject) jsonObject).opt(key);
485489
} else {
486490
break;
487491
}
488492
}
489493
} else if (node instanceof Integer) {
490494
if (jsonObject instanceof JSONArray) {
491-
result = ((JSONArray)jsonObject).opt(((Integer)node).intValue());
495+
result = ((JSONArray) jsonObject).opt(((Integer) node).intValue());
492496
} else {
493497
break;
494498
}
@@ -586,23 +590,23 @@ public Object getValueFromEL(Object jsonObject) {
586590
if (conditionValue == null) {
587591
determine = false;
588592
} else if (conditionValue instanceof Boolean) {
589-
determine = ((Boolean)conditionValue).booleanValue();
593+
determine = ((Boolean) conditionValue).booleanValue();
590594
} else if (conditionValue instanceof String) {
591-
if (TextUtils.isEmpty((CharSequence)conditionValue)) {
595+
if (TextUtils.isEmpty((CharSequence) conditionValue)) {
592596
determine = false;
593597
} else {
594-
if (TextUtils.equals((CharSequence)conditionValue, "null")) {
598+
if (TextUtils.equals((CharSequence) conditionValue, "null")) {
595599
determine = false;
596-
} else if (TextUtils.equals(((String)conditionValue).toLowerCase(), "false")) {
600+
} else if (TextUtils.equals(((String) conditionValue).toLowerCase(), "false")) {
597601
determine = false;
598602
}
599603
}
600604
} else if (conditionValue instanceof JSONObject) {
601-
if (((JSONObject)conditionValue).length() == 0) {
605+
if (((JSONObject) conditionValue).length() == 0) {
602606
determine = false;
603607
}
604608
} else if (conditionValue instanceof JSONArray) {
605-
if (((JSONArray)conditionValue).length() == 0) {
609+
if (((JSONArray) conditionValue).length() == 0) {
606610
determine = false;
607611
}
608612
} else if (conditionValue.equals(JSONObject.NULL)) {
@@ -627,7 +631,7 @@ public Object getValueFromEL(Object jsonObject) {
627631
* so we make Integer.MIN_VALUE as invalid input
628632
*/
629633
public static int parseInt(String s) {
630-
return parseInt(s,10);
634+
return parseInt(s, 10);
631635
}
632636

633637
public static int parseInt(String s, int radix) {
@@ -673,7 +677,7 @@ public static int parseInt(String s, int radix) {
673677
multmin = limit / radix;
674678
while (i < len) {
675679
// Accumulating negatively avoids surprises near MAX_VALUE
676-
digit = Character.digit(s.charAt(i++),radix);
680+
digit = Character.digit(s.charAt(i++), radix);
677681
if (digit < 0) {
678682
return Integer.MIN_VALUE;
679683
}

0 commit comments

Comments
 (0)