JDK-6301085 : (coll) Add Collections.asLifoQueue(Deque)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-07-24
  • Updated: 2017-05-19
  • Resolved: 2005-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b51Fixed
Description
Add Collections.asLifoQueue(Deque)

This method was inadvertently omitted from the CCC for
6192552: Add BlockingDeque to java.util.concurrent

Comments
SUGGESTED FIX /** * Returns a view of a {@link Deque} as a Last-in-first-out (Lifo) * {@link Queue}. Method <tt>add</tt> is mapped to <tt>push</tt>, * <tt>remove</tt> is mapped to <tt>pop</tt> and so on. This * view can be useful when you would like to use a method * requiring a <tt>Queue</tt> but you need Lifo ordering. * @param deque the deque * @return the queue * @since 1.6 */ public static <T> Queue<T> asLifoQueue(Deque<T> deque) { return new AsLIFOQueue<T>(deque); } static class AsLIFOQueue<E> extends AbstractQueue<E> implements Queue<E>, Serializable { private static final long serialVersionUID = 1802017725587941708L; private final Deque<E> q; AsLIFOQueue(Deque<E> q) { this.q = q; } public boolean offer(E e) { return q.offerFirst(e); } public E poll() { return q.pollFirst(); } public E remove() { return q.removeFirst(); } public E peek() { return q.peekFirst(); } public E element() { return q.getFirst(); } public int size() { return q.size(); } public boolean isEmpty() { return q.isEmpty(); } public boolean contains(Object o) { return q.contains(o); } public Iterator<E> iterator() { return q.iterator(); } public Object[] toArray() { return q.toArray(); } public <T> T[] toArray(T[] a) { return q.toArray(a); } public boolean add(E e) { return q.offerFirst(e); } public boolean remove(Object o) { return q.remove(o); } public void clear() { q.clear(); } } }
24-07-2005

EVALUATION A fine idea
24-07-2005