// Path: src/main/java/com/lmax/disruptor/util/Util.java
// public static long getMinimumSequence(final Sequence[] sequences)
// {
//     long minimum = Long.MAX_VALUE;
// 
//     for (Sequence sequence : sequences)
//     {
//         long value = sequence.get();
//         minimum = minimum < value ? minimum : value;
//     }
// 
//     return minimum;
// }


import com.lmax.disruptor.util.PaddedLong;
import java.util.concurrent.locks.LockSupport;
import static com.lmax.disruptor.util.Util.getMinimumSequence;
/*
 * Copyright 2011 LMAX Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lmax.disruptor;




/**
 * Optimised strategy can be used when there is a single publisher thread claiming sequences.
 *
 * This strategy must <b>not</b> be used when multiple threads are used for publishing concurrently on the same {@link Sequencer}
 */
public final class SingleThreadedClaimStrategy
    implements ClaimStrategy
{
    private final int bufferSize;
    private final PaddedLong minGatingSequence = new PaddedLong(Sequencer.INITIAL_CURSOR_VALUE);
    private final PaddedLong claimSequence = new PaddedLong(Sequencer.INITIAL_CURSOR_VALUE);

    /**
     * Construct a new single threaded publisher {@link ClaimStrategy} for a given buffer size.
     *
     * @param bufferSize for the underlying data structure.
     */
    public SingleThreadedClaimStrategy(final int bufferSize)
    {
        this.bufferSize = bufferSize;
    }

    @Override
    public int getBufferSize()
    {
        return bufferSize;
    }

    @Override
    public long getSequence()
    {
        return claimSequence.get();
    }

    @Override
    public boolean hasAvailableCapacity(final int availableCapacity, final Sequence[] dependentSequences)
    {
        final long wrapPoint = (claimSequence.get() + availableCapacity) - bufferSize;
        if (wrapPoint > minGatingSequence.get())
        {
// Path: src/main/java/com/lmax/disruptor/util/Util.java
// public static long getMinimumSequence(final Sequence[] sequences)
// {
//     long minimum = Long.MAX_VALUE;
// 
//     for (Sequence sequence : sequences)
//     {
//         long value = sequence.get();
//         minimum = minimum < value ? minimum : value;
//     }
// 
//     return minimum;
// }


// Path: src/main/java/com/lmax/disruptor/SingleThreadedClaimStrategy.java
import com.lmax.disruptor.util.PaddedLong;
import java.util.concurrent.locks.LockSupport;
import static com.lmax.disruptor.util.Util.getMinimumSequence;

/*
 * Copyright 2011 LMAX Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lmax.disruptor;




/**
 * Optimised strategy can be used when there is a single publisher thread claiming sequences.
 *
 * This strategy must <b>not</b> be used when multiple threads are used for publishing concurrently on the same {@link Sequencer}
 */
public final class SingleThreadedClaimStrategy
    implements ClaimStrategy
{
    private final int bufferSize;
    private final PaddedLong minGatingSequence = new PaddedLong(Sequencer.INITIAL_CURSOR_VALUE);
    private final PaddedLong claimSequence = new PaddedLong(Sequencer.INITIAL_CURSOR_VALUE);

    /**
     * Construct a new single threaded publisher {@link ClaimStrategy} for a given buffer size.
     *
     * @param bufferSize for the underlying data structure.
     */
    public SingleThreadedClaimStrategy(final int bufferSize)
    {
        this.bufferSize = bufferSize;
    }

    @Override
    public int getBufferSize()
    {
        return bufferSize;
    }

    @Override
    public long getSequence()
    {
        return claimSequence.get();
    }

    @Override
    public boolean hasAvailableCapacity(final int availableCapacity, final Sequence[] dependentSequences)
    {
        final long wrapPoint = (claimSequence.get() + availableCapacity) - bufferSize;
        if (wrapPoint > minGatingSequence.get())
        {
            long minSequence = getMinimumSequence(dependentSequences);