-
Notifications
You must be signed in to change notification settings - Fork 31
Muraveva_A_B_queue #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "Muraveva_A_B_pra\u0441_6"
Muraveva_A_B_queue #140
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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(); | ||||||
| } | ||||||
| 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(); | ||||||
|
||||||
| throw new NullPointerException(); | |
| throw new NullPointerException("item must not be null"); |
Copilot
AI
Mar 20, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.