Skip to content

Instantly share code, notes, and snippets.

@njofce
Created March 24, 2020 08:42
Show Gist options
  • Select an option

  • Save njofce/3d2ac1f43ca73d3d892a8a62fe96fe81 to your computer and use it in GitHub Desktop.

Select an option

Save njofce/3d2ac1f43ca73d3d892a8a62fe96fe81 to your computer and use it in GitHub Desktop.
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