package com.github.mustachejava.reflect.guards;

import com.github.mustachejava.reflect.Guard;
import java.util.List;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class ClassGuard implements Guard {
    protected final Class classGuard;
    protected final int scopeIndex;

    public ClassGuard(int i, Object obj) {
        this.scopeIndex = i;
        this.classGuard = obj == null ? null : obj.getClass();
    }

    public int hashCode() {
        Class cls = this.classGuard;
        if (cls == null) {
            return 0;
        }
        return cls.hashCode();
    }

    public boolean equals(Object obj) {
        if (obj instanceof ClassGuard) {
            return Objects.equals(this.classGuard, ((ClassGuard) obj).classGuard);
        }
        return false;
    }

    @Override // com.github.mustachejava.reflect.Guard
    public boolean apply(List<Object> list) {
        if (list == null) {
            return false;
        }
        int size = list.size();
        int i = this.scopeIndex;
        if (size <= i) {
            return false;
        }
        Object obj = list.get(i);
        if (obj == null || this.classGuard == obj.getClass()) {
            return obj != null || this.classGuard == null;
        }
        return false;
    }

    public String toString() {
        return "[ClassGuard: " + this.scopeIndex + " " + this.classGuard.getName() + "]";
    }
}
