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

package com.hypixel.hytale.common.collection;

import java.util.Collection;
import java.util.Arrays;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import javax.annotation.Nonnull;
import java.util.List;

public class BucketItemPool<E>
{
    @Nonnull
    protected final List<BucketItem<E>> pool;
    
    public BucketItemPool() {
        this.pool = new ObjectArrayList<BucketItem<E>>();
    }
    
    public void deallocate(final BucketItem<E>[] entityHolders, final int count) {
        this.pool.addAll(Arrays.asList(entityHolders).subList(0, count));
    }
    
    public BucketItem<E> allocate(final E reference, final double squaredDistance) {
        final int l = this.pool.size();
        final BucketItem<E> holder = (l == 0) ? new BucketItem<E>() : this.pool.remove(l - 1);
        return holder.set(reference, squaredDistance);
    }
}
