package o;

import java.util.HashMap;
import java.util.Map;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class XJ {
    public final HashMap a = new HashMap();
    public final int b = 64;
    public final int c;

    public XJ(int i) {
        this.c = i;
    }

    public static String a(int i, String str) {
        if (str != null) {
            str = str.trim();
            if (str.length() > i) {
                return str.substring(0, i);
            }
        }
        return str;
    }

    public final synchronized boolean b(String str) {
        String strA = a(this.c, "com.crashlytics.version-control-info");
        if (this.a.size() >= this.b && !this.a.containsKey(strA)) {
            return false;
        }
        String strA2 = a(this.c, str);
        String str2 = (String) this.a.get(strA);
        if (str2 == null ? strA2 == null : str2.equals(strA2)) {
            return false;
        }
        this.a.put(strA, strA2);
        return true;
    }

    public final synchronized void c(Map map) {
        try {
            for (Map.Entry entry : map.entrySet()) {
                String str = (String) entry.getKey();
                if (str == null) {
                    throw new IllegalArgumentException("Custom attribute key must not be null.");
                }
                String strA = a(this.c, str);
                if (this.a.size() < this.b || this.a.containsKey(strA)) {
                    String str2 = (String) entry.getValue();
                    this.a.put(strA, str2 == null ? "" : a(this.c, str2));
                }
            }
        } catch (Throwable th) {
            throw th;
        }
    }
}
