1/*
2 * Copyright (C) 2009 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.collect;
18
19import java.util.Collection;
20import java.util.Collections;
21import java.util.Set;
22
23import javax.annotation.Nullable;
24
25/**
26 * GWT implementation of {@link ImmutableSet} that forwards to another {@code Set} implementation.
27 *
28 * @author Hayward Chan
29 */
30@SuppressWarnings("serial")  // Serialization only done in GWT.
31public abstract class ForwardingImmutableSet<E> extends ImmutableSet<E> {
32  private final transient Set<E> delegate;
33
34  ForwardingImmutableSet(Set<E> delegate) {
35    // TODO(cpovirk): are we over-wrapping?
36    this.delegate = Collections.unmodifiableSet(delegate);
37  }
38
39  @Override public UnmodifiableIterator<E> iterator() {
40    return Iterators.unmodifiableIterator(delegate.iterator());
41  }
42
43  @Override public boolean contains(@Nullable Object object) {
44    return object != null && delegate.contains(object);
45  }
46
47  @Override public boolean containsAll(Collection<?> targets) {
48    return delegate.containsAll(targets);
49  }
50
51  @Override public int size() {
52    return delegate.size();
53  }
54
55  @Override public boolean isEmpty() {
56    return delegate.isEmpty();
57  }
58
59  @Override public Object[] toArray() {
60    return delegate.toArray();
61  }
62
63  @Override public <T> T[] toArray(T[] other) {
64    return delegate.toArray(other);
65  }
66
67  @Override public String toString() {
68    return delegate.toString();
69  }
70
71  // TODO(cpovirk): equals(), as well, in case it's any faster than Sets.equalsImpl?
72
73  @Override public int hashCode() {
74    return delegate.hashCode();
75  }
76}
77