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

package io.sentry.cache.tape;

import java.io.OutputStream;
import java.util.Iterator;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.ApiStatus;
import java.io.Closeable;

@ApiStatus.Internal
public abstract class ObjectQueue<T> implements Iterable<T>, Closeable
{
    public static <T> ObjectQueue<T> create(final QueueFile qf, final Converter<T> converter) {
        return new FileObjectQueue<T>(qf, converter);
    }
    
    public static <T> ObjectQueue<T> createEmpty() {
        return new EmptyObjectQueue<T>();
    }
    
    @Nullable
    public abstract QueueFile file();
    
    public abstract int size();
    
    public boolean isEmpty() {
        return this.size() == 0;
    }
    
    public abstract void add(final T p0) throws IOException;
    
    @Nullable
    public abstract T peek() throws IOException;
    
    public List<T> peek(final int max) throws IOException {
        final int end = Math.min(max, this.size());
        final List<T> subList = new ArrayList<T>(end);
        final Iterator<T> iterator = this.iterator();
        for (int i = 0; i < end; ++i) {
            subList.add(iterator.next());
        }
        return Collections.unmodifiableList((List<? extends T>)subList);
    }
    
    public List<T> asList() throws IOException {
        return this.peek(this.size());
    }
    
    public void remove() throws IOException {
        this.remove(1);
    }
    
    public abstract void remove(final int p0) throws IOException;
    
    public void clear() throws IOException {
        this.remove(this.size());
    }
    
    public interface Converter<T>
    {
        @Nullable
        T from(final byte[] p0) throws IOException;
        
        void toStream(final T p0, final OutputStream p1) throws IOException;
    }
}
