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