001 /*
002 * Copyright (C) 2007 Google Inc.
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
017 package com.google.common.collect;
018
019 import com.google.common.annotations.GwtCompatible;
020
021 import java.util.Collection;
022 import java.util.Iterator;
023
024 /**
025 * A collection which forwards all its method calls to another collection.
026 * Subclasses should override one or more methods to modify the behavior of
027 * the backing collection as desired per the <a
028 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
029 *
030 * @author Kevin Bourrillion
031 * @since 2 (imported from Google Collections Library)
032 */
033 @GwtCompatible
034 public abstract class ForwardingCollection<E> extends ForwardingObject
035 implements Collection<E> {
036
037 /** Constructor for use by subclasses. */
038 protected ForwardingCollection() {}
039
040 @Override protected abstract Collection<E> delegate();
041
042 public Iterator<E> iterator() {
043 return delegate().iterator();
044 }
045
046 public int size() {
047 return delegate().size();
048 }
049
050 public boolean removeAll(Collection<?> collection) {
051 return delegate().removeAll(collection);
052 }
053
054 public boolean isEmpty() {
055 return delegate().isEmpty();
056 }
057
058 public boolean contains(Object object) {
059 return delegate().contains(object);
060 }
061
062 public Object[] toArray() {
063 return delegate().toArray();
064 }
065
066 public <T> T[] toArray(T[] array) {
067 return delegate().toArray(array);
068 }
069
070 public boolean add(E element) {
071 return delegate().add(element);
072 }
073
074 public boolean remove(Object object) {
075 return delegate().remove(object);
076 }
077
078 public boolean containsAll(Collection<?> collection) {
079 return delegate().containsAll(collection);
080 }
081
082 public boolean addAll(Collection<? extends E> collection) {
083 return delegate().addAll(collection);
084 }
085
086 public boolean retainAll(Collection<?> collection) {
087 return delegate().retainAll(collection);
088 }
089
090 public void clear() {
091 delegate().clear();
092 }
093 }