Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
package hse.java.lectures.lecture6.tasks.queue;

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

public class BoundedBlockingQueue<T> {

private final int capacity;
private final Queue<T> queue;

public BoundedBlockingQueue(int capacity) {

if (capacity <= 0) {
throw new IllegalArgumentException();
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing IllegalArgumentException without a message makes it harder to debug invalid usage (e.g., when capacity <= 0). Consider including a short, descriptive message indicating the expected constraint.

Suggested change
throw new IllegalArgumentException();
throw new IllegalArgumentException("capacity must be greater than 0: " + capacity);

Copilot uses AI. Check for mistakes.
}
this.capacity = capacity;
this.queue = new LinkedList<>();
}

public void put(T item) throws InterruptedException {

public synchronized void put(T item) throws InterruptedException {
if (item == null) {
throw new NullPointerException();
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing NullPointerException without a message makes it harder to diagnose which argument was null at call sites. Consider adding a brief message (or using a helper like Objects.requireNonNull) to clarify what was expected.

Suggested change
throw new NullPointerException();
throw new NullPointerException("item must not be null");

Copilot uses AI. Check for mistakes.
}
while (queue.size() == capacity) {
wait();
}
queue.add(item);
notifyAll();
}

public T take() throws InterruptedException {
return null;
public synchronized T take() throws InterruptedException {
while (queue.isEmpty()) {
wait();
}
T item = queue.poll();
notifyAll();
return item;
Comment on lines +19 to +36
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no unit tests covering the blocking/interrupt behavior of this queue implementation (e.g., put blocks when full, take blocks when empty, FIFO ordering, and interruption while waiting). Given the concurrency semantics, adding JUnit tests would help prevent regressions and validate the task requirements.

Copilot uses AI. Check for mistakes.
}

public int size() {
return 0;
public synchronized int size() {
return queue.size();
}

public int capacity() {
return 0;
return capacity;
}
}
}
Loading