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


package com.nirvana.tools.core;

import android.content.Context;

public class UTSharedPreferencesHelper {
    /* JADX WARNING: Code restructure failed: missing block: B:12:0x0019, code lost:
        return;
     */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    public static synchronized void clearInfo(Context context, String str, String str2) {
        synchronized (UTSharedPreferencesHelper.class) {
            context.getSharedPreferences(str, 0).edit().remove(str2).commit();
        }
    }

    public static boolean contains(Context context, String str, String str2) {
        return context.getSharedPreferences(str, 0).contains(str2);
    }

    public static <T> T get(Context context, String str, String str2, T t) {
        try {
            if (contains(context, str, str2)) {
                String decode = EncodeUtil.decode(context.getSharedPreferences(str, 0).getString(str2, ""));
                if (t instanceof Integer) {
                    return (T) Integer.valueOf(decode);
                }
                if (t instanceof Boolean) {
                    return (T) Boolean.valueOf(decode);
                }
                if (t instanceof Long) {
                    return (T) Long.valueOf(decode);
                }
                if (t instanceof String) {
                    return (T) String.valueOf(decode);
                }
                throw new Exception("unsupported type");
            }
        } catch (Exception unused) {
        }
        return t;
    }

    public static <T> void put(Context context, String str, String str2, T t) {
        try {
            context.getSharedPreferences(str, 0).edit().putString(str2, EncodeUtil.encode(t.toString())).commit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}