package com.google.gson.internal; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; import com.google.gson.Gson; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.annotations.Expose; import com.google.gson.annotations.Since; import com.google.gson.annotations.Until; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /* loaded from: classes.dex */ public final class Excluder implements TypeAdapterFactory, Cloneable { public static final Excluder DEFAULT = new Excluder(); private static final double IGNORE_VERSIONS = -1.0d; private boolean requireExpose; private double version = IGNORE_VERSIONS; private int modifiers = 136; private boolean serializeInnerClasses = true; private List serializationStrategies = Collections.emptyList(); private List deserializationStrategies = Collections.emptyList(); private boolean isAnonymousOrLocal(Class cls) { return !Enum.class.isAssignableFrom(cls) && (cls.isAnonymousClass() || cls.isLocalClass()); } private boolean isInnerClass(Class cls) { return cls.isMemberClass() && !isStatic(cls); } private boolean isStatic(Class cls) { return (cls.getModifiers() & 8) != 0; } private boolean isValidSince(Since since) { return since == null || since.value() <= this.version; } private boolean isValidUntil(Until until) { return until == null || until.value() > this.version; } private boolean isValidVersion(Since since, Until until) { return isValidSince(since) && isValidUntil(until); } @Override // com.google.gson.TypeAdapterFactory public TypeAdapter create(final Gson gson, final TypeToken typeToken) { Class rawType = typeToken.getRawType(); final boolean excludeClass = excludeClass(rawType, true); final boolean excludeClass2 = excludeClass(rawType, false); if (excludeClass || excludeClass2) { return new TypeAdapter() { // from class: com.google.gson.internal.Excluder.1 private TypeAdapter delegate; private TypeAdapter delegate() { TypeAdapter typeAdapter = this.delegate; if (typeAdapter != null) { return typeAdapter; } TypeAdapter delegateAdapter = gson.getDelegateAdapter(Excluder.this, typeToken); this.delegate = delegateAdapter; return delegateAdapter; } @Override // com.google.gson.TypeAdapter public T read(JsonReader jsonReader) throws IOException { if (!excludeClass2) { return delegate().read(jsonReader); } jsonReader.skipValue(); return null; } @Override // com.google.gson.TypeAdapter public void write(JsonWriter jsonWriter, T t) throws IOException { if (excludeClass) { jsonWriter.nullValue(); } else { delegate().write(jsonWriter, t); } } }; } return null; } public Excluder disableInnerClassSerialization() { Excluder m13clone = m13clone(); m13clone.serializeInnerClasses = false; return m13clone; } public boolean excludeClass(Class cls, boolean z) { if (this.version != IGNORE_VERSIONS && !isValidVersion((Since) cls.getAnnotation(Since.class), (Until) cls.getAnnotation(Until.class))) { return true; } if ((!this.serializeInnerClasses && isInnerClass(cls)) || isAnonymousOrLocal(cls)) { return true; } Iterator it = (z ? this.serializationStrategies : this.deserializationStrategies).iterator(); while (it.hasNext()) { if (it.next().shouldSkipClass(cls)) { return true; } } return false; } public boolean excludeField(Field field, boolean z) { Expose expose; if ((this.modifiers & field.getModifiers()) != 0) { return true; } if ((this.version != IGNORE_VERSIONS && !isValidVersion((Since) field.getAnnotation(Since.class), (Until) field.getAnnotation(Until.class))) || field.isSynthetic()) { return true; } if (this.requireExpose && ((expose = (Expose) field.getAnnotation(Expose.class)) == null || (!z ? expose.deserialize() : expose.serialize()))) { return true; } if ((!this.serializeInnerClasses && isInnerClass(field.getType())) || isAnonymousOrLocal(field.getType())) { return true; } List list = z ? this.serializationStrategies : this.deserializationStrategies; if (list.isEmpty()) { return false; } FieldAttributes fieldAttributes = new FieldAttributes(field); Iterator it = list.iterator(); while (it.hasNext()) { if (it.next().shouldSkipField(fieldAttributes)) { return true; } } return false; } public Excluder excludeFieldsWithoutExposeAnnotation() { Excluder m13clone = m13clone(); m13clone.requireExpose = true; return m13clone; } public Excluder withExclusionStrategy(ExclusionStrategy exclusionStrategy, boolean z, boolean z2) { Excluder m13clone = m13clone(); if (z) { m13clone.serializationStrategies = new ArrayList(this.serializationStrategies); m13clone.serializationStrategies.add(exclusionStrategy); } if (z2) { m13clone.deserializationStrategies = new ArrayList(this.deserializationStrategies); m13clone.deserializationStrategies.add(exclusionStrategy); } return m13clone; } public Excluder withModifiers(int... iArr) { Excluder m13clone = m13clone(); m13clone.modifiers = 0; for (int i : iArr) { m13clone.modifiers = i | m13clone.modifiers; } return m13clone; } public Excluder withVersion(double d) { Excluder m13clone = m13clone(); m13clone.version = d; return m13clone; } /* JADX INFO: Access modifiers changed from: protected */ /* renamed from: clone, reason: merged with bridge method [inline-methods] */ public Excluder m13clone() { try { return (Excluder) super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(e); } } }