From 855dee6478238b7b67a324e975f07e033afd0eab Mon Sep 17 00:00:00 2001
From: Juan Lauer Garrido <juan.lauer_garrido@student.reutlingen-university.de>
Date: Tue, 14 Jun 2022 07:28:07 +0200
Subject: [PATCH] Comments Added

---
 ErzeugerVerbraucher/src/Buffer.java   |  6 +++++-
 ErzeugerVerbraucher/src/Consumer.java | 13 +++++++++++++
 ErzeugerVerbraucher/src/Main.java     |  3 +++
 ErzeugerVerbraucher/src/Producer.java | 12 ++++++++++++
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/ErzeugerVerbraucher/src/Buffer.java b/ErzeugerVerbraucher/src/Buffer.java
index a1101dc..3ab26b2 100644
--- a/ErzeugerVerbraucher/src/Buffer.java
+++ b/ErzeugerVerbraucher/src/Buffer.java
@@ -26,10 +26,13 @@ public class Buffer<T> {
      * @throws IllegalStateException Thrown if pushing would exceed the maximum allowed size
      */
     public void push(T item) throws IllegalStateException {
+
         if (this.itemCount.get() >= this.size) {
             throw new IllegalStateException();
         }
 
+
+
         this.items.set(this.itemCount.get(), item);
         this.itemCount.incrementAndGet();
     }
@@ -37,10 +40,11 @@ public class Buffer<T> {
     /**
      * Pop an item from the Buffer
      * @return The item to be popped
+     *
      * @throws IllegalStateException Thrown if popping would underflow the minimum allowed size
      */
     public T pop() throws IllegalStateException {
-        if (this.itemCount.get() <= 0) {  /// ORIGINAL <1
+        if (this.itemCount.get() <= 0) {
             throw new IllegalStateException();
         }
 
diff --git a/ErzeugerVerbraucher/src/Consumer.java b/ErzeugerVerbraucher/src/Consumer.java
index e576eb8..4cf398c 100644
--- a/ErzeugerVerbraucher/src/Consumer.java
+++ b/ErzeugerVerbraucher/src/Consumer.java
@@ -7,6 +7,13 @@ public class Consumer implements Runnable {
     private final AtomicBoolean asleep;
     private final AtomicBoolean wakeCall;
 
+    /**
+     * Constructor for Consumer data structure
+     * @param buffer Buffer instance for Consumer
+     * @param interval interval of Consumer
+     * @param asleep Boolean for Status
+     * @param wakeCall Boolean for Status
+     */
     public Consumer(Buffer<Car> buffer, int interval, AtomicBoolean asleep, AtomicBoolean wakeCall) {
         this.buffer = buffer;
         this.interval = interval;
@@ -14,6 +21,12 @@ public class Consumer implements Runnable {
         this.wakeCall = wakeCall;
     }
 
+    /**
+     * Run function for the Consumer
+     * This Function checks randomly if the buffer has Cars and Pops them if that is the case.
+     * If the buffer is full it wakens the sleeping consumers.
+     *
+     */
     @Override
     public void run() {
         while(true) {
diff --git a/ErzeugerVerbraucher/src/Main.java b/ErzeugerVerbraucher/src/Main.java
index c842161..755a764 100644
--- a/ErzeugerVerbraucher/src/Main.java
+++ b/ErzeugerVerbraucher/src/Main.java
@@ -1,5 +1,8 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 
+/**
+ * Main to show the functionalities of this Implementation
+ */
 public class Main {
     public static void main(String[] args) {
         Buffer<Car> buffer = new Buffer<>(5);
diff --git a/ErzeugerVerbraucher/src/Producer.java b/ErzeugerVerbraucher/src/Producer.java
index 2f89cf4..716b190 100644
--- a/ErzeugerVerbraucher/src/Producer.java
+++ b/ErzeugerVerbraucher/src/Producer.java
@@ -7,6 +7,13 @@ public class Producer implements Runnable {
     private final AtomicBoolean asleep;
     private final AtomicBoolean wakeCall;
 
+    /**
+     * Constructor for Consumer data structure
+     * @param buffer Buffer instance for Producer
+     * @param interval interval of Consumer
+     * @param asleep Boolean for Status
+     * @param wakeCall Boolean for Status
+     */
     public Producer(Buffer<Car> buffer, int interval, AtomicBoolean asleep, AtomicBoolean wakeCall) {
         this.buffer = buffer;
         this.interval = interval;
@@ -14,6 +21,11 @@ public class Producer implements Runnable {
         this.wakeCall = wakeCall;
     }
 
+    /**
+     * Run Function for the Producer
+     * This function Produces Cars randomly when the Buffer is not full.
+     * If the Buffer is empty it wakens the Sleeping Producers
+     */
     @Override
     public void run() {
         while(true) {
-- 
GitLab