OnJava8-Examples/generics/SimpleQueue.java

15 lines
427 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: generics/SimpleQueue.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
// A different kind of container that is Iterable
import java.util.*;
public class SimpleQueue<T> implements Iterable<T> {
2015-05-05 11:20:13 -07:00
private LinkedList<T> storage = new LinkedList<>();
2015-04-20 15:36:01 -07:00
public void add(T t) { storage.offer(t); }
public T get() { return storage.poll(); }
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public Iterator<T> iterator() {
return storage.iterator();
}
} ///:~