package com.greensnow25.patternProducerCostumer;

import javax.jws.soap.SOAPBinding;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Public class UsefulWork.
 *
 * @author greensnow25.
 * @version 1.
 * @since 07.07.2017.
 */
public class MyBlockigQueue<E> {
    /**
     * Blocking queue.
     */
    private List<E> queue;
    /**
     * Queue capacity.
     */
    private static final int CAPACITY = 10;

    /**
     * constructor.
     */
    public MyBlockigQueue() {
        this.queue = new ArrayList(CAPACITY);
    }

    /**
     * put number to the queue.
     *
     * @param e number.
     * @throws InterruptedException ex.
     */
    public void put(E e) throws InterruptedException {
        synchronized (queue) {
            while (queue.size() == CAPACITY) {
                queue.wait();
            }
            queue.add(e);
            System.out.printf("%s  %d%s", "PUT number:", e, System.getProperty("line.separator"));
            queue.notify();
        }
    }

    /**
     * get number from the queue.
     *
     * @throws InterruptedException ex.
     */
    public void get() throws InterruptedException {
        synchronized (queue) {
            while (queue.size() == 0) {
                queue.wait();
            }
            E e = queue.remove(0);
            System.out.printf("%s  %d%s", "GET number:", e, System.getProperty("line.separator"));
            queue.notify();
        }
    }

//    /**
//     * Checks the values ​​on not null.
//     *
//     * @return the number of non null objects.
//     */
//    public int checkNotNull() {
//        int count = 0;
//        for (Integer i : queue) {
//            if (i != null) {
//                count++;
//            } else break;
//        }
//        return count;
//    }
}

@@ -1536,351 +1536,6 @@
  %7D%0A%0A
-//    /**%0A//     * Checks the values %E2%80%8B%E2%80%8Bon not null.%0A//     *%0A//     * @return the number of non null objects.%0A//     */%0A//    public int checkNotNull() %7B%0A//        int count = 0;%0A//        for (Integer i : queue) %7B%0A//            if (i != null) %7B%0A//                count++;%0A//            %7D else break;%0A//        %7D%0A//        return count;%0A//    %7D%0A
 %7D%0A

Update date 24.07.2017