- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
340 lines
12 KiB
Java
340 lines
12 KiB
Java
package com.glu.plugins.gluanalytics.util;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.os.Bundle;
|
|
import android.text.TextUtils;
|
|
import android.util.JsonReader;
|
|
import android.util.JsonToken;
|
|
import com.applovin.impl.f;
|
|
import csdk.gluads.Consts;
|
|
import java.io.IOException;
|
|
import java.io.StringReader;
|
|
import java.lang.reflect.Array;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
import org.json.JSONStringer;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class CollectionUtil {
|
|
public static Map<String, Object> parseJsonObject(String str) throws JSONException {
|
|
return Api11.parseJsonObject(str);
|
|
}
|
|
|
|
public static void putIfNotEmpty(JSONStringer jSONStringer, String str, String str2) throws JSONException {
|
|
if (TextUtils.isEmpty(str2)) {
|
|
return;
|
|
}
|
|
jSONStringer.key(str).value(str2);
|
|
}
|
|
|
|
public static void putIfNotNull(JSONStringer jSONStringer, String str, Object obj) throws JSONException {
|
|
if (obj != null) {
|
|
jSONStringer.key(str);
|
|
addValue(jSONStringer, obj);
|
|
}
|
|
}
|
|
|
|
public static void putIf(Map<String, Object> map, boolean z, String str, Object obj) {
|
|
if (z) {
|
|
map.put(str, obj);
|
|
}
|
|
}
|
|
|
|
public static void putIfNotEmpty(Map<String, ? super String> map, String str, String str2) {
|
|
if (TextUtils.isEmpty(str2)) {
|
|
return;
|
|
}
|
|
map.put(str, str2);
|
|
}
|
|
|
|
public static void putIfNotNull(Map<String, Object> map, String str, Object obj) {
|
|
if (obj != null) {
|
|
map.put(str, obj);
|
|
}
|
|
}
|
|
|
|
public static void putAll(Map<String, Object> map, Map<String, ?> map2) {
|
|
if (map2 != null) {
|
|
map.putAll(map2);
|
|
}
|
|
}
|
|
|
|
public static void putAll(JSONStringer jSONStringer, Map<String, ?> map) throws JSONException {
|
|
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
|
jSONStringer.key(entry.getKey());
|
|
addValue(jSONStringer, entry.getValue());
|
|
}
|
|
}
|
|
|
|
public static void addAll(JSONStringer jSONStringer, Collection<?> collection) throws JSONException {
|
|
Iterator<?> it = collection.iterator();
|
|
while (it.hasNext()) {
|
|
addValue(jSONStringer, it.next());
|
|
}
|
|
}
|
|
|
|
public static void addValue(JSONStringer jSONStringer, Object obj) throws JSONException {
|
|
if (obj instanceof Map) {
|
|
jSONStringer.object();
|
|
putAll(jSONStringer, (Map<String, ?>) obj);
|
|
jSONStringer.endObject();
|
|
} else {
|
|
if (obj instanceof List) {
|
|
jSONStringer.array();
|
|
addAll(jSONStringer, (Collection) obj);
|
|
jSONStringer.endArray();
|
|
return;
|
|
}
|
|
jSONStringer.value(obj);
|
|
}
|
|
}
|
|
|
|
public static void writeSanitizedList(JSONStringer jSONStringer, List<?> list) throws JSONException {
|
|
jSONStringer.array();
|
|
for (Object obj : list) {
|
|
if (obj instanceof Map) {
|
|
writeSanitizedMap(jSONStringer, (Map) obj);
|
|
} else if (obj instanceof List) {
|
|
writeSanitizedList(jSONStringer, (List) obj);
|
|
} else {
|
|
writeSanitizedValue(jSONStringer, obj);
|
|
}
|
|
}
|
|
jSONStringer.endArray();
|
|
}
|
|
|
|
public static void writeSanitizedMap(JSONStringer jSONStringer, Map<String, ?> map) throws JSONException {
|
|
jSONStringer.object();
|
|
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
|
Object value = entry.getValue();
|
|
if (value != null) {
|
|
if (value instanceof String) {
|
|
String str = (String) value;
|
|
if (str.length() > 0) {
|
|
jSONStringer.key(entry.getKey()).value(str);
|
|
}
|
|
} else if (value instanceof Map) {
|
|
Map map2 = (Map) value;
|
|
if (!isEmpty((Map<?, ?>) map2)) {
|
|
jSONStringer.key(entry.getKey());
|
|
writeSanitizedMap(jSONStringer, map2);
|
|
}
|
|
} else if (value instanceof List) {
|
|
List list = (List) value;
|
|
if (!isEmpty((List<?>) list)) {
|
|
jSONStringer.key(entry.getKey());
|
|
writeSanitizedList(jSONStringer, list);
|
|
}
|
|
} else {
|
|
jSONStringer.key(entry.getKey());
|
|
writeSanitizedValue(jSONStringer, value);
|
|
}
|
|
}
|
|
}
|
|
jSONStringer.endObject();
|
|
}
|
|
|
|
public static boolean isEmpty(List<?> list) {
|
|
return list.isEmpty();
|
|
}
|
|
|
|
public static boolean isEmpty(Map<?, ?> map) {
|
|
if (map.isEmpty()) {
|
|
return true;
|
|
}
|
|
for (Object obj : map.values()) {
|
|
if (obj != null) {
|
|
if (obj instanceof Map) {
|
|
if (!isEmpty((Map<?, ?>) obj)) {
|
|
return false;
|
|
}
|
|
} else if (obj instanceof List) {
|
|
if (!isEmpty((List<?>) obj)) {
|
|
return false;
|
|
}
|
|
} else if (!(obj instanceof String) || ((String) obj).length() > 0) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static Map<String, Object> toMap(Bundle bundle) {
|
|
return (Map) toSimpleJavaTypes(bundle);
|
|
}
|
|
|
|
public static Map<String, Object> toMap(JSONObject jSONObject) {
|
|
return (Map) toSimpleJavaTypes(jSONObject);
|
|
}
|
|
|
|
public static <K, V> Map<K, V> createMap() {
|
|
return new HashMap();
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static <K, V> Map<K, V> createMap(Object... objArr) {
|
|
f.b bVar = (Map<K, V>) createMap();
|
|
int length = objArr.length;
|
|
for (int i = 0; i < length; i += 2) {
|
|
bVar.put(objArr[i], objArr[i + 1]);
|
|
}
|
|
return bVar;
|
|
}
|
|
|
|
public static <K, V> Map<K, V> shallowClone(Map<K, V> map) {
|
|
Map<K, V> createMap = createMap();
|
|
if (map != null) {
|
|
createMap.putAll(map);
|
|
}
|
|
return createMap;
|
|
}
|
|
|
|
private static Object toSimpleJavaTypes(Object obj) {
|
|
if (obj == null || (obj instanceof String) || (obj instanceof Number) || (obj instanceof Boolean)) {
|
|
return obj;
|
|
}
|
|
if ((obj instanceof CharSequence) || (obj instanceof Character)) {
|
|
return obj.toString();
|
|
}
|
|
if (obj instanceof Iterable) {
|
|
ArrayList arrayList = new ArrayList();
|
|
Iterator it = ((Iterable) obj).iterator();
|
|
while (it.hasNext()) {
|
|
arrayList.add(toSimpleJavaTypes(it.next()));
|
|
}
|
|
return arrayList;
|
|
}
|
|
int i = 0;
|
|
if (obj.getClass().isArray()) {
|
|
ArrayList arrayList2 = new ArrayList();
|
|
int length = Array.getLength(obj);
|
|
while (i < length) {
|
|
arrayList2.add(toSimpleJavaTypes(Array.get(obj, i)));
|
|
i++;
|
|
}
|
|
return arrayList2;
|
|
}
|
|
if (obj instanceof Bundle) {
|
|
Map createMap = createMap();
|
|
Bundle bundle = (Bundle) obj;
|
|
for (String str : bundle.keySet()) {
|
|
createMap.put(str, toSimpleJavaTypes(bundle.get(str)));
|
|
}
|
|
return createMap;
|
|
}
|
|
if (obj instanceof JSONArray) {
|
|
ArrayList arrayList3 = new ArrayList();
|
|
JSONArray jSONArray = (JSONArray) obj;
|
|
while (i < jSONArray.length()) {
|
|
arrayList3.add(toSimpleJavaTypes(jSONArray.opt(i)));
|
|
i++;
|
|
}
|
|
return arrayList3;
|
|
}
|
|
if (obj instanceof JSONObject) {
|
|
Map createMap2 = createMap();
|
|
JSONObject jSONObject = (JSONObject) obj;
|
|
Iterator<String> keys = jSONObject.keys();
|
|
while (keys.hasNext()) {
|
|
String next = keys.next();
|
|
createMap2.put(next, toSimpleJavaTypes(jSONObject.opt(next)));
|
|
}
|
|
return createMap2;
|
|
}
|
|
if (obj == JSONObject.NULL) {
|
|
return null;
|
|
}
|
|
throw new IllegalArgumentException(String.format("Unsupported type %s", obj.getClass()));
|
|
}
|
|
|
|
private static void writeSanitizedValue(JSONStringer jSONStringer, Object obj) throws JSONException {
|
|
if (obj instanceof Boolean) {
|
|
jSONStringer.value(((Boolean) obj).booleanValue() ? 1L : 0L);
|
|
} else {
|
|
jSONStringer.value(obj);
|
|
}
|
|
}
|
|
|
|
@TargetApi(11)
|
|
public static class Api11 {
|
|
public static Map<String, Object> parseJsonObject(String str) throws JSONException {
|
|
try {
|
|
JsonReader jsonReader = new JsonReader(new StringReader(str));
|
|
jsonReader.setLenient(true);
|
|
return parseJsonObject(jsonReader);
|
|
} catch (IOException e) {
|
|
throw Common.propagate(e);
|
|
}
|
|
}
|
|
|
|
public static Object parseJsonValue(JsonReader jsonReader) throws JSONException, IOException {
|
|
JsonToken peek = jsonReader.peek();
|
|
if (peek == JsonToken.BEGIN_OBJECT) {
|
|
return parseJsonObject(jsonReader);
|
|
}
|
|
if (peek == JsonToken.BEGIN_ARRAY) {
|
|
return parseJsonArray(jsonReader);
|
|
}
|
|
if (peek == JsonToken.BOOLEAN) {
|
|
return Boolean.valueOf(jsonReader.nextBoolean());
|
|
}
|
|
if (peek == JsonToken.NULL) {
|
|
jsonReader.nextNull();
|
|
return null;
|
|
}
|
|
if (peek == JsonToken.NUMBER) {
|
|
String nextString = jsonReader.nextString();
|
|
if (nextString.contains(Consts.STRING_PERIOD) || nextString.contains("e") || nextString.contains("E")) {
|
|
return Double.valueOf(Double.parseDouble(nextString));
|
|
}
|
|
return Long.valueOf(Long.parseLong(nextString));
|
|
}
|
|
if (peek == JsonToken.STRING) {
|
|
return jsonReader.nextString();
|
|
}
|
|
throw new JSONException("Unexpected token " + peek);
|
|
}
|
|
|
|
public static Map<String, Object> parseJsonObject(JsonReader jsonReader) throws JSONException, IOException {
|
|
Map<String, Object> createMap = CollectionUtil.createMap();
|
|
jsonReader.beginObject();
|
|
while (true) {
|
|
JsonToken peek = jsonReader.peek();
|
|
if (peek == JsonToken.END_OBJECT) {
|
|
jsonReader.endObject();
|
|
return createMap;
|
|
}
|
|
if (peek == JsonToken.NAME) {
|
|
createMap.put(jsonReader.nextName(), parseJsonValue(jsonReader));
|
|
} else {
|
|
throw new JSONException("Expected } or name but found " + peek);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static List<Object> parseJsonArray(JsonReader jsonReader) throws JSONException, IOException {
|
|
ArrayList arrayList = new ArrayList();
|
|
jsonReader.beginArray();
|
|
while (jsonReader.peek() != JsonToken.END_ARRAY) {
|
|
arrayList.add(parseJsonValue(jsonReader));
|
|
}
|
|
jsonReader.endArray();
|
|
return arrayList;
|
|
}
|
|
}
|
|
|
|
public static class Api1 {
|
|
public static Map<String, Object> parseJsonObject(String str) throws JSONException {
|
|
return CollectionUtil.toMap(new JSONObject(str));
|
|
}
|
|
}
|
|
}
|