// 
// Decompiled by Procyon v0.6.0
// 

package io.sentry;

import java.util.Iterator;
import io.sentry.util.AutoClosableReentrantLock;
import java.io.Serializable;
import java.util.Collection;

class SynchronizedCollection<E> implements Collection<E>, Serializable
{
    private static final long serialVersionUID = 2412805092710877986L;
    private final Collection<E> collection;
    final AutoClosableReentrantLock lock;
    
    public static <T> SynchronizedCollection<T> synchronizedCollection(final Collection<T> coll) {
        return new SynchronizedCollection<T>(coll);
    }
    
    SynchronizedCollection(final Collection<E> collection) {
        if (collection == null) {
            throw new NullPointerException("Collection must not be null.");
        }
        this.collection = collection;
        this.lock = new AutoClosableReentrantLock();
    }
    
    SynchronizedCollection(final Collection<E> collection, final AutoClosableReentrantLock lock) {
        if (collection == null) {
            throw new NullPointerException("Collection must not be null.");
        }
        if (lock == null) {
            throw new NullPointerException("Lock must not be null.");
        }
        this.collection = collection;
        this.lock = lock;
    }
    
    protected Collection<E> decorated() {
        return this.collection;
    }
    
    @Override
    public boolean add(final E object) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().add(object);
        }
    }
    
    @Override
    public boolean addAll(final Collection<? extends E> coll) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().addAll(coll);
        }
    }
    
    @Override
    public void clear() {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            this.decorated().clear();
        }
    }
    
    @Override
    public boolean contains(final Object object) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().contains(object);
        }
    }
    
    @Override
    public boolean containsAll(final Collection<?> coll) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().containsAll(coll);
        }
    }
    
    @Override
    public boolean isEmpty() {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().isEmpty();
        }
    }
    
    @Override
    public Iterator<E> iterator() {
        return this.decorated().iterator();
    }
    
    @Override
    public Object[] toArray() {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().toArray();
        }
    }
    
    @Override
    public <T> T[] toArray(final T[] object) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().toArray(object);
        }
    }
    
    @Override
    public boolean remove(final Object object) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().remove(object);
        }
    }
    
    @Override
    public boolean removeAll(final Collection<?> coll) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().removeAll(coll);
        }
    }
    
    @Override
    public boolean retainAll(final Collection<?> coll) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().retainAll(coll);
        }
    }
    
    @Override
    public int size() {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().size();
        }
    }
    
    @Override
    public boolean equals(final Object object) {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            if (object == this) {
                try (final ISentryLifecycleToken ignored = (ISentryLifecycleToken)true) {}
                return;
            }
            return object == this || this.decorated().equals(object);
        }
    }
    
    @Override
    public int hashCode() {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().hashCode();
        }
    }
    
    @Override
    public String toString() {
        try (final ISentryLifecycleToken ignored = this.lock.acquire()) {
            return this.decorated().toString();
        }
    }
}
