Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public final class RotatingQueue<T> {
  2. private final ConcurrentLinkedDeque<T> queue;
  3.  
  4. public RotatingQueue() {
  5. queue = new ConcurrentLinkedDeque<>();
  6. }
  7.  
  8. public RotatingQueue(T... tees) {
  9. this();
  10. add(tees);
  11. }
  12.  
  13. public RotatingQueue add(T ... objects) {
  14. for (T object : objects) {
  15. queue.add(object);
  16. }
  17. return this;
  18. }
  19.  
  20. public T next() {
  21. T object = queue.pollFirst();
  22. queue.add(object); // Add last again
  23. return object;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement