summaryrefslogtreecommitdiffstats
path: root/guava/src/com/google/common/collect/ForwardingSet.java
diff options
context:
space:
mode:
authorYohann Roussel <yroussel@google.com>2014-03-19 16:25:37 +0100
committerYohann Roussel <yroussel@google.com>2014-03-20 15:13:33 +0100
commit4eceb95409e844fdc33c9c706e1dc307bfd40303 (patch)
treeee9f4f3fc79f757c79081c336bce4f1782c6ccd8 /guava/src/com/google/common/collect/ForwardingSet.java
parent3d2402901b1a6462e2cf47a6fd09711f327961c3 (diff)
downloadtoolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.zip
toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.gz
toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.bz2
Initial Jack import.
Change-Id: I953cf0a520195a7187d791b2885848ad0d5a9b43
Diffstat (limited to 'guava/src/com/google/common/collect/ForwardingSet.java')
-rw-r--r--guava/src/com/google/common/collect/ForwardingSet.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/guava/src/com/google/common/collect/ForwardingSet.java b/guava/src/com/google/common/collect/ForwardingSet.java
new file mode 100644
index 0000000..ef4b343
--- /dev/null
+++ b/guava/src/com/google/common/collect/ForwardingSet.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2007 The Guava Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.common.collect;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.annotations.GwtCompatible;
+
+import java.util.Collection;
+import java.util.Set;
+
+import javax.annotation.Nullable;
+
+/**
+ * A set which forwards all its method calls to another set. Subclasses should
+ * override one or more methods to modify the behavior of the backing set as
+ * desired per the <a
+ * href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator pattern</a>.
+ *
+ * <p><b>Warning:</b> The methods of {@code ForwardingSet} forward
+ * <b>indiscriminately</b> to the methods of the delegate. For example,
+ * overriding {@link #add} alone <b>will not</b> change the behavior of {@link
+ * #addAll}, which can lead to unexpected behavior. In this case, you should
+ * override {@code addAll} as well, either providing your own implementation, or
+ * delegating to the provided {@code standardAddAll} method.
+ *
+ * <p>The {@code standard} methods are not guaranteed to be thread-safe, even
+ * when all of the methods that they depend on are thread-safe.
+ *
+ * @author Kevin Bourrillion
+ * @author Louis Wasserman
+ * @since 2.0 (imported from Google Collections Library)
+ */
+@GwtCompatible
+public abstract class ForwardingSet<E> extends ForwardingCollection<E>
+ implements Set<E> {
+ // TODO(user): identify places where thread safety is actually lost
+
+ /** Constructor for use by subclasses. */
+ protected ForwardingSet() {}
+
+ @Override protected abstract Set<E> delegate();
+
+ @Override public boolean equals(@Nullable Object object) {
+ return object == this || delegate().equals(object);
+ }
+
+ @Override public int hashCode() {
+ return delegate().hashCode();
+ }
+
+ /**
+ * A sensible definition of {@link #removeAll} in terms of {@link #iterator}
+ * and {@link #remove}. If you override {@code iterator} or {@code remove},
+ * you may wish to override {@link #removeAll} to forward to this
+ * implementation.
+ *
+ * @since 7.0 (this version overrides the {@code ForwardingCollection} version as of 12.0)
+ */
+ @Override
+ protected boolean standardRemoveAll(Collection<?> collection) {
+ return Sets.removeAllImpl(this, checkNotNull(collection)); // for GWT
+ }
+
+ /**
+ * A sensible definition of {@link #equals} in terms of {@link #size} and
+ * {@link #containsAll}. If you override either of those methods, you may wish
+ * to override {@link #equals} to forward to this implementation.
+ *
+ * @since 7.0
+ */
+ @Beta protected boolean standardEquals(@Nullable Object object) {
+ return Sets.equalsImpl(this, object);
+ }
+
+ /**
+ * A sensible definition of {@link #hashCode} in terms of {@link #iterator}.
+ * If you override {@link #iterator}, you may wish to override {@link #equals}
+ * to forward to this implementation.
+ *
+ * @since 7.0
+ */
+ @Beta protected int standardHashCode() {
+ return Sets.hashCodeImpl(this);
+ }
+}