001/*
002 * Copyright (C) 2009 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 com.google.common.annotations.GwtCompatible;
020import com.google.errorprone.annotations.CanIgnoreReturnValue;
021import java.util.Collection;
022import java.util.Map;
023import java.util.Set;
024import javax.annotation.CheckForNull;
025import org.checkerframework.checker.nullness.qual.Nullable;
026
027/**
028 * A table which forwards all its method calls to another table. Subclasses should override one or
029 * more methods to modify the behavior of the backing map as desired per the <a
030 * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
031 *
032 * @author Gregory Kick
033 * @since 7.0
034 */
035@GwtCompatible
036@ElementTypesAreNonnullByDefault
037public abstract class ForwardingTable<
038        R extends @Nullable Object, C extends @Nullable Object, V extends @Nullable Object>
039    extends ForwardingObject implements Table<R, C, V> {
040  /** Constructor for use by subclasses. */
041  protected ForwardingTable() {}
042
043  @Override
044  protected abstract Table<R, C, V> delegate();
045
046  @Override
047  public Set<Cell<R, C, V>> cellSet() {
048    return delegate().cellSet();
049  }
050
051  @Override
052  public void clear() {
053    delegate().clear();
054  }
055
056  @Override
057  public Map<R, V> column(@ParametricNullness C columnKey) {
058    return delegate().column(columnKey);
059  }
060
061  @Override
062  public Set<C> columnKeySet() {
063    return delegate().columnKeySet();
064  }
065
066  @Override
067  public Map<C, Map<R, V>> columnMap() {
068    return delegate().columnMap();
069  }
070
071  @Override
072  public boolean contains(@CheckForNull Object rowKey, @CheckForNull Object columnKey) {
073    return delegate().contains(rowKey, columnKey);
074  }
075
076  @Override
077  public boolean containsColumn(@CheckForNull Object columnKey) {
078    return delegate().containsColumn(columnKey);
079  }
080
081  @Override
082  public boolean containsRow(@CheckForNull Object rowKey) {
083    return delegate().containsRow(rowKey);
084  }
085
086  @Override
087  public boolean containsValue(@CheckForNull Object value) {
088    return delegate().containsValue(value);
089  }
090
091  @Override
092  @CheckForNull
093  public V get(@CheckForNull Object rowKey, @CheckForNull Object columnKey) {
094    return delegate().get(rowKey, columnKey);
095  }
096
097  @Override
098  public boolean isEmpty() {
099    return delegate().isEmpty();
100  }
101
102  @CanIgnoreReturnValue
103  @Override
104  @CheckForNull
105  public V put(
106      @ParametricNullness R rowKey, @ParametricNullness C columnKey, @ParametricNullness V value) {
107    return delegate().put(rowKey, columnKey, value);
108  }
109
110  @Override
111  public void putAll(Table<? extends R, ? extends C, ? extends V> table) {
112    delegate().putAll(table);
113  }
114
115  @CanIgnoreReturnValue
116  @Override
117  @CheckForNull
118  public V remove(@CheckForNull Object rowKey, @CheckForNull Object columnKey) {
119    return delegate().remove(rowKey, columnKey);
120  }
121
122  @Override
123  public Map<C, V> row(@ParametricNullness R rowKey) {
124    return delegate().row(rowKey);
125  }
126
127  @Override
128  public Set<R> rowKeySet() {
129    return delegate().rowKeySet();
130  }
131
132  @Override
133  public Map<R, Map<C, V>> rowMap() {
134    return delegate().rowMap();
135  }
136
137  @Override
138  public int size() {
139    return delegate().size();
140  }
141
142  @Override
143  public Collection<V> values() {
144    return delegate().values();
145  }
146
147  @Override
148  public boolean equals(@CheckForNull Object obj) {
149    return (obj == this) || delegate().equals(obj);
150  }
151
152  @Override
153  public int hashCode() {
154    return delegate().hashCode();
155  }
156}