package ru.job4j;

import net.jcip.annotations.GuardedBy;
import net.jcip.annotations.ThreadSafe;

import java.util.LinkedList;
import java.util.Queue;

@ThreadSafe
public class SimpleBlockingQueue<E> {
    private Queue<E> queue = new LinkedList<>();
    private final Integer maxSize = 10;
    private Integer size = 0;
    private final Object lockProd = new Object();
    private final Object lockCons = new Object();

    public Integer getSize() {
        return size;
    }

    public void offer(E value) throws InterruptedException {
        synchronized(this.lockProd) {
            synchronized (this.lockCons) {
                while (maxSize <= this.size) {
                    lockProd.wait();
                }
                queue.offer(value);
                this.size++;
                lockCons.notify();
            }
        }
    }

    public E peek() throws InterruptedException {
        synchronized(this.lockCons) {
            synchronized (this.lockProd) {
                while (0 >= this.size) {
                    lockCons.wait();
                }
                E value = queue.peek();
                this.size--;
                lockProd.notify();
                return value;
            }
        }
    }

}

@@ -348,62 +348,8 @@
 lock
-Prod = new Object();%0A    private final Object lockCons
  = n
@@ -361,16 +361,16 @@
 ject();%0A
+
 %0A    pub
@@ -516,55 +516,8 @@
 lock
-Prod) %7B%0A            synchronized (this.lockCons
 ) %7B%0A
@@ -587,20 +587,16 @@
     lock
-Prod
 .wait();
@@ -699,20 +699,16 @@
     lock
-Cons
 .notify(
@@ -710,29 +710,16 @@
 tify();%0A
-            %7D
 %0A       
@@ -808,20 +808,16 @@
 his.lock
-Cons
 ) %7B%0A    
@@ -847,20 +847,16 @@
 his.lock
-Prod
 ) %7B%0A    
@@ -920,12 +920,8 @@
 lock
-Cons
 .wai
@@ -1012,16 +1012,16 @@
 size--;%0A
+
         
@@ -1036,12 +1036,8 @@
 lock
-Prod
 .not

task 1098.01