package com.helpshift.util; import com.helpshift.log.HSLogger; import com.vungle.ads.internal.signals.SignalManager; import java.io.Closeable; 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; /* loaded from: classes3.dex */ public abstract class Utils { public static String mapToJsonString(Map map) { return map != null ? new JSONObject(map).toString() : ""; } public static Map jsonStringToMap(String str) { if (isEmpty(str) || !isValidJsonString(str)) { return new HashMap(); } try { HashMap hashMap = new HashMap(); JSONObject jSONObject = new JSONObject(str); Iterator keys = jSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); hashMap.put(next, jSONObject.get(next)); } return hashMap; } catch (JSONException e) { HSLogger.e("Utils", "Error in creating map from string json", e); return new HashMap(); } } public static Map jsonStringToStringMap(String str) { if (isEmpty(str) || !isValidJsonString(str)) { return new HashMap(); } try { HashMap hashMap = new HashMap(); JSONObject jSONObject = new JSONObject(str); Iterator keys = jSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); hashMap.put(next, jSONObject.getString(next)); } return hashMap; } catch (Exception e) { HSLogger.e("Utils", "Error in creating map from string json", e); return new HashMap(); } } public static JSONArray listToJSONArray(List list) { if (list == null || list.size() == 0) { return new JSONArray(); } return new JSONArray((Collection) list); } public static boolean isNotEmpty(String str) { return !isEmpty(str); } public static boolean isEmpty(String str) { return str == null || str.trim().length() == 0; } public static boolean isNotEmpty(Map map) { return !isEmpty(map); } public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); } public static boolean isEmpty(JSONArray jSONArray) { return jSONArray == null || jSONArray.length() == 0; } public static boolean isValidJsonString(String str) { try { try { new JSONObject(str); return true; } catch (Exception unused) { return false; } } catch (Exception unused2) { new JSONArray(str); return true; } } public static void closeQuietly(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (Exception unused) { } } } public static String join(CharSequence charSequence, Iterable iterable) { if (iterable == null) { return null; } StringBuilder sb = new StringBuilder(); boolean z = true; for (Object obj : iterable) { if (z) { z = false; } else { sb.append(charSequence); } sb.append(obj); } return sb.toString(); } public static boolean isToday(long j) { return j / SignalManager.TWENTY_FOUR_HOURS_MILLIS == System.currentTimeMillis() / SignalManager.TWENTY_FOUR_HOURS_MILLIS; } }