blob: 041d4e42317d432c4efbe64026950e9700de271b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2015 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Contributors:
* Oracle - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.common.utility.internal.queue;
import java.io.Serializable;
import org.eclipse.jpt.common.utility.deque.Deque;
import org.eclipse.jpt.common.utility.queue.Queue;
/**
* Adapt a {@link Deque} to the {@link Queue} interface.
* Elements are dequeued from the head of the deque and
* enqueued to the tail of the deque.
* @param <E> the type of elements maintained by the queue
* @see QueueTools
*/
public class DequeQueue<E>
implements Queue<E>, Serializable
{
private Deque<E> deque;
private static final long serialVersionUID = 1L;
// ********** constructors **********
/**
* Construct a queue, adapting the specified deque.
* Elements are dequeued from the head of the deque and
* enqueued to the tail of the deque.
*/
public DequeQueue(Deque<E> deque) {
super();
this.deque = deque;
}
// ********** Queue implementation **********
public void enqueue(E element) {
this.deque.enqueueTail(element);
}
public E dequeue() {
return this.deque.dequeueHead();
}
public E peek() {
return this.deque.peekHead();
}
public boolean isEmpty() {
return this.deque.isEmpty();
}
// ********** standard methods **********
@Override
public String toString() {
return this.deque.toString();
}
}