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

package io.netty.util.internal.shaded.org.jctools.queues;

public final class IndexedQueueSizeUtil
{
    public static final int PLAIN_DIVISOR = 1;
    public static final int IGNORE_PARITY_DIVISOR = 2;
    
    public static int size(final IndexedQueue iq, final int divisor) {
        long after = iq.lvConsumerIndex();
        long before;
        long currentProducerIndex;
        do {
            before = after;
            currentProducerIndex = iq.lvProducerIndex();
            after = iq.lvConsumerIndex();
        } while (before != after);
        final long size = (currentProducerIndex - after) / divisor;
        return sanitizedSize(iq.capacity(), size);
    }
    
    public static int sanitizedSize(final int capacity, final long size) {
        if (size < 0L) {
            return 0;
        }
        if (capacity != -1 && size > capacity) {
            return capacity;
        }
        if (size > 2147483647L) {
            return Integer.MAX_VALUE;
        }
        return (int)size;
    }
    
    public static boolean isEmpty(final IndexedQueue iq) {
        return iq.lvConsumerIndex() >= iq.lvProducerIndex();
    }
    
    public interface IndexedQueue
    {
        long lvConsumerIndex();
        
        long lvProducerIndex();
        
        int capacity();
    }
}
