Created
March 24, 2020 08:42
-
-
Save njofce/3d2ac1f43ca73d3d892a8a62fe96fe81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Buffer<T> { | |
| List<T> items; | |
| private int capacity; | |
| public Buffer(int capacity){ | |
| this.items = new ArrayList<>(capacity); | |
| this.capacity = capacity; | |
| } | |
| public T getItem() { | |
| T item = null; | |
| if(items.size() > 0) { | |
| item = items.remove(items.size() - 1); | |
| } | |
| return item; | |
| } | |
| public void addItem(T item) { | |
| if(items.size() == capacity) | |
| return; | |
| items.add(item); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment