001/*
002 * Copyright (C) 2012 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect;
018
019import java.util.Deque;
020import java.util.Iterator;
021
022/**
023 * A deque which forwards all its method calls to another deque. Subclasses
024 * should override one or more methods to modify the behavior of the backing
025 * deque as desired per the <a
026 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
027 *
028 * <p><b>Warning:</b> The methods of {@code ForwardingDeque} forward
029 * <b>indiscriminately</b> to the methods of the delegate. For example,
030 * overriding {@link #add} alone <b>will not</b> change the behavior of {@link
031 * #offer} which can lead to unexpected behavior. In this case, you should
032 * override {@code offer} as well.
033 *
034 * @author Kurt Alfred Kluever
035 * @since 12.0
036 */
037public abstract class ForwardingDeque<E> extends ForwardingQueue<E> implements Deque<E> {
038
039  /** Constructor for use by subclasses. */
040  protected ForwardingDeque() {}
041
042  @Override
043  protected abstract Deque<E> delegate();
044
045  @Override
046  public void addFirst(E e) {
047    delegate().addFirst(e);
048  }
049
050  @Override
051  public void addLast(E e) {
052    delegate().addLast(e);
053  }
054
055  @Override
056  public Iterator<E> descendingIterator() {
057    return delegate().descendingIterator();
058  }
059
060  @Override
061  public E getFirst() {
062    return delegate().getFirst();
063  }
064
065  @Override
066  public E getLast() {
067    return delegate().getLast();
068  }
069
070  @Override
071  public boolean offerFirst(E e) {
072    return delegate().offerFirst(e);
073  }
074
075  @Override
076  public boolean offerLast(E e) {
077    return delegate().offerLast(e);
078  }
079
080  @Override
081  public E peekFirst() {
082    return delegate().peekFirst();
083  }
084
085  @Override
086  public E peekLast() {
087    return delegate().peekLast();
088  }
089
090  @Override
091  public E pollFirst() {
092    return delegate().pollFirst();
093  }
094
095  @Override
096  public E pollLast() {
097    return delegate().pollLast();
098  }
099
100  @Override
101  public E pop() {
102    return delegate().pop();
103  }
104
105  @Override
106  public void push(E e) {
107    delegate().push(e);
108  }
109
110  @Override
111  public E removeFirst() {
112    return delegate().removeFirst();
113  }
114
115  @Override
116  public E removeLast() {
117    return delegate().removeLast();
118  }
119
120  @Override
121  public boolean removeFirstOccurrence(Object o) {
122    return delegate().removeFirstOccurrence(o);
123  }
124
125  @Override
126  public boolean removeLastOccurrence(Object o) {
127    return delegate().removeLastOccurrence(o);
128  }
129}