package com.squareup.leakcanary; import java.io.Serializable; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; /* loaded from: classes.dex */ public final class ExcludedRefs implements Serializable { public final Map classNames; public final Map> fieldNameByClassName; public final Map> staticFieldNameByClassName; public final Map threadNames; public interface Builder { ExcludedRefs build(); BuilderWithParams clazz(String str); BuilderWithParams instanceField(String str, String str2); BuilderWithParams staticField(String str, String str2); BuilderWithParams thread(String str); } public static final class BuilderWithParams implements Builder { private ParamsBuilder lastParams; private final Map> fieldNameByClassName = new LinkedHashMap(); private final Map> staticFieldNameByClassName = new LinkedHashMap(); private final Map threadNames = new LinkedHashMap(); private final Map classNames = new LinkedHashMap(); BuilderWithParams() { } public BuilderWithParams alwaysExclude() { this.lastParams.alwaysExclude = true; return this; } @Override // com.squareup.leakcanary.ExcludedRefs.Builder public ExcludedRefs build() { return new ExcludedRefs(this); } @Override // com.squareup.leakcanary.ExcludedRefs.Builder public BuilderWithParams clazz(String str) { Preconditions.checkNotNull(str, "className"); this.lastParams = new ParamsBuilder("any subclass of " + str); this.classNames.put(str, this.lastParams); return this; } @Override // com.squareup.leakcanary.ExcludedRefs.Builder public BuilderWithParams instanceField(String str, String str2) { Preconditions.checkNotNull(str, "className"); Preconditions.checkNotNull(str2, "fieldName"); Map map = this.fieldNameByClassName.get(str); if (map == null) { map = new LinkedHashMap<>(); this.fieldNameByClassName.put(str, map); } this.lastParams = new ParamsBuilder("field " + str + "#" + str2); map.put(str2, this.lastParams); return this; } public BuilderWithParams named(String str) { this.lastParams.name = str; return this; } public BuilderWithParams reason(String str) { this.lastParams.reason = str; return this; } @Override // com.squareup.leakcanary.ExcludedRefs.Builder public BuilderWithParams staticField(String str, String str2) { Preconditions.checkNotNull(str, "className"); Preconditions.checkNotNull(str2, "fieldName"); Map map = this.staticFieldNameByClassName.get(str); if (map == null) { map = new LinkedHashMap<>(); this.staticFieldNameByClassName.put(str, map); } this.lastParams = new ParamsBuilder("static field " + str + "#" + str2); map.put(str2, this.lastParams); return this; } @Override // com.squareup.leakcanary.ExcludedRefs.Builder public BuilderWithParams thread(String str) { Preconditions.checkNotNull(str, "threadName"); this.lastParams = new ParamsBuilder("any threads named " + str); this.threadNames.put(str, this.lastParams); return this; } } static final class ParamsBuilder { boolean alwaysExclude; final String matching; String name; String reason; ParamsBuilder(String str) { this.matching = str; } } ExcludedRefs(BuilderWithParams builderWithParams) { this.fieldNameByClassName = unmodifiableRefStringMap(builderWithParams.fieldNameByClassName); this.staticFieldNameByClassName = unmodifiableRefStringMap(builderWithParams.staticFieldNameByClassName); this.threadNames = unmodifiableRefMap(builderWithParams.threadNames); this.classNames = unmodifiableRefMap(builderWithParams.classNames); } public static Builder builder() { return new BuilderWithParams(); } private Map unmodifiableRefMap(Map map) { LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Map.Entry entry : map.entrySet()) { linkedHashMap.put(entry.getKey(), new Exclusion(entry.getValue())); } return Collections.unmodifiableMap(linkedHashMap); } private Map> unmodifiableRefStringMap(Map> map) { LinkedHashMap linkedHashMap = new LinkedHashMap(); for (Map.Entry> entry : map.entrySet()) { linkedHashMap.put(entry.getKey(), unmodifiableRefMap(entry.getValue())); } return Collections.unmodifiableMap(linkedHashMap); } public String toString() { String str = ""; for (Map.Entry> entry : this.fieldNameByClassName.entrySet()) { String key = entry.getKey(); for (Map.Entry entry2 : entry.getValue().entrySet()) { str = str + "| Field: " + key + "." + entry2.getKey() + (entry2.getValue().alwaysExclude ? " (always)" : "") + "\n"; } } for (Map.Entry> entry3 : this.staticFieldNameByClassName.entrySet()) { String key2 = entry3.getKey(); for (Map.Entry entry4 : entry3.getValue().entrySet()) { str = str + "| Static field: " + key2 + "." + entry4.getKey() + (entry4.getValue().alwaysExclude ? " (always)" : "") + "\n"; } } for (Map.Entry entry5 : this.threadNames.entrySet()) { str = str + "| Thread:" + entry5.getKey() + (entry5.getValue().alwaysExclude ? " (always)" : "") + "\n"; } for (Map.Entry entry6 : this.classNames.entrySet()) { str = str + "| Class:" + entry6.getKey() + (entry6.getValue().alwaysExclude ? " (always)" : "") + "\n"; } return str; } }