    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 behavior.
    025 * <p>
    026 * Methods are forwarded directly to the decorated queue.
    027 * </p>
    028 * <p>
    029 * This implementation does not forward the hashCode and equals methods through
    030 * to the backing object, but relies on Object's implementation. This is
    031 * necessary as some Queue implementations, e.g. LinkedList, have a custom
    032 * equals implementation for which symmetry can not be preserved.
    033 * See class Javadoc of AbstractCollectionDecorator for more information.
    034 * </p>
    035 *
    036 * @param <E> the type of the elements in the queue
    037 * @since 4.0
    038 */
    039public abstract class AbstractQueueDecorator<E> extends AbstractCollectionDecorator<E>
    040        implements Queue<E> {
    041
    042    /** Serialization version */
    043    private static final long serialVersionUID = -2629815475789577029L;
    044
    045    /**
    046     * Constructor only used in deserialization, do not use otherwise.
    047     */
    048    protected AbstractQueueDecorator() {
    049    }
    050
    051    /**
    052     * Constructor that wraps (not copies).
    053     *
    054     * @param queue  the queue to decorate, must not be null
    055     * @throws NullPointerException if queue is null
    056     */
    057    protected AbstractQueueDecorator(final Queue<E> queue) {
    058        super(queue);
    059    }
    060
    061    /**
    062     * Gets the queue being decorated.
    063     *
    064     * @return the decorated queue
    065     */
    066    @Override
    067    protected Queue<E> decorated() {
    068        return (Queue<E>) super.decorated();
    069    }
    070
    071    @Override
    072    public E element() {
    073        return decorated().element();
    074    }
    075
    076    @Override
    077    public boolean offer(final E obj) {
    078        return decorated().offer(obj);
    079    }
    080
    081    @Override
    082    public E peek() {
    083        return decorated().peek();
    084    }
    085
    086    @Override
    087    public E poll() {
    088        return decorated().poll();
    089    }
    090
    091    @Override
    092    public E remove() {
    093        return decorated().remove();
    094    }
    095
    096}