diff options
Diffstat (limited to 'guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common')
7 files changed, 0 insertions, 1380 deletions
diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java deleted file mode 100644 index 48b5ce2..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/AbstractMultisetSetCountTester.java +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright (C) 2009 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.testing.google; - -import static com.google.common.collect.testing.features.CollectionFeature.ALLOWS_NULL_VALUES; -import static com.google.common.collect.testing.features.CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION; -import static com.google.common.collect.testing.features.CollectionFeature.RESTRICTS_ELEMENTS; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; -import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.Multiset; -import com.google.common.collect.Multiset.Entry; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.ConcurrentModificationException; -import java.util.Iterator; - -/** - * Common superclass for {@link MultisetSetCountUnconditionallyTester} and - * {@link MultisetSetCountConditionallyTester}. It is used by those testers to - * test calls to the unconditional {@code setCount()} method and calls to the - * conditional {@code setCount()} method when the expected present count is - * correct. - * - * @author Chris Povirk - */ -@GwtCompatible(emulated = true) -public abstract class AbstractMultisetSetCountTester<E> - extends AbstractMultisetTester<E> { - /* - * TODO: consider adding MultisetFeatures.SUPPORTS_SET_COUNT. Currently we - * assume that using setCount() to increase the count is permitted iff add() - * is permitted and similarly for decrease/remove(). We assume that a - * setCount() no-op is permitted if either add() or remove() is permitted, - * though we also allow it to "succeed" if neither is permitted. - */ - - private void assertSetCount(E element, int count) { - setCountCheckReturnValue(element, count); - - assertEquals( - "multiset.count() should return the value passed to setCount()", - count, getMultiset().count(element)); - - int size = 0; - for (Multiset.Entry<E> entry : getMultiset().entrySet()) { - size += entry.getCount(); - } - assertEquals( - "multiset.size() should be the sum of the counts of all entries", - size, getMultiset().size()); - } - - /** - * Call the {@code setCount()} method under test, and check its return value. - */ - abstract void setCountCheckReturnValue(E element, int count); - - /** - * Call the {@code setCount()} method under test, but do not check its return - * value. Callers should use this method over - * {@link #setCountCheckReturnValue(Object, int)} when they expect - * {@code setCount()} to throw an exception, as checking the return value - * could produce an incorrect error message like - * "setCount() should return the original count" instead of the message passed - * to a later invocation of {@code fail()}, like "setCount should throw - * UnsupportedOperationException." - */ - abstract void setCountNoCheckReturnValue(E element, int count); - - private void assertSetCountIncreasingFailure(E element, int count) { - try { - setCountNoCheckReturnValue(element, count); - fail("a call to multiset.setCount() to increase an element's count " - + "should throw"); - } catch (UnsupportedOperationException expected) { - } - } - - private void assertSetCountDecreasingFailure(E element, int count) { - try { - setCountNoCheckReturnValue(element, count); - fail("a call to multiset.setCount() to decrease an element's count " - + "should throw"); - } catch (UnsupportedOperationException expected) { - } - } - - // Unconditional setCount no-ops. - - private void assertZeroToZero() { - assertSetCount(samples.e3, 0); - } - - private void assertOneToOne() { - assertSetCount(samples.e0, 1); - } - - private void assertThreeToThree() { - initThreeCopies(); - assertSetCount(samples.e0, 3); - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_zeroToZero_addSupported() { - assertZeroToZero(); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_zeroToZero_removeSupported() { - assertZeroToZero(); - } - - @CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) - public void testSetCount_zeroToZero_unsupported() { - try { - assertZeroToZero(); - } catch (UnsupportedOperationException tolerated) { - } - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_oneToOne_addSupported() { - assertOneToOne(); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_oneToOne_removeSupported() { - assertOneToOne(); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) - public void testSetCount_oneToOne_unsupported() { - try { - assertOneToOne(); - } catch (UnsupportedOperationException tolerated) { - } - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_threeToThree_addSupported() { - assertThreeToThree(); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_threeToThree_removeSupported() { - assertThreeToThree(); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(absent = {SUPPORTS_ADD, SUPPORTS_REMOVE}) - public void testSetCount_threeToThree_unsupported() { - try { - assertThreeToThree(); - } catch (UnsupportedOperationException tolerated) { - } - } - - // Unconditional setCount size increases: - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_zeroToOne_supported() { - assertSetCount(samples.e3, 1); - } - - @CollectionFeature.Require({SUPPORTS_ADD, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - public void testSetCountZeroToOneConcurrentWithIteration() { - try { - Iterator<E> iterator = collection.iterator(); - assertSetCount(samples.e3, 1); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionFeature.Require({SUPPORTS_ADD, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - public void testSetCountZeroToOneConcurrentWithEntrySetIteration() { - try { - Iterator<Entry<E>> iterator = getMultiset().entrySet().iterator(); - assertSetCount(samples.e3, 1); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_zeroToThree_supported() { - assertSetCount(samples.e3, 3); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_ADD) - public void testSetCount_oneToThree_supported() { - assertSetCount(samples.e0, 3); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testSetCount_zeroToOne_unsupported() { - assertSetCountIncreasingFailure(samples.e3, 1); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testSetCount_zeroToThree_unsupported() { - assertSetCountIncreasingFailure(samples.e3, 3); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testSetCount_oneToThree_unsupported() { - assertSetCountIncreasingFailure(samples.e3, 3); - } - - // Unconditional setCount size decreases: - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_oneToZero_supported() { - assertSetCount(samples.e0, 0); - } - - @CollectionFeature.Require({SUPPORTS_REMOVE, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - @CollectionSize.Require(absent = ZERO) - public void testSetCountOneToZeroConcurrentWithIteration() { - try { - Iterator<E> iterator = collection.iterator(); - assertSetCount(samples.e0, 0); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionFeature.Require({SUPPORTS_REMOVE, - FAILS_FAST_ON_CONCURRENT_MODIFICATION}) - public void testSetCountOneToZeroConcurrentWithEntrySetIteration() { - try { - Iterator<Entry<E>> iterator = getMultiset().entrySet().iterator(); - assertSetCount(samples.e0, 0); - iterator.next(); - fail("Expected ConcurrentModificationException"); - } catch (ConcurrentModificationException expected) { - // success - } - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_threeToZero_supported() { - initThreeCopies(); - assertSetCount(samples.e0, 0); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_threeToOne_supported() { - initThreeCopies(); - assertSetCount(samples.e0, 1); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testSetCount_oneToZero_unsupported() { - assertSetCountDecreasingFailure(samples.e0, 0); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testSetCount_threeToZero_unsupported() { - initThreeCopies(); - assertSetCountDecreasingFailure(samples.e0, 0); - } - - @CollectionSize.Require(SEVERAL) - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testSetCount_threeToOne_unsupported() { - initThreeCopies(); - assertSetCountDecreasingFailure(samples.e0, 1); - } - - // setCount with nulls: - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require({SUPPORTS_REMOVE, ALLOWS_NULL_VALUES}) - public void testSetCount_removeNull_nullSupported() { - initCollectionWithNullElement(); - assertSetCount(null, 0); - } - - @CollectionFeature.Require(value = {SUPPORTS_ADD, ALLOWS_NULL_VALUES}, - absent = RESTRICTS_ELEMENTS) - public void testSetCount_addNull_nullSupported() { - assertSetCount(null, 1); - } - - @CollectionFeature.Require(value = SUPPORTS_ADD, absent = ALLOWS_NULL_VALUES) - public void testSetCount_addNull_nullUnsupported() { - try { - setCountNoCheckReturnValue(null, 1); - fail("adding null with setCount() should throw NullPointerException"); - } catch (NullPointerException expected) { - } - } - - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - public void testSetCount_noOpNull_nullSupported() { - try { - assertSetCount(null, 0); - } catch (UnsupportedOperationException tolerated) { - } - } - - @CollectionFeature.Require(absent = ALLOWS_NULL_VALUES) - public void testSetCount_noOpNull_nullUnsupported() { - try { - assertSetCount(null, 0); - } catch (NullPointerException tolerated) { - } catch (UnsupportedOperationException tolerated) { - } - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(ALLOWS_NULL_VALUES) - public void testSetCount_existingNoNopNull_nullSupported() { - initCollectionWithNullElement(); - try { - assertSetCount(null, 1); - } catch (UnsupportedOperationException tolerated) { - } - } - - // Negative count. - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testSetCount_negative_removeSupported() { - try { - setCountNoCheckReturnValue(samples.e3, -1); - fail("calling setCount() with a negative count should throw " - + "IllegalArgumentException"); - } catch (IllegalArgumentException expected) { - } - } - - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testSetCount_negative_removeUnsupported() { - try { - setCountNoCheckReturnValue(samples.e3, -1); - fail("calling setCount() with a negative count should throw " - + "IllegalArgumentException or UnsupportedOperationException"); - } catch (IllegalArgumentException expected) { - } catch (UnsupportedOperationException expected) { - } - } - - // TODO: test adding element of wrong type -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapInverseTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapInverseTester.java deleted file mode 100644 index eef939b..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapInverseTester.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2012 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.testing.google; - -import static com.google.common.collect.testing.features.CollectionFeature.SERIALIZABLE; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.BiMap; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.testing.SerializableTester; - -import java.io.Serializable; - -/** - * Tests for the {@code inverse} view of a BiMap. - * - * <p>This assumes that {@code bimap.inverse().inverse() == bimap}, which is not technically - * required but is fulfilled by all current implementations. - * - * @author Louis Wasserman - */ -@GwtCompatible(emulated = true) -public class BiMapInverseTester<K, V> extends AbstractBiMapTester<K, V> { - - public void testInverseSame() { - assertSame(getMap(), getMap().inverse().inverse()); - } - - @CollectionFeature.Require(SERIALIZABLE) - public void testInverseSerialization() { - BiMapPair<K, V> pair = new BiMapPair<K, V>(getMap()); - BiMapPair<K, V> copy = SerializableTester.reserialize(pair); - assertEquals(pair.forward, copy.forward); - assertEquals(pair.backward, copy.backward); - assertSame(copy.backward, copy.forward.inverse()); - assertSame(copy.forward, copy.backward.inverse()); - } - - private static class BiMapPair<K, V> implements Serializable { - final BiMap<K, V> forward; - final BiMap<V, K> backward; - - BiMapPair(BiMap<K, V> original) { - this.forward = original; - this.backward = original.inverse(); - } - - private static final long serialVersionUID = 0; - } - -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapRemoveTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapRemoveTester.java deleted file mode 100644 index 5c01444..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/BiMapRemoveTester.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2012 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.testing.google; - -import static com.google.common.collect.testing.features.CollectionSize.ZERO; -import static com.google.common.collect.testing.features.MapFeature.SUPPORTS_REMOVE; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.features.CollectionSize; -import com.google.common.collect.testing.features.MapFeature; - -import java.util.Iterator; - -/** - * Tester for {@code BiMap.remove}. - * - * @author Louis Wasserman - */ -@GwtCompatible(emulated = true) -public class BiMapRemoveTester<K, V> extends AbstractBiMapTester<K, V> { - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveKeyRemovesFromInverse() { - getMap().remove(samples.e0.getKey()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveKeyFromKeySetRemovesFromInverse() { - getMap().keySet().remove(samples.e0.getKey()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveFromValuesRemovesFromInverse() { - getMap().values().remove(samples.e0.getValue()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveFromInverseRemovesFromForward() { - getMap().inverse().remove(samples.e0.getValue()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveFromInverseKeySetRemovesFromForward() { - getMap().inverse().keySet().remove(samples.e0.getValue()); - expectMissing(samples.e0); - } - - @SuppressWarnings("unchecked") - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testRemoveFromInverseValuesRemovesFromInverse() { - getMap().inverse().values().remove(samples.e0.getKey()); - expectMissing(samples.e0); - } - - @MapFeature.Require(SUPPORTS_REMOVE) - @CollectionSize.Require(absent = ZERO) - public void testKeySetIteratorRemove() { - int initialSize = getNumElements(); - Iterator<K> iterator = getMap().keySet().iterator(); - iterator.next(); - iterator.remove(); - assertEquals(initialSize - 1, getMap().size()); - assertEquals(initialSize - 1, getMap().inverse().size()); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetIteratorTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetIteratorTester.java deleted file mode 100644 index e665afc..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetIteratorTester.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2011 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.testing.google; - -import static com.google.common.collect.testing.features.CollectionFeature.KNOWN_ORDER; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.testing.IteratorFeature; -import com.google.common.collect.testing.IteratorTester; -import com.google.common.collect.testing.features.CollectionFeature; - -import java.util.Arrays; -import java.util.Iterator; - -/** - * Tester to make sure the {@code iterator().remove()} implementation of {@code Multiset} works when - * there are multiple occurrences of elements. - * - * @author Louis Wasserman - */ -@GwtCompatible(emulated = true) -public class MultisetIteratorTester<E> extends AbstractMultisetTester<E> { - @SuppressWarnings("unchecked") - @CollectionFeature.Require({SUPPORTS_REMOVE, KNOWN_ORDER}) - public void testRemovingIteratorKnownOrder() { - new IteratorTester<E>(4, IteratorFeature.MODIFIABLE, getSubjectGenerator().order( - Arrays.asList(samples.e0, samples.e1, samples.e1, samples.e2)), - IteratorTester.KnownOrder.KNOWN_ORDER) { - @Override - protected Iterator<E> newTargetIterator() { - return getSubjectGenerator().create(samples.e0, samples.e1, samples.e1, samples.e2) - .iterator(); - } - }.test(); - } - - @SuppressWarnings("unchecked") - @CollectionFeature.Require(value = SUPPORTS_REMOVE, absent = KNOWN_ORDER) - public void testRemovingIteratorUnknownOrder() { - new IteratorTester<E>(4, IteratorFeature.MODIFIABLE, Arrays.asList(samples.e0, samples.e1, - samples.e1, samples.e2), IteratorTester.KnownOrder.UNKNOWN_ORDER) { - @Override - protected Iterator<E> newTargetIterator() { - return getSubjectGenerator().create(samples.e0, samples.e1, samples.e1, samples.e2) - .iterator(); - } - }.test(); - } - - @SuppressWarnings("unchecked") - @CollectionFeature.Require(value = KNOWN_ORDER, absent = SUPPORTS_REMOVE) - public void testIteratorKnownOrder() { - new IteratorTester<E>(4, IteratorFeature.UNMODIFIABLE, getSubjectGenerator().order( - Arrays.asList(samples.e0, samples.e1, samples.e1, samples.e2)), - IteratorTester.KnownOrder.KNOWN_ORDER) { - @Override - protected Iterator<E> newTargetIterator() { - return getSubjectGenerator().create(samples.e0, samples.e1, samples.e1, samples.e2) - .iterator(); - } - }.test(); - } - - @SuppressWarnings("unchecked") - @CollectionFeature.Require(absent = {SUPPORTS_REMOVE, KNOWN_ORDER}) - public void testIteratorUnknownOrder() { - new IteratorTester<E>(4, IteratorFeature.UNMODIFIABLE, Arrays.asList(samples.e0, samples.e1, - samples.e1, samples.e2), IteratorTester.KnownOrder.UNKNOWN_ORDER) { - @Override - protected Iterator<E> newTargetIterator() { - return getSubjectGenerator().create(samples.e0, samples.e1, samples.e1, samples.e2) - .iterator(); - } - }.test(); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetReadsTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetReadsTester.java deleted file mode 100644 index ea11eac..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetReadsTester.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2008 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.testing.google; - -import static com.google.common.collect.testing.features.CollectionSize.ONE; -import static com.google.common.collect.testing.features.CollectionSize.SEVERAL; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.HashMultiset; -import com.google.common.collect.Multiset; -import com.google.common.collect.Multisets; -import com.google.common.collect.testing.WrongType; -import com.google.common.collect.testing.features.CollectionSize; - -/** - * A generic JUnit test which tests multiset-specific read operations. - * Can't be invoked directly; please see - * {@link com.google.common.collect.testing.SetTestSuiteBuilder}. - * - * @author Jared Levy - */ -@GwtCompatible(emulated = true) -public class MultisetReadsTester<E> extends AbstractMultisetTester<E> { - public void testCount_0() { - assertEquals("multiset.count(missing) didn't return 0", - 0, getMultiset().count(samples.e3)); - } - - @CollectionSize.Require(absent = ZERO) - public void testCount_1() { - assertEquals("multiset.count(present) didn't return 1", - 1, getMultiset().count(samples.e0)); - } - - @CollectionSize.Require(SEVERAL) - public void testCount_3() { - initThreeCopies(); - assertEquals("multiset.count(thriceContained) didn't return 3", - 3, getMultiset().count(samples.e0)); - } - - public void testCount_null() { - assertEquals("multiset.count(null) didn't return 0", - 0, getMultiset().count(null)); - } - - public void testCount_wrongType() { - assertEquals("multiset.count(wrongType) didn't return 0", - 0, getMultiset().count(WrongType.VALUE)); - } - - @CollectionSize.Require(absent = ZERO) - public void testElementSet_contains() { - assertTrue("multiset.elementSet().contains(present) returned false", - getMultiset().elementSet().contains(samples.e0)); - } - - @CollectionSize.Require(absent = ZERO) - public void testEntrySet_contains() { - assertTrue("multiset.entrySet() didn't contain [present, 1]", - getMultiset().entrySet().contains( - Multisets.immutableEntry(samples.e0, 1))); - } - - public void testEntrySet_contains_count0() { - assertFalse("multiset.entrySet() contains [missing, 0]", - getMultiset().entrySet().contains( - Multisets.immutableEntry(samples.e3, 0))); - } - - public void testEntrySet_contains_nonentry() { - assertFalse("multiset.entrySet() contains a non-entry", - getMultiset().entrySet().contains(samples.e0)); - } - - public void testEntrySet_twice() { - assertEquals("calling multiset.entrySet() twice returned unequal sets", - getMultiset().entrySet(), getMultiset().entrySet()); - } - - @CollectionSize.Require(ZERO) - public void testEntrySet_hashCode_size0() { - assertEquals("multiset.entrySet() has incorrect hash code", - 0, getMultiset().entrySet().hashCode()); - } - - @CollectionSize.Require(ONE) - public void testEntrySet_hashCode_size1() { - assertEquals("multiset.entrySet() has incorrect hash code", - 1 ^ samples.e0.hashCode(), getMultiset().entrySet().hashCode()); - } - - public void testEquals_yes() { - assertTrue("multiset doesn't equal a multiset with the same elements", - getMultiset().equals(HashMultiset.create(getSampleElements()))); - } - - public void testEquals_differentSize() { - Multiset<E> other = HashMultiset.create(getSampleElements()); - other.add(samples.e0); - assertFalse("multiset equals a multiset with a different size", - getMultiset().equals(other)); - } - - @CollectionSize.Require(absent = ZERO) - public void testEquals_differentElements() { - Multiset<E> other = HashMultiset.create(getSampleElements()); - other.remove(samples.e0); - other.add(samples.e3); - assertFalse("multiset equals a multiset with different elements", - getMultiset().equals(other)); - } - - @CollectionSize.Require(ZERO) - public void testHashCode_size0() { - assertEquals("multiset has incorrect hash code", - 0, getMultiset().hashCode()); - } - - @CollectionSize.Require(ONE) - public void testHashCode_size1() { - assertEquals("multiset has incorrect hash code", - 1 ^ samples.e0.hashCode(), getMultiset().hashCode()); - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetWritesTester.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetWritesTester.java deleted file mode 100644 index 91cd8d3..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/MultisetWritesTester.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2008 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.testing.google; - -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_ADD; -import static com.google.common.collect.testing.features.CollectionFeature.SUPPORTS_REMOVE; -import static com.google.common.collect.testing.features.CollectionSize.ONE; -import static com.google.common.collect.testing.features.CollectionSize.ZERO; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.Multiset; -import com.google.common.collect.Multisets; -import com.google.common.collect.testing.WrongType; -import com.google.common.collect.testing.features.CollectionFeature; -import com.google.common.collect.testing.features.CollectionSize; - -import java.util.Collections; -import java.util.Iterator; - -/** - * A generic JUnit test which tests multiset-specific write operations. - * Can't be invoked directly; please see {@link MultisetTestSuiteBuilder}. - * - * @author Jared Levy - */ -@GwtCompatible(emulated = true) -public class MultisetWritesTester<E> extends AbstractMultisetTester<E> { - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAddOccurrencesZero() { - int originalCount = getMultiset().count(samples.e0); - assertEquals("old count", originalCount, getMultiset().add(samples.e0, 0)); - expectUnchanged(); - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAddOccurrences() { - int originalCount = getMultiset().count(samples.e0); - assertEquals("old count", originalCount, getMultiset().add(samples.e0, 2)); - assertEquals("old count", originalCount + 2, getMultiset().count(samples.e0)); - } - - @CollectionFeature.Require(absent = SUPPORTS_ADD) - public void testAddOccurrences_unsupported() { - try { - getMultiset().add(samples.e0, 2); - fail("unsupported multiset.add(E, int) didn't throw exception"); - } catch (UnsupportedOperationException required) {} - } - - @CollectionFeature.Require(SUPPORTS_ADD) - public void testAdd_occurrences_negative() { - try { - getMultiset().add(samples.e0, -1); - fail("multiset.add(E, -1) didn't throw an exception"); - } catch (IllegalArgumentException required) {} - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemoveZeroNoOp() { - int originalCount = getMultiset().count(samples.e0); - assertEquals("old count", originalCount, getMultiset().remove(samples.e0, 0)); - expectUnchanged(); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_present() { - assertEquals("multiset.remove(present, 2) didn't return the old count", - 1, getMultiset().remove(samples.e0, 2)); - assertFalse("multiset contains present after multiset.remove(present, 2)", - getMultiset().contains(samples.e0)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_absent() { - assertEquals("multiset.remove(absent, 0) didn't return 0", - 0, getMultiset().remove(samples.e3, 2)); - } - - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testRemove_occurrences_unsupported_absent() { - // notice: we don't care whether it succeeds, or fails with UOE - try { - assertEquals( - "multiset.remove(absent, 2) didn't return 0 or throw an exception", - 0, getMultiset().remove(samples.e3, 2)); - } catch (UnsupportedOperationException ok) {} - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_0() { - int oldCount = getMultiset().count(samples.e0); - assertEquals("multiset.remove(E, 0) didn't return the old count", - oldCount, getMultiset().remove(samples.e0, 0)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_negative() { - try { - getMultiset().remove(samples.e0, -1); - fail("multiset.remove(E, -1) didn't throw an exception"); - } catch (IllegalArgumentException required) {} - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testRemove_occurrences_wrongType() { - assertEquals("multiset.remove(wrongType, 1) didn't return 0", - 0, getMultiset().remove(WrongType.VALUE, 1)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_clear() { - getMultiset().entrySet().clear(); - assertTrue("multiset not empty after entrySet().clear()", - getMultiset().isEmpty()); - } - - @CollectionSize.Require(ONE) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_iterator() { - Iterator<Multiset.Entry<E>> iterator = getMultiset().entrySet().iterator(); - assertTrue( - "non-empty multiset.entrySet() iterator.hasNext() returned false", - iterator.hasNext()); - assertEquals("multiset.entrySet() iterator.next() returned incorrect entry", - Multisets.immutableEntry(samples.e0, 1), iterator.next()); - assertFalse( - "size 1 multiset.entrySet() iterator.hasNext() returned true " - + "after next()", - iterator.hasNext()); - iterator.remove(); - assertTrue( - "multiset isn't empty after multiset.entrySet() iterator.remove()", - getMultiset().isEmpty()); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(absent = SUPPORTS_REMOVE) - public void testEntrySet_iterator_remove_unsupported() { - Iterator<Multiset.Entry<E>> iterator = getMultiset().entrySet().iterator(); - assertTrue( - "non-empty multiset.entrySet() iterator.hasNext() returned false", - iterator.hasNext()); - try { - iterator.remove(); - fail("multiset.entrySet() iterator.remove() didn't throw an exception"); - } catch (UnsupportedOperationException expected) {} - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_remove_present() { - assertTrue( - "multiset.entrySet.remove(presentEntry) returned false", - getMultiset().entrySet().remove( - Multisets.immutableEntry(samples.e0, 1))); - assertFalse( - "multiset contains element after removing its entry", - getMultiset().contains(samples.e0)); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_remove_missing() { - assertFalse( - "multiset.entrySet.remove(missingEntry) returned true", - getMultiset().entrySet().remove( - Multisets.immutableEntry(samples.e0, 2))); - assertTrue( - "multiset didn't contain element after removing a missing entry", - getMultiset().contains(samples.e0)); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_removeAll_present() { - assertTrue( - "multiset.entrySet.removeAll(presentEntry) returned false", - getMultiset().entrySet().removeAll( - Collections.singleton(Multisets.immutableEntry(samples.e0, 1)))); - assertFalse( - "multiset contains element after removing its entry", - getMultiset().contains(samples.e0)); - } - - @CollectionSize.Require(absent = ZERO) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_removeAll_missing() { - assertFalse( - "multiset.entrySet.remove(missingEntry) returned true", - getMultiset().entrySet().removeAll( - Collections.singleton(Multisets.immutableEntry(samples.e0, 2)))); - assertTrue( - "multiset didn't contain element after removing a missing entry", - getMultiset().contains(samples.e0)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_removeAll_null() { - try { - getMultiset().entrySet().removeAll(null); - fail("multiset.entrySet.removeAll(null) didn't throw an exception"); - } catch (NullPointerException expected) {} - } - - @CollectionSize.Require(ONE) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_retainAll_present() { - assertFalse( - "multiset.entrySet.retainAll(presentEntry) returned false", - getMultiset().entrySet().retainAll( - Collections.singleton(Multisets.immutableEntry(samples.e0, 1)))); - assertTrue( - "multiset doesn't contains element after retaining its entry", - getMultiset().contains(samples.e0)); - } - - @CollectionSize.Require(ONE) - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_retainAll_missing() { - assertTrue( - "multiset.entrySet.retainAll(missingEntry) returned true", - getMultiset().entrySet().retainAll( - Collections.singleton(Multisets.immutableEntry(samples.e0, 2)))); - assertFalse( - "multiset contains element after retaining a different entry", - getMultiset().contains(samples.e0)); - } - - @CollectionFeature.Require(SUPPORTS_REMOVE) - public void testEntrySet_retainAll_null() { - try { - getMultiset().entrySet().retainAll(null); - // Returning successfully is not ideal, but tolerated. - } catch (NullPointerException expected) {} - } -} - diff --git a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/SetGenerators.java b/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/SetGenerators.java deleted file mode 100644 index 5102cdf..0000000 --- a/guava-testlib/blackhole-gwt/src-super/com/google/common/collect/testing/google/super/com/google/common/collect/testing/google/SetGenerators.java +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (C) 2008 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.testing.google; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Sets.newTreeSet; -import static com.google.common.collect.testing.SampleElements.Strings.AFTER_LAST; -import static com.google.common.collect.testing.SampleElements.Strings.AFTER_LAST_2; -import static com.google.common.collect.testing.SampleElements.Strings.BEFORE_FIRST; -import static com.google.common.collect.testing.SampleElements.Strings.BEFORE_FIRST_2; -import static junit.framework.Assert.assertEquals; - -import com.google.common.annotations.GwtCompatible; -import com.google.common.collect.ContiguousSet; -import com.google.common.collect.DiscreteDomain; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; -import com.google.common.collect.Range; -import com.google.common.collect.Sets; -import com.google.common.collect.testing.TestCollectionGenerator; -import com.google.common.collect.testing.TestCollidingSetGenerator; -import com.google.common.collect.testing.TestIntegerSortedSetGenerator; -import com.google.common.collect.testing.TestSetGenerator; -import com.google.common.collect.testing.TestStringListGenerator; -import com.google.common.collect.testing.TestStringSetGenerator; -import com.google.common.collect.testing.TestStringSortedSetGenerator; -import com.google.common.collect.testing.TestUnhashableCollectionGenerator; -import com.google.common.collect.testing.UnhashableObject; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; - -/** - * Generators of different types of sets and derived collections from sets. - * - * @author Kevin Bourrillion - * @author Jared Levy - * @author Hayward Chan - */ -@GwtCompatible(emulated = true) -public class SetGenerators { - - public static class ImmutableSetCopyOfGenerator extends TestStringSetGenerator { - @Override protected Set<String> create(String[] elements) { - return ImmutableSet.copyOf(elements); - } - } - - public static class ImmutableSetWithBadHashesGenerator - extends TestCollidingSetGenerator - // Work around a GWT compiler bug. Not explicitly listing this will - // cause the createArray() method missing in the generated javascript. - // TODO: Remove this once the GWT bug is fixed. - implements TestCollectionGenerator<Object> { - @Override - public Set<Object> create(Object... elements) { - return ImmutableSet.copyOf(elements); - } - } - - public static class DegeneratedImmutableSetGenerator - extends TestStringSetGenerator { - // Make sure we get what we think we're getting, or else this test - // is pointless - @SuppressWarnings("cast") - @Override protected Set<String> create(String[] elements) { - return (ImmutableSet<String>) - ImmutableSet.of(elements[0], elements[0]); - } - } - - public static class ImmutableSortedSetCopyOfGenerator - extends TestStringSortedSetGenerator { - @Override protected SortedSet<String> create(String[] elements) { - return ImmutableSortedSet.copyOf(elements); - } - } - - public static class ImmutableSortedSetHeadsetGenerator - extends TestStringSortedSetGenerator { - @Override protected SortedSet<String> create(String[] elements) { - List<String> list = Lists.newArrayList(elements); - list.add("zzz"); - return ImmutableSortedSet.copyOf(list) - .headSet("zzy"); - } - } - - public static class ImmutableSortedSetTailsetGenerator - extends TestStringSortedSetGenerator { - @Override protected SortedSet<String> create(String[] elements) { - List<String> list = Lists.newArrayList(elements); - list.add("\0"); - return ImmutableSortedSet.copyOf(list) - .tailSet("\0\0"); - } - } - - public static class ImmutableSortedSetSubsetGenerator - extends TestStringSortedSetGenerator { - @Override protected SortedSet<String> create(String[] elements) { - List<String> list = Lists.newArrayList(elements); - list.add("\0"); - list.add("zzz"); - return ImmutableSortedSet.copyOf(list) - .subSet("\0\0", "zzy"); - } - } - - public static class ImmutableSortedSetExplicitComparator - extends TestStringSetGenerator { - - private static final Comparator<String> STRING_REVERSED - = Collections.reverseOrder(); - - @Override protected SortedSet<String> create(String[] elements) { - return ImmutableSortedSet.orderedBy(STRING_REVERSED) - .add(elements) - .build(); - } - - @Override public List<String> order(List<String> insertionOrder) { - Collections.sort(insertionOrder, Collections.reverseOrder()); - return insertionOrder; - } - } - - public static class ImmutableSortedSetExplicitSuperclassComparatorGenerator - extends TestStringSetGenerator { - - private static final Comparator<Comparable<?>> COMPARABLE_REVERSED - = Collections.reverseOrder(); - - @Override protected SortedSet<String> create(String[] elements) { - return new ImmutableSortedSet.Builder<String>(COMPARABLE_REVERSED) - .add(elements) - .build(); - } - - @Override public List<String> order(List<String> insertionOrder) { - Collections.sort(insertionOrder, Collections.reverseOrder()); - return insertionOrder; - } - } - - public static class ImmutableSortedSetReversedOrderGenerator - extends TestStringSetGenerator { - - @Override protected SortedSet<String> create(String[] elements) { - return ImmutableSortedSet.<String>reverseOrder() - .addAll(Arrays.asList(elements).iterator()) - .build(); - } - - @Override public List<String> order(List<String> insertionOrder) { - Collections.sort(insertionOrder, Collections.reverseOrder()); - return insertionOrder; - } - } - - public static class ImmutableSortedSetUnhashableGenerator - extends TestUnhashableSetGenerator { - @Override public Set<UnhashableObject> create( - UnhashableObject[] elements) { - return ImmutableSortedSet.copyOf(elements); - } - } - - public static class ImmutableSetAsListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - return ImmutableSet.copyOf(elements).asList(); - } - } - - public static class ImmutableSortedSetAsListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - Comparator<String> comparator = createExplicitComparator(elements); - ImmutableSet<String> set = ImmutableSortedSet.copyOf( - comparator, Arrays.asList(elements)); - return set.asList(); - } - } - - public static class ImmutableSortedSetSubsetAsListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - Comparator<String> comparator = createExplicitComparator(elements); - ImmutableSortedSet.Builder<String> builder - = ImmutableSortedSet.orderedBy(comparator); - builder.add(BEFORE_FIRST); - builder.add(elements); - builder.add(AFTER_LAST); - return builder.build().subSet(BEFORE_FIRST_2, - AFTER_LAST).asList(); - } - } - - public static class ImmutableSortedSetAsListSubListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - Comparator<String> comparator = createExplicitComparator(elements); - ImmutableSortedSet.Builder<String> builder - = ImmutableSortedSet.orderedBy(comparator); - builder.add(BEFORE_FIRST); - builder.add(elements); - builder.add(AFTER_LAST); - return builder.build().asList().subList(1, elements.length + 1); - } - } - - public static class ImmutableSortedSetSubsetAsListSubListGenerator - extends TestStringListGenerator { - @Override protected List<String> create(String[] elements) { - Comparator<String> comparator = createExplicitComparator(elements); - ImmutableSortedSet.Builder<String> builder - = ImmutableSortedSet.orderedBy(comparator); - builder.add(BEFORE_FIRST); - builder.add(BEFORE_FIRST_2); - builder.add(elements); - builder.add(AFTER_LAST); - builder.add(AFTER_LAST_2); - return builder.build().subSet(BEFORE_FIRST_2, - AFTER_LAST_2) - .asList().subList(1, elements.length + 1); - } - } - - public abstract static class TestUnhashableSetGenerator - extends TestUnhashableCollectionGenerator<Set<UnhashableObject>> - implements TestSetGenerator<UnhashableObject> { - } - - private static Ordering<String> createExplicitComparator( - String[] elements) { - // Collapse equal elements, which Ordering.explicit() doesn't support, while - // maintaining the ordering by first occurrence. - Set<String> elementsPlus = Sets.newLinkedHashSet(); - elementsPlus.add(BEFORE_FIRST); - elementsPlus.add(BEFORE_FIRST_2); - elementsPlus.addAll(Arrays.asList(elements)); - elementsPlus.add(AFTER_LAST); - elementsPlus.add(AFTER_LAST_2); - return Ordering.explicit(Lists.newArrayList(elementsPlus)); - } - - /* - * All the ContiguousSet generators below manually reject nulls here. In principle, we'd like to - * defer that to Range, since it's ContiguousSet.create() that's used to create the sets. However, - * that gets messy here, and we already have null tests for Range. - */ - - /* - * These generators also rely on consecutive integer inputs (not necessarily in order, but no - * holes). - */ - - // SetCreationTester has some tests that pass in duplicates. Dedup them. - private static <E extends Comparable<? super E>> SortedSet<E> nullCheckedTreeSet(E[] elements) { - SortedSet<E> set = newTreeSet(); - for (E element : elements) { - // Explicit null check because TreeSet wrongly accepts add(null) when empty. - set.add(checkNotNull(element)); - } - return set; - } - - public static class ContiguousSetGenerator extends AbstractContiguousSetGenerator { - @Override protected SortedSet<Integer> create(Integer[] elements) { - return checkedCreate(nullCheckedTreeSet(elements)); - } - } - - public static class ContiguousSetHeadsetGenerator extends AbstractContiguousSetGenerator { - @Override protected SortedSet<Integer> create(Integer[] elements) { - SortedSet<Integer> set = nullCheckedTreeSet(elements); - int tooHigh = (set.isEmpty()) ? 0 : set.last() + 1; - set.add(tooHigh); - return checkedCreate(set).headSet(tooHigh); - } - } - - public static class ContiguousSetTailsetGenerator extends AbstractContiguousSetGenerator { - @Override protected SortedSet<Integer> create(Integer[] elements) { - SortedSet<Integer> set = nullCheckedTreeSet(elements); - int tooLow = (set.isEmpty()) ? 0 : set.first() - 1; - set.add(tooLow); - return checkedCreate(set).tailSet(tooLow + 1); - } - } - - public static class ContiguousSetSubsetGenerator extends AbstractContiguousSetGenerator { - @Override protected SortedSet<Integer> create(Integer[] elements) { - SortedSet<Integer> set = nullCheckedTreeSet(elements); - if (set.isEmpty()) { - /* - * The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be - * greater than tooHigh. - */ - return ContiguousSet.create(Range.openClosed(0, 1), DiscreteDomain.integers()).subSet(0, 1); - } - int tooHigh = set.last() + 1; - int tooLow = set.first() - 1; - set.add(tooHigh); - set.add(tooLow); - return checkedCreate(set).subSet(tooLow + 1, tooHigh); - } - } - - private abstract static class AbstractContiguousSetGenerator - extends TestIntegerSortedSetGenerator { - protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) { - List<Integer> elements = newArrayList(elementsSet); - /* - * A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it - * doesn't need one, or it should be suppressed for ContiguousSet. - */ - for (int i = 0; i < elements.size() - 1; i++) { - assertEquals(elements.get(i) + 1, (int) elements.get(i + 1)); - } - Range<Integer> range = - (elements.isEmpty()) ? Range.closedOpen(0, 0) : Range.encloseAll(elements); - return ContiguousSet.create(range, DiscreteDomain.integers()); - } - } -} - |