package csdk.gluads.util; import android.text.TextUtils; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import csdk.gluads.Consts; import java.util.List; import java.util.Map; /* loaded from: classes4.dex */ public class ConfigUtil { public static boolean getBoolean(@Nullable Object obj, @NonNull String str) { return getBoolean(obj, str, false); } public static boolean getBoolean(@Nullable Object obj, @NonNull String str, boolean z) { Object object = getObject(obj, str, null); if (object == null) { return z; } if (object instanceof Boolean) { return ((Boolean) object).booleanValue(); } if (object instanceof String) { String str2 = (String) object; if (TextUtils.equals(str2, "true")) { return true; } if (TextUtils.equals(str2, "false")) { return false; } throw new IllegalArgumentException("Can't convert string to boolean value: " + str2 + Consts.STRING_PERIOD); } throw new IllegalArgumentException("Unsupported type for boolean value: " + object.getClass()); } public static int getInteger(@Nullable Object obj, @NonNull String str) { return getInteger(obj, str, 0); } public static int getInteger(@Nullable Object obj, @NonNull String str, int i) { Object object = getObject(obj, str, null); if (object == null) { return i; } if (object instanceof Number) { return ((Number) object).intValue(); } if (object instanceof String) { return Integer.parseInt((String) object); } throw new IllegalArgumentException("Unsupported type for int value: " + object.getClass()); } public static Integer getInteger(@Nullable Object obj, @NonNull String str, Integer num) { Object object = getObject(obj, str, null); if (object == null) { return num; } if (object instanceof Number) { return Integer.valueOf(((Number) object).intValue()); } if (object instanceof String) { return Integer.valueOf(Integer.parseInt((String) object)); } throw new IllegalArgumentException("Unsupported type for int value: " + object.getClass()); } public static long getLong(@Nullable Object obj, @NonNull String str) { return getLong(obj, str, 0L); } public static long getLong(@Nullable Object obj, @NonNull String str, long j) { Object object = getObject(obj, str, null); if (object == null) { return j; } if (object instanceof Number) { return ((Number) object).longValue(); } if (object instanceof String) { return Long.parseLong((String) object); } throw new IllegalArgumentException("Unsupported type for long value: " + object.getClass()); } public static double getDouble(@Nullable Object obj, @NonNull String str) { return getDouble(obj, str, 0.0d); } public static double getDouble(@Nullable Object obj, @NonNull String str, double d) { Object object = getObject(obj, str, null); if (object == null) { return d; } if (object instanceof Number) { return ((Number) object).doubleValue(); } if (object instanceof String) { return Double.parseDouble((String) object); } throw new IllegalArgumentException("Unsupported type for double value: " + object.getClass()); } @Nullable public static String getString(@Nullable Object obj, @NonNull String str) { return getString(obj, str, null); } @Nullable public static String getString(@Nullable Object obj, @NonNull String str, @Nullable String str2) { Object object = getObject(obj, str, null); if (object == null) { return str2; } if (object instanceof String) { return (String) object; } if ((object instanceof Number) || (object instanceof Boolean)) { return object.toString(); } throw new IllegalArgumentException("Unsupported type for string value: " + object.getClass()); } @Nullable public static Map getMap(@Nullable Object obj, @NonNull String str) { return getMap(obj, str, null); } @Nullable public static Map getMap(@Nullable Object obj, @NonNull String str, @Nullable Map map) { Object object = getObject(obj, str, null); if (object == null) { return map; } if (object instanceof Map) { return (Map) object; } throw new IllegalArgumentException("Unsupported type for map value: " + object.getClass()); } public static List getList(@Nullable Object obj, @NonNull String str) { return getList(obj, str, null); } @Nullable public static List getList(@Nullable Object obj, @NonNull String str, @Nullable List list) { Object object = getObject(obj, str, null); if (object == null) { return list; } if (object instanceof List) { return (List) object; } throw new IllegalArgumentException("Unsupported type for list value: " + object.getClass()); } public static Object getObject(@Nullable Object obj, @NonNull String str) { return getObject(obj, str, null); } @Nullable public static Object getObject(@Nullable Object obj, @NonNull String str, @Nullable Object obj2) { if (obj == null) { return obj2; } for (String str2 : splitPath(str)) { if (obj == null) { return obj2; } obj = ((Map) obj).get(str2); } return obj; } @NonNull private static String[] splitPath(@NonNull String str) { return str.split("\\."); } @Nullable public static String getCustomCrossPromoQueries(@NonNull Object obj) { return getString(obj, Consts.CROSSPROMO_CUSTOMDATAP_KEY_NAME, null); } @NonNull public static Object setCustomCrossPromoQueries(@NonNull String str, @NonNull Map map) { map.put(Consts.CROSSPROMO_CUSTOMDATAP_KEY_NAME, str); return map; } @Nullable public static Map configSdk(@NonNull Map map) { return getMap(map, "csdk.gluAds"); } @Nullable public static Map configComponents(@NonNull Map map) { return getMap(configSdk(map), "components"); } @Nullable public static Map configDisabled(@NonNull Map map) { return getMap(configSdk(map), "disabled"); } public static Map getConfigMapVariant(Map map, String str, boolean z, Map map2) { Map map3 = getMap(map, str + (z ? "Tablet" : "Phone"), null); return map3 != null ? map3 : getMap(map, str, map2); } public static int getIntegerVariant(Map map, String str, boolean z, int i) { int integer = getInteger(map, str + (z ? "Tablet" : "Phone"), -1); return integer > 0 ? integer : getInteger(map, str, i); } public static boolean shouldSendImpressionData(Map map) { return !getBoolean(map, Consts.KEY_NAME_IMPRESSION_DATA, false); } }