翰林优商.apk(点击下载) / b.java


package com.kwad.sdk.core.config;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import org.json.JSONObject;

public final class b {
    public static final Map<String, Set<com.kwad.sdk.core.config.item.b>> aSs = new ConcurrentHashMap();
    private static SharedPreferences aSt = null;

    static void a(Context context, com.kwad.sdk.core.config.item.b<?> bVar) {
        SharedPreferences bg;
        if (bVar != null && (bg = bg(context)) != null) {
            try {
                bVar.a(bg);
            } catch (Exception e) {
                com.kwad.sdk.core.e.b.printStackTraceOnly(e);
            }
        }
    }

    private static void a(SharedPreferences sharedPreferences) {
        if (sharedPreferences != null) {
            for (String str : aSs.keySet()) {
                Set<com.kwad.sdk.core.config.item.b> set = aSs.get(str);
                if (set != null && !set.isEmpty()) {
                    for (com.kwad.sdk.core.config.item.b bVar : set) {
                        if (bVar != null) {
                            try {
                                bVar.a(sharedPreferences);
                            } catch (Exception e) {
                                com.kwad.sdk.core.e.b.printStackTraceOnly(e);
                            }
                        }
                    }
                }
            }
        }
    }

    public static <T> void a(com.kwad.sdk.core.config.item.b<T> bVar) {
        String key = bVar.getKey();
        if (!TextUtils.isEmpty(key)) {
            Set<com.kwad.sdk.core.config.item.b> cJ = cJ(key);
            if (cJ == null) {
                cJ = new CopyOnWriteArraySet<>();
                aSs.put(key, cJ);
            }
            cJ.add(bVar);
        }
    }

    private static void b(SharedPreferences.Editor editor) {
        if (editor != null) {
            for (String str : aSs.keySet()) {
                Set<com.kwad.sdk.core.config.item.b> set = aSs.get(str);
                if (set != null && !set.isEmpty()) {
                    for (com.kwad.sdk.core.config.item.b bVar : set) {
                        if (bVar != null) {
                            bVar.a(editor);
                        }
                    }
                }
            }
        }
    }

    private static SharedPreferences bg(Context context) {
        if (aSt == null && context != null) {
            aSt = context.getSharedPreferences("ksadsdk_config", 0);
        }
        return aSt;
    }

    public static synchronized boolean bh(Context context) {
        synchronized (b.class) {
            SharedPreferences bg = bg(context);
            if (bg == null) {
                return false;
            }
            SharedPreferences.Editor edit = bg.edit();
            b(edit);
            return edit.commit();
        }
    }

    public static synchronized void bi(Context context) {
        synchronized (b.class) {
            SharedPreferences bg = bg(context);
            if (bg != null) {
                a(bg);
            }
        }
    }

    private static Set<com.kwad.sdk.core.config.item.b> cJ(String str) {
        if (!TextUtils.isEmpty(str)) {
            return aSs.get(str);
        }
        return null;
    }

    public static void f(JSONObject jSONObject) {
        if (jSONObject != null) {
            for (String str : aSs.keySet()) {
                Set<com.kwad.sdk.core.config.item.b> set = aSs.get(str);
                if (set != null && !set.isEmpty() && jSONObject.has(str)) {
                    for (com.kwad.sdk.core.config.item.b bVar : set) {
                        if (bVar != null) {
                            bVar.e(jSONObject);
                        }
                    }
                }
            }
        }
    }
}