io.microsphere.collection.AbstractDeque Maven / Gradle / Ivy
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.microsphere.collection;
import java.util.AbstractQueue;
import java.util.Deque;
import java.util.NoSuchElementException;
/**
* Abstract {@link Deque}
*
* @param The elements' type
* @author Mercy
* @since 1.0.0
*/
public abstract class AbstractDeque extends AbstractQueue implements Deque {
@Override
public void addFirst(E e) {
if (!offerFirst(e))
throw new IllegalStateException("Queue full");
}
@Override
public void addLast(E e) {
if (!offerLast(e))
throw new IllegalStateException("Queue full");
}
@Override
public E removeFirst() {
E x = pollFirst();
if (x != null)
return x;
else
throw new NoSuchElementException();
}
@Override
public E removeLast() {
E x = pollLast();
if (x != null)
return x;
else
throw new NoSuchElementException();
}
@Override
public E peekFirst() {
return getFirst();
}
@Override
public E peekLast() {
return getLast();
}
@Override
public boolean removeFirstOccurrence(Object o) {
return remove(o);
}
@Override
public void push(E e) {
addFirst(e);
}
@Override
public E pop() {
return removeFirst();
}
@Override
public boolean offer(E e) {
return offerLast(e);
}
@Override
public E poll() {
return pollFirst();
}
@Override
public E peek() {
return peekFirst();
}
}