package com.bytedance.ugc.ugcwidget;

import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class UGCSafeList<T> implements Collection<T> {
    public ArrayList<T> copy;
    public final ArrayList<T> list = new ArrayList<>();

    static {
        Covode.recordClassIndex(39816);
    }

    public boolean isEmpty() {
        return this.list.isEmpty();
    }

    public int size() {
        return this.list.size();
    }

    public Object[] toArray() {
        return this.list.toArray();
    }

    public void clear() {
        this.list.clear();
        this.copy = null;
    }

    public Iterator<T> iterator() {
        ArrayList<T> arrayList = this.copy;
        if (arrayList == null) {
            arrayList = new ArrayList<>(this.list);
            this.copy = arrayList;
        }
        return arrayList.iterator();
    }

    public boolean contains(Object obj) {
        return this.list.contains(obj);
    }

    public boolean add(T t) {
        boolean add = this.list.add(t);
        this.copy = null;
        return add;
    }

    public boolean containsAll(Collection<?> collection) {
        if (collection == null || !this.list.containsAll(collection)) {
            return false;
        }
        return true;
    }

    public boolean remove(Object obj) {
        boolean remove = this.list.remove(obj);
        this.copy = null;
        return remove;
    }

    public <T1> T1[] toArray(T1[] t1Arr) {
        return this.list.toArray(t1Arr);
    }

    public boolean addAll(Collection<? extends T> collection) {
        boolean z;
        if (collection == null || !this.list.addAll(collection)) {
            z = false;
        } else {
            z = true;
        }
        this.copy = null;
        return z;
    }

    public boolean removeAll(Collection<?> collection) {
        boolean z;
        if (collection == null || !this.list.removeAll(collection)) {
            z = false;
        } else {
            z = true;
        }
        this.copy = null;
        return z;
    }

    public boolean retainAll(Collection<?> collection) {
        boolean z;
        if (collection == null || !this.list.retainAll(collection)) {
            z = false;
        } else {
            z = true;
        }
        this.copy = null;
        return z;
    }
}
