// Path: app/src/mixedbit/speechtrainer/Assertions.java
// public class Assertions {
// 
//     public static void check(boolean shouldBeTrue) {
//         if (shouldBeTrue == false) {
//             throw new AssertionError();
//         }
//     }
// 
//     public static void illegalStateIfFalse(boolean shouldBeTrue) {
//         if (shouldBeTrue == false) {
//             throw new IllegalStateException();
//         }
//     }
// 
//     public static void illegalStateIfFalse(boolean shouldBeTrue, String errorMessage) {
//         if (shouldBeTrue == false) {
//             throw new IllegalStateException(errorMessage);
//         }
//     }
// }


import java.util.concurrent.ConcurrentLinkedQueue;
import mixedbit.speechtrainer.Assertions;
     */
    public AudioBuffer allocateAudioBuffer() {
        final AudioBuffer buffer = availableBuffers.poll();
        if (buffer != null) {
            buffer.setAudioBufferId(nextAudioBufferId);
            ++nextAudioBufferId;
            buffer.changeStateTo(BufferState.ALLOCATED);
        }
        return buffer;
    }

    /**
     * Releases an audio buffer. The caller returns the ownership of the buffer
     * to the {@link AudioBufferAllocator} and can not use the buffer anymore.
     * Calling any method on a released buffer is forbidden.
     */
    public void releaseAudioBuffer(AudioBuffer audioBuffer) {
        audioBuffer.checkStateIs(BufferState.ALLOCATED);
        // Clear audio data of the released buffer.
        audioBuffer.audioDataStored(0);
        audioBuffer.changeStateTo(BufferState.AVAILABLE);
        availableBuffers.add(audioBuffer);
    }

    /**
     * Sanity check that can be executed by a user in places where all buffers
     * should be released and available for allocation. Helps to ensure audio
     * buffers do not leak.
     */
    public void assertAllAudioBuffersAvailable() {
// Path: app/src/mixedbit/speechtrainer/Assertions.java
// public class Assertions {
// 
//     public static void check(boolean shouldBeTrue) {
//         if (shouldBeTrue == false) {
//             throw new AssertionError();
//         }
//     }
// 
//     public static void illegalStateIfFalse(boolean shouldBeTrue) {
//         if (shouldBeTrue == false) {
//             throw new IllegalStateException();
//         }
//     }
// 
//     public static void illegalStateIfFalse(boolean shouldBeTrue, String errorMessage) {
//         if (shouldBeTrue == false) {
//             throw new IllegalStateException(errorMessage);
//         }
//     }
// }


// Path: app/src/mixedbit/speechtrainer/controller/AudioBufferAllocator.java
import java.util.concurrent.ConcurrentLinkedQueue;
import mixedbit.speechtrainer.Assertions;

     */
    public AudioBuffer allocateAudioBuffer() {
        final AudioBuffer buffer = availableBuffers.poll();
        if (buffer != null) {
            buffer.setAudioBufferId(nextAudioBufferId);
            ++nextAudioBufferId;
            buffer.changeStateTo(BufferState.ALLOCATED);
        }
        return buffer;
    }

    /**
     * Releases an audio buffer. The caller returns the ownership of the buffer
     * to the {@link AudioBufferAllocator} and can not use the buffer anymore.
     * Calling any method on a released buffer is forbidden.
     */
    public void releaseAudioBuffer(AudioBuffer audioBuffer) {
        audioBuffer.checkStateIs(BufferState.ALLOCATED);
        // Clear audio data of the released buffer.
        audioBuffer.audioDataStored(0);
        audioBuffer.changeStateTo(BufferState.AVAILABLE);
        availableBuffers.add(audioBuffer);
    }

    /**
     * Sanity check that can be executed by a user in places where all buffers
     * should be released and available for allocation. Helps to ensure audio
     * buffers do not leak.
     */
    public void assertAllAudioBuffersAvailable() {
        Assertions.check(this.numberOfBuffers == availableBuffers.size());