    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.collections4.queue;
    018
    019import java.util.Queue;
    020
    021import org.apache.commons.collections4.collection.AbstractCollectionDecorator;
    022
    023/**
    024 * Decorates another {@link Queue} to provide additional behaviour.
    025 * <p>
    026 * Methods are forwarded directly to the decorated queue.
    027 * <p>
    028 * This implementation does not forward the hashCode and equals methods through
    029 * to the backing object, but relies on Object's implementation. This is
    030 * necessary as some Queue implementations, e.g. LinkedList, have custom a
    031 * equals implementation for which symmetry can not be preserved.
    032 * See class javadoc of AbstractCollectionDecorator for more information.
    033 *
    034 * @param <E> the type of the elements in the queue
    035 * @since 4.0
    036 */
    037public abstract class AbstractQueueDecorator<E> extends AbstractCollectionDecorator<E>
    038        implements Queue<E> {
    039
    040    /** Serialization version */
    041    private static final long serialVersionUID = -2629815475789577029L;
    042
    043    /**
    044     * Constructor only used in deserialization, do not use otherwise.
    045     */
    046    protected AbstractQueueDecorator() {
    047        super();
    048    }
    049
    050    /**
    051     * Constructor that wraps (not copies).
    052     *
    053     * @param queue  the queue to decorate, must not be null
    054     * @throws NullPointerException if queue is null
    055     */
    056    protected AbstractQueueDecorator(final Queue<E> queue) {
    057        super(queue);
    058    }
    059
    060    /**
    061     * Gets the queue being decorated.
    062     *
    063     * @return the decorated queue
    064     */
    065    @Override
    066    protected Queue<E> decorated() {
    067        return (Queue<E>) super.decorated();
    068    }
    069
    070    //-----------------------------------------------------------------------
    071
    072    @Override
    073    public boolean offer(final E obj) {
    074        return decorated().offer(obj);
    075    }
    076
    077    @Override
    078    public E poll() {
    079        return decorated().poll();
    080    }
    081
    082    @Override
    083    public E peek() {
    084        return decorated().peek();
    085    }
    086
    087    @Override
    088    public E element() {
    089        return decorated().element();
    090    }
    091
    092    @Override
    093    public E remove() {
    094        return decorated().remove();
    095    }
    096
    097}