http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java b/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java index 1ec5c34..8d1a857 100644 --- a/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java +++ b/src/test/org/apache/commons/collections/bidimap/AbstractTestSortedBidiMap.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You 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. @@ -34,74 +34,89 @@ import org.apache.commons.collections.map.AbstractTestSortedMap; /** * Abstract test class for {@link SortedBidiMap} methods and contracts. - * + * * @version $Revision$ $Date$ - * + * * @author Matthew Hawthorne * @author Stephen Colebourne */ -public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiMap { +public abstract class AbstractTestSortedBidiMap<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestOrderedBidiMap<K, V> { - protected List sortedKeys = new ArrayList(); - protected List sortedValues = new ArrayList(); - protected SortedSet sortedNewValues = new TreeSet(); + protected List<K> sortedKeys = new ArrayList<K>(); + protected List<V> sortedValues = new ArrayList<V>(); + protected SortedSet<V> sortedNewValues = new TreeSet<V>(); public AbstractTestSortedBidiMap(String testName) { super(testName); sortedKeys.addAll(Arrays.asList(getSampleKeys())); Collections.sort(sortedKeys); sortedKeys = Collections.unmodifiableList(sortedKeys); - - Map map = new TreeMap(); - for (int i = 0; i < getSampleKeys().length; i++) { - map.put(getSampleKeys()[i], getSampleValues()[i]); - } - sortedValues.addAll(map.values()); - sortedValues = Collections.unmodifiableList(sortedValues); - - sortedNewValues.addAll(Arrays.asList(getNewSampleValues())); - } - public AbstractTestSortedBidiMap() { - super(); - sortedKeys.addAll(Arrays.asList(getSampleValues())); - Collections.sort(sortedKeys); - sortedKeys = Collections.unmodifiableList(sortedKeys); - - Map map = new TreeMap(); - for (int i = 0; i < getSampleKeys().length; i++) { - map.put(getSampleValues()[i], getSampleKeys()[i]); - } + Map<K, V> map = new TreeMap<K, V>(); + addSampleMappings(map); + sortedValues.addAll(map.values()); sortedValues = Collections.unmodifiableList(sortedValues); - + sortedNewValues.addAll(Arrays.asList(getNewSampleValues())); } +// public AbstractTestSortedBidiMap() { +// super(); +// sortedKeys.addAll(Arrays.asList(getSampleValues())); +// Collections.sort(sortedKeys); +// sortedKeys = Collections.unmodifiableList(sortedKeys); +// +// Map map = new TreeMap(); +// for (int i = 0; i < getSampleKeys().length; i++) { +// map.put(getSampleValues()[i], getSampleKeys()[i]); +// } +// sortedValues.addAll(map.values()); +// sortedValues = Collections.unmodifiableList(sortedValues); +// +// sortedNewValues.addAll(Arrays.asList(getNewSampleValues())); +// } + //----------------------------------------------------------------------- public boolean isAllowNullKey() { return false; } + public boolean isAllowNullValue() { return false; } - public Map makeConfirmedMap() { - return new TreeMap(); + + /** + * {@inheritDoc} + */ + @Override + public abstract SortedBidiMap<K, V> makeObject(); + + /** + * {@inheritDoc} + */ + @Override + public SortedBidiMap<K, V> makeFullMap() { + return (SortedBidiMap<K, V>) super.makeFullMap(); + } + + public SortedMap<K, V> makeConfirmedMap() { + return new TreeMap<K, V>(); } //----------------------------------------------------------------------- //----------------------------------------------------------------------- public void testBidiHeadMapContains() { // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); - Object first = it.next(); - Object toKey = it.next(); - Object second = it.next(); - Object firstValue = sm.get(first); - Object secondValue = sm.get(second); - - SortedMap head = sm.headMap(toKey); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); + K first = it.next(); + K toKey = it.next(); + K second = it.next(); + V firstValue = sm.get(first); + V secondValue = sm.get(second); + + SortedMap<K, V> head = sm.headMap(toKey); assertEquals(1, head.size()); assertEquals(true, sm.containsKey(first)); assertEquals(true, head.containsKey(first)); @@ -112,44 +127,44 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(true, sm.containsValue(secondValue)); assertEquals(false, head.containsValue(secondValue)); } - + //----------------------------------------------------------------------- public void testBidiClearByHeadMap() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); - Object first = it.next(); - Object second = it.next(); - Object toKey = it.next(); - - Object firstValue = sm.get(first); - Object secondValue = sm.get(second); - Object toKeyValue = sm.get(toKey); - - SortedMap sub = sm.headMap(toKey); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); + K first = it.next(); + K second = it.next(); + K toKey = it.next(); + + V firstValue = sm.get(first); + V secondValue = sm.get(second); + V toKeyValue = sm.get(toKey); + + SortedMap<K, V> sub = sm.headMap(toKey); int size = sm.size(); assertEquals(2, sub.size()); sub.clear(); assertEquals(0, sub.size()); assertEquals(size - 2, sm.size()); assertEquals(size - 2, sm.inverseBidiMap().size()); - + assertEquals(false, sm.containsKey(first)); assertEquals(false, sm.containsValue(firstValue)); assertEquals(false, sm.inverseBidiMap().containsKey(firstValue)); assertEquals(false, sm.inverseBidiMap().containsValue(first)); assertEquals(false, sub.containsKey(first)); assertEquals(false, sub.containsValue(firstValue)); - + assertEquals(false, sm.containsKey(second)); assertEquals(false, sm.containsValue(secondValue)); assertEquals(false, sm.inverseBidiMap().containsKey(secondValue)); assertEquals(false, sm.inverseBidiMap().containsValue(second)); assertEquals(false, sub.containsKey(second)); assertEquals(false, sub.containsValue(secondValue)); - + assertEquals(true, sm.containsKey(toKey)); assertEquals(true, sm.containsValue(toKeyValue)); assertEquals(true, sm.inverseBidiMap().containsKey(toKeyValue)); @@ -161,23 +176,23 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiRemoveByHeadMap() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); - Object first = it.next(); - Object second = it.next(); - Object toKey = it.next(); - + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); + K first = it.next(); + K second = it.next(); + K toKey = it.next(); + int size = sm.size(); - SortedMap sub = sm.headMap(toKey); + SortedMap<K, V> sub = sm.headMap(toKey); assertEquals(2, sub.size()); assertEquals(true, sm.containsKey(first)); assertEquals(true, sub.containsKey(first)); assertEquals(true, sm.containsKey(second)); assertEquals(true, sub.containsKey(second)); - - Object firstValue = sub.remove(first); + + V firstValue = sub.remove(first); assertEquals(1, sub.size()); assertEquals(size - 1, sm.size()); assertEquals(size - 1, sm.inverseBidiMap().size()); @@ -187,8 +202,8 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(false, sm.inverseBidiMap().containsValue(first)); assertEquals(false, sub.containsKey(first)); assertEquals(false, sub.containsValue(firstValue)); - - Object secondValue = sub.remove(second); + + V secondValue = sub.remove(second); assertEquals(0, sub.size()); assertEquals(size - 2, sm.size()); assertEquals(size - 2, sm.inverseBidiMap().size()); @@ -203,30 +218,30 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiRemoveByHeadMapEntrySet() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); - Object first = it.next(); - Object second = it.next(); - Object toKey = it.next(); - + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); + K first = it.next(); + K second = it.next(); + K toKey = it.next(); + int size = sm.size(); - SortedMap sub = sm.headMap(toKey); - Set set = sub.entrySet(); + SortedMap<K, V> sub = sm.headMap(toKey); + Set<Map.Entry<K, V>> set = sub.entrySet(); assertEquals(2, sub.size()); assertEquals(2, set.size()); - - Iterator it2 = set.iterator(); - Map.Entry firstEntry = cloneMapEntry((Map.Entry) it2.next()); - Map.Entry secondEntry = cloneMapEntry((Map.Entry) it2.next()); + + Iterator<Map.Entry<K, V>> it2 = set.iterator(); + Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next()); + Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next()); assertEquals(true, sm.containsKey(first)); assertEquals(true, sub.containsKey(first)); assertEquals(true, set.contains(firstEntry)); assertEquals(true, sm.containsKey(second)); assertEquals(true, sub.containsKey(second)); assertEquals(true, set.contains(secondEntry)); - + set.remove(firstEntry); assertEquals(1, sub.size()); assertEquals(size - 1, sm.size()); @@ -238,7 +253,7 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(false, sub.containsKey(firstEntry.getKey())); assertEquals(false, sub.containsValue(firstEntry.getValue())); assertEquals(false, set.contains(firstEntry)); - + set.remove(secondEntry); assertEquals(0, sub.size()); assertEquals(size - 2, sm.size()); @@ -256,16 +271,16 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiTailMapContains() { // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); - Object first = it.next(); - Object fromKey = it.next(); - Object second = it.next(); - Object firstValue = sm.get(first); - Object fromKeyValue = sm.get(fromKey); - Object secondValue = sm.get(second); - - SortedMap sub = sm.tailMap(fromKey); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); + K first = it.next(); + K fromKey = it.next(); + K second = it.next(); + V firstValue = sm.get(first); + V fromKeyValue = sm.get(fromKey); + V secondValue = sm.get(second); + + SortedMap<K, V> sub = sm.tailMap(fromKey); assertEquals(sm.size() - 1, sub.size()); assertEquals(true, sm.containsKey(first)); assertEquals(false, sub.containsKey(first)); @@ -284,42 +299,42 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiClearByTailMap() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); it.next(); it.next(); - Object first = it.next(); - Object fromKey = it.next(); - Object second = it.next(); - - Object firstValue = sm.get(first); - Object fromKeyValue = sm.get(fromKey); - Object secondValue = sm.get(second); - - SortedMap sub = sm.tailMap(fromKey); + K first = it.next(); + K fromKey = it.next(); + K second = it.next(); + + V firstValue = sm.get(first); + V fromKeyValue = sm.get(fromKey); + V secondValue = sm.get(second); + + SortedMap<K, V> sub = sm.tailMap(fromKey); int size = sm.size(); assertEquals(size - 3, sub.size()); sub.clear(); assertEquals(0, sub.size()); assertEquals(3, sm.size()); assertEquals(3, sm.inverseBidiMap().size()); - + assertEquals(true, sm.containsKey(first)); assertEquals(true, sm.containsValue(firstValue)); assertEquals(true, sm.inverseBidiMap().containsKey(firstValue)); assertEquals(true, sm.inverseBidiMap().containsValue(first)); assertEquals(false, sub.containsKey(first)); assertEquals(false, sub.containsValue(firstValue)); - + assertEquals(false, sm.containsKey(fromKey)); assertEquals(false, sm.containsValue(fromKeyValue)); assertEquals(false, sm.inverseBidiMap().containsKey(fromKeyValue)); assertEquals(false, sm.inverseBidiMap().containsValue(fromKey)); assertEquals(false, sub.containsKey(fromKey)); assertEquals(false, sub.containsValue(fromKeyValue)); - + assertEquals(false, sm.containsKey(second)); assertEquals(false, sm.containsValue(secondValue)); assertEquals(false, sm.inverseBidiMap().containsKey(secondValue)); @@ -328,26 +343,26 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(false, sub.containsValue(secondValue)); } - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- public void testBidiRemoveByTailMap() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); it.next(); it.next(); - Object fromKey = it.next(); - Object first = it.next(); - Object second = it.next(); - + K fromKey = it.next(); + K first = it.next(); + K second = it.next(); + int size = sm.size(); - SortedMap sub = sm.tailMap(fromKey); + SortedMap<K, V> sub = sm.tailMap(fromKey); assertEquals(true, sm.containsKey(first)); assertEquals(true, sub.containsKey(first)); assertEquals(true, sm.containsKey(second)); assertEquals(true, sub.containsKey(second)); - + Object firstValue = sub.remove(first); assertEquals(size - 3, sub.size()); assertEquals(size - 1, sm.size()); @@ -358,7 +373,7 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(false, sm.inverseBidiMap().containsValue(first)); assertEquals(false, sub.containsKey(first)); assertEquals(false, sub.containsValue(firstValue)); - + Object secondValue = sub.remove(second); assertEquals(size - 4, sub.size()); assertEquals(size - 2, sm.size()); @@ -374,30 +389,30 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiRemoveByTailMapEntrySet() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); it.next(); it.next(); - Object fromKey = it.next(); - Object first = it.next(); - Object second = it.next(); - + K fromKey = it.next(); + K first = it.next(); + K second = it.next(); + int size = sm.size(); - SortedMap sub = sm.tailMap(fromKey); - Set set = sub.entrySet(); - Iterator it2 = set.iterator(); - Object fromEntry = it2.next(); - Map.Entry firstEntry = cloneMapEntry((Map.Entry) it2.next()); - Map.Entry secondEntry = cloneMapEntry((Map.Entry) it2.next()); + SortedMap<K, V> sub = sm.tailMap(fromKey); + Set<Map.Entry<K, V>> set = sub.entrySet(); + Iterator<Map.Entry<K, V>> it2 = set.iterator(); + it2.next(); + Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next()); + Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next()); assertEquals(true, sm.containsKey(first)); assertEquals(true, sub.containsKey(first)); assertEquals(true, set.contains(firstEntry)); assertEquals(true, sm.containsKey(second)); assertEquals(true, sub.containsKey(second)); assertEquals(true, set.contains(secondEntry)); - + set.remove(firstEntry); assertEquals(size - 3, sub.size()); assertEquals(size - 1, sm.size()); @@ -409,7 +424,7 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(false, sub.containsKey(firstEntry.getKey())); assertEquals(false, sub.containsValue(firstEntry.getValue())); assertEquals(false, set.contains(firstEntry)); - + set.remove(secondEntry); assertEquals(size - 4, sub.size()); assertEquals(size - 2, sm.size()); @@ -427,19 +442,19 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiSubMapContains() { // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); - Object first = it.next(); - Object fromKey = it.next(); - Object second = it.next(); - Object toKey = it.next(); - Object third = it.next(); - Object firstValue = sm.get(first); - Object fromKeyValue = sm.get(fromKey); - Object secondValue = sm.get(second); - Object thirdValue = sm.get(third); - - SortedMap sub = sm.subMap(fromKey, toKey); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); + K first = it.next(); + K fromKey = it.next(); + K second = it.next(); + K toKey = it.next(); + K third = it.next(); + V firstValue = sm.get(first); + V fromKeyValue = sm.get(fromKey); + V secondValue = sm.get(second); + V thirdValue = sm.get(third); + + SortedMap<K, V> sub = sm.subMap(fromKey, toKey); assertEquals(2, sub.size()); assertEquals(true, sm.containsKey(first)); assertEquals(false, sub.containsKey(first)); @@ -462,50 +477,50 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiClearBySubMap() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); it.next(); - Object fromKey = it.next(); - Object first = it.next(); - Object second = it.next(); - Object toKey = it.next(); - - Object fromKeyValue = sm.get(fromKey); - Object firstValue = sm.get(first); - Object secondValue = sm.get(second); - Object toKeyValue = sm.get(toKey); - - SortedMap sub = sm.subMap(fromKey, toKey); + K fromKey = it.next(); + K first = it.next(); + K second = it.next(); + K toKey = it.next(); + + V fromKeyValue = sm.get(fromKey); + V firstValue = sm.get(first); + V secondValue = sm.get(second); + V toKeyValue = sm.get(toKey); + + SortedMap<K, V> sub = sm.subMap(fromKey, toKey); int size = sm.size(); assertEquals(3, sub.size()); sub.clear(); assertEquals(0, sub.size()); assertEquals(size - 3, sm.size()); assertEquals(size - 3, sm.inverseBidiMap().size()); - + assertEquals(false, sm.containsKey(fromKey)); assertEquals(false, sm.containsValue(fromKeyValue)); assertEquals(false, sm.inverseBidiMap().containsKey(fromKeyValue)); assertEquals(false, sm.inverseBidiMap().containsValue(fromKey)); assertEquals(false, sub.containsKey(fromKey)); assertEquals(false, sub.containsValue(fromKeyValue)); - + assertEquals(false, sm.containsKey(first)); assertEquals(false, sm.containsValue(firstValue)); assertEquals(false, sm.inverseBidiMap().containsKey(firstValue)); assertEquals(false, sm.inverseBidiMap().containsValue(first)); assertEquals(false, sub.containsKey(first)); assertEquals(false, sub.containsValue(firstValue)); - + assertEquals(false, sm.containsKey(second)); assertEquals(false, sm.containsValue(secondValue)); assertEquals(false, sm.inverseBidiMap().containsKey(secondValue)); assertEquals(false, sm.inverseBidiMap().containsValue(second)); assertEquals(false, sub.containsKey(second)); assertEquals(false, sub.containsValue(secondValue)); - + assertEquals(true, sm.containsKey(toKey)); assertEquals(true, sm.containsValue(toKeyValue)); assertEquals(true, sm.inverseBidiMap().containsKey(toKeyValue)); @@ -517,25 +532,25 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiRemoveBySubMap() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); it.next(); it.next(); - Object fromKey = it.next(); - Object first = it.next(); - Object second = it.next(); - Object toKey = it.next(); - + K fromKey = it.next(); + K first = it.next(); + K second = it.next(); + K toKey = it.next(); + int size = sm.size(); - SortedMap sub = sm.subMap(fromKey, toKey); + SortedMap<K, V> sub = sm.subMap(fromKey, toKey); assertEquals(true, sm.containsKey(first)); assertEquals(true, sub.containsKey(first)); assertEquals(true, sm.containsKey(second)); assertEquals(true, sub.containsKey(second)); - - Object firstValue = sub.remove(first); + + V firstValue = sub.remove(first); assertEquals(2, sub.size()); assertEquals(size - 1, sm.size()); assertEquals(size - 1, sm.inverseBidiMap().size()); @@ -545,8 +560,8 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(false, sm.inverseBidiMap().containsValue(first)); assertEquals(false, sub.containsKey(first)); assertEquals(false, sub.containsValue(firstValue)); - - Object secondValue = sub.remove(second); + + V secondValue = sub.remove(second); assertEquals(1, sub.size()); assertEquals(size - 2, sm.size()); assertEquals(size - 2, sm.inverseBidiMap().size()); @@ -561,32 +576,32 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM //----------------------------------------------------------------------- public void testBidiRemoveBySubMapEntrySet() { if (isRemoveSupported() == false) return; - + // extra test as other tests get complex - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); - Iterator it = sm.keySet().iterator(); + SortedBidiMap<K, V> sm = makeFullMap(); + Iterator<K> it = sm.keySet().iterator(); it.next(); it.next(); - Object fromKey = it.next(); - Object first = it.next(); - Object second = it.next(); - Object toKey = it.next(); - + K fromKey = it.next(); + K first = it.next(); + K second = it.next(); + K toKey = it.next(); + int size = sm.size(); - SortedMap sub = sm.subMap(fromKey, toKey); - Set set = sub.entrySet(); + SortedMap<K, V> sub = sm.subMap(fromKey, toKey); + Set<Map.Entry<K, V>> set = sub.entrySet(); assertEquals(3, set.size()); - Iterator it2 = set.iterator(); - Object fromEntry = it2.next(); - Map.Entry firstEntry = cloneMapEntry((Map.Entry) it2.next()); - Map.Entry secondEntry = cloneMapEntry((Map.Entry) it2.next()); + Iterator<Map.Entry<K, V>> it2 = set.iterator(); + it2.next(); + Map.Entry<K, V> firstEntry = cloneMapEntry(it2.next()); + Map.Entry<K, V> secondEntry = cloneMapEntry(it2.next()); assertEquals(true, sm.containsKey(first)); assertEquals(true, sub.containsKey(first)); assertEquals(true, set.contains(firstEntry)); assertEquals(true, sm.containsKey(second)); assertEquals(true, sub.containsKey(second)); assertEquals(true, set.contains(secondEntry)); - + set.remove(firstEntry); assertEquals(2, sub.size()); assertEquals(size - 1, sm.size()); @@ -598,7 +613,7 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(false, sub.containsKey(firstEntry.getKey())); assertEquals(false, sub.containsValue(firstEntry.getValue())); assertEquals(false, set.contains(firstEntry)); - + set.remove(secondEntry); assertEquals(1, sub.size()); assertEquals(size - 2, sm.size()); @@ -612,17 +627,17 @@ public abstract class AbstractTestSortedBidiMap extends AbstractTestOrderedBidiM assertEquals(false, set.contains(secondEntry)); } - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- public BulkTest bulkTestHeadMap() { - return new AbstractTestSortedMap.TestHeadMap(this); + return new AbstractTestSortedMap.TestHeadMap<K, V>(this); } public BulkTest bulkTestTailMap() { - return new AbstractTestSortedMap.TestTailMap(this); + return new AbstractTestSortedMap.TestTailMap<K, V>(this); } public BulkTest bulkTestSubMap() { - return new AbstractTestSortedMap.TestSubMap(this); + return new AbstractTestSortedMap.TestSubMap<K, V>(this); } }
http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/TestAbstractOrderedBidiMapDecorator.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/TestAbstractOrderedBidiMapDecorator.java b/src/test/org/apache/commons/collections/bidimap/TestAbstractOrderedBidiMapDecorator.java index b385bf8..3223033 100644 --- a/src/test/org/apache/commons/collections/bidimap/TestAbstractOrderedBidiMapDecorator.java +++ b/src/test/org/apache/commons/collections/bidimap/TestAbstractOrderedBidiMapDecorator.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You 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. @@ -16,22 +16,21 @@ */ package org.apache.commons.collections.bidimap; -import java.util.Map; +import java.util.SortedMap; import java.util.TreeMap; import junit.framework.Test; import junit.framework.TestSuite; -import org.apache.commons.collections.BidiMap; import org.apache.commons.collections.OrderedBidiMap; /** * Test class for AbstractOrderedBidiMapDecorator. - * + * * @version $Revision$ $Date$ */ -public class TestAbstractOrderedBidiMapDecorator - extends AbstractTestOrderedBidiMap { +public class TestAbstractOrderedBidiMapDecorator<K, V> + extends AbstractTestOrderedBidiMap<K, V> { public TestAbstractOrderedBidiMapDecorator(String testName) { super(testName); @@ -41,12 +40,16 @@ public class TestAbstractOrderedBidiMapDecorator return new TestSuite(TestAbstractOrderedBidiMapDecorator.class); } - public BidiMap makeEmptyBidiMap() { - return new TestOrderedBidiMap(); + /** + * {@inheritDoc} + */ + @Override + public OrderedBidiMap<K, V> makeObject() { + return new TestOrderedBidiMap<K, V>(); } - public Map makeConfirmedMap() { - return new TreeMap(); + public SortedMap<K, V> makeConfirmedMap() { + return new TreeMap<K, V>(); } public boolean isAllowNullKey() { @@ -64,21 +67,21 @@ public class TestAbstractOrderedBidiMapDecorator /** * Simple class to actually test. */ - private static final class TestOrderedBidiMap extends AbstractOrderedBidiMapDecorator { - - private TestOrderedBidiMap inverse = null; + private static final class TestOrderedBidiMap<K, V> extends AbstractOrderedBidiMapDecorator<K, V> { + + private TestOrderedBidiMap<V, K> inverse = null; public TestOrderedBidiMap() { - super(new DualTreeBidiMap()); + super(new DualTreeBidiMap<K, V>()); } - - public TestOrderedBidiMap(OrderedBidiMap map) { + + public TestOrderedBidiMap(OrderedBidiMap<K, V> map) { super(map); } - - public BidiMap inverseBidiMap() { + + public OrderedBidiMap<V, K> inverseBidiMap() { if (inverse == null) { - inverse = new TestOrderedBidiMap((OrderedBidiMap) getBidiMap().inverseBidiMap()); + inverse = new TestOrderedBidiMap<V, K>(decorated().inverseBidiMap()); inverse.inverse = this; } return inverse; http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/TestDualHashBidiMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/TestDualHashBidiMap.java b/src/test/org/apache/commons/collections/bidimap/TestDualHashBidiMap.java index 1118356..af5c363 100644 --- a/src/test/org/apache/commons/collections/bidimap/TestDualHashBidiMap.java +++ b/src/test/org/apache/commons/collections/bidimap/TestDualHashBidiMap.java @@ -19,7 +19,6 @@ package org.apache.commons.collections.bidimap; import junit.framework.Test; import junit.textui.TestRunner; -import org.apache.commons.collections.BidiMap; import org.apache.commons.collections.BulkTest; /** @@ -30,7 +29,7 @@ import org.apache.commons.collections.BulkTest; * @author Matthew Hawthorne * @author Stephen Colebourne */ -public class TestDualHashBidiMap extends AbstractTestBidiMap { +public class TestDualHashBidiMap<K, V> extends AbstractTestBidiMap<K, V> { public static void main(String[] args) { TestRunner.run(suite()); @@ -44,15 +43,19 @@ public class TestDualHashBidiMap extends AbstractTestBidiMap { super(testName); } - public BidiMap makeEmptyBidiMap() { - return new DualHashBidiMap(); + /** + * {@inheritDoc} + */ + @Override + public DualHashBidiMap<K, V> makeObject() { + return new DualHashBidiMap<K, V>(); } /** * Override to prevent infinite recursion of tests. */ public String[] ignoredTests() { - return new String[] {"TestDualHashBidiMap.bulkTestInverseMap.bulkTestInverseMap"}; + return new String[] { "TestDualHashBidiMap.bulkTestInverseMap.bulkTestInverseMap" }; } // public void testCreate() throws Exception { http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap.java b/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap.java index a9c34f5..470d6c0 100644 --- a/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap.java +++ b/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap.java @@ -19,7 +19,6 @@ package org.apache.commons.collections.bidimap; import junit.framework.Test; import junit.textui.TestRunner; -import org.apache.commons.collections.BidiMap; import org.apache.commons.collections.BulkTest; /** @@ -30,7 +29,7 @@ import org.apache.commons.collections.BulkTest; * @author Matthew Hawthorne * @author Stephen Colebourne */ -public class TestDualTreeBidiMap extends AbstractTestSortedBidiMap { +public class TestDualTreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestSortedBidiMap<K, V> { public static void main(String[] args) { TestRunner.run(suite()); @@ -44,8 +43,12 @@ public class TestDualTreeBidiMap extends AbstractTestSortedBidiMap { super(testName); } - public BidiMap makeEmptyBidiMap() { - return new DualTreeBidiMap(); + /** + * {@inheritDoc} + */ + @Override + public DualTreeBidiMap<K, V> makeObject() { + return new DualTreeBidiMap<K, V>(); } /** http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java b/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java index fba5af8..74c7389 100644 --- a/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java +++ b/src/test/org/apache/commons/collections/bidimap/TestDualTreeBidiMap2.java @@ -25,13 +25,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.TreeMap; import junit.framework.Test; import junit.textui.TestRunner; -import org.apache.commons.collections.BidiMap; import org.apache.commons.collections.BulkTest; import org.apache.commons.collections.SortedBidiMap; import org.apache.commons.collections.comparators.ComparableComparator; @@ -46,7 +44,7 @@ import org.apache.commons.collections.comparators.ReverseComparator; * @author Stephen Colebourne * @author Jonas Van Poucke */ -public class TestDualTreeBidiMap2 extends AbstractTestSortedBidiMap { +public class TestDualTreeBidiMap2<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestSortedBidiMap<K, V> { public static void main(String[] args) { TestRunner.run(suite()); @@ -60,21 +58,24 @@ public class TestDualTreeBidiMap2 extends AbstractTestSortedBidiMap { super(testName); } - public BidiMap makeEmptyBidiMap() { - return new DualTreeBidiMap(new ReverseComparator(ComparableComparator.getInstance())); + public DualTreeBidiMap<K, V> makeObject() { + return new DualTreeBidiMap<K, V>( + new ReverseComparator<K>(ComparableComparator.<K> getInstance()), + new ReverseComparator<V>(ComparableComparator.<V> getInstance())); } - public Map makeConfirmedMap() { - return new TreeMap(new ReverseComparator(ComparableComparator.getInstance())); + public TreeMap<K, V> makeConfirmedMap() { + return new TreeMap<K, V>(new ReverseComparator<K>(ComparableComparator.<K>getInstance())); } public void testComparator() { resetEmpty(); - SortedBidiMap bidi = (SortedBidiMap) map; + SortedBidiMap<K, V> bidi = (SortedBidiMap<K, V>) map; assertNotNull(bidi.comparator()); assertTrue(bidi.comparator() instanceof ReverseComparator); } + @SuppressWarnings("unchecked") public void testSerializeDeserializeCheckComparator() throws Exception { SortedBidiMap obj = (SortedBidiMap) makeObject(); if (obj instanceof Serializable && isTestSerialization()) { @@ -95,18 +96,18 @@ public class TestDualTreeBidiMap2 extends AbstractTestSortedBidiMap { } public void testSortOrder() throws Exception { - SortedBidiMap sm = (SortedBidiMap) makeFullMap(); + SortedBidiMap<K, V> sm = makeFullMap(); // Sort by the comparator used in the makeEmptyBidiMap() method - List newSortedKeys = Arrays.asList(getSampleKeys()); - Collections.sort(newSortedKeys, new ReverseComparator(ComparableComparator.getInstance())); + List<K> newSortedKeys = Arrays.asList(getSampleKeys()); + Collections.sort(newSortedKeys, new ReverseComparator<K>(ComparableComparator.<K>getInstance())); newSortedKeys = Collections.unmodifiableList(newSortedKeys); - Iterator mapIter = sm.keySet().iterator(); - Iterator expectedIter = newSortedKeys.iterator(); + Iterator<K> mapIter = sm.keySet().iterator(); + Iterator<K> expectedIter = newSortedKeys.iterator(); while (expectedIter.hasNext()) { - Object expectedKey = expectedIter.next(); - Object mapKey = mapIter.next(); + K expectedKey = expectedIter.next(); + K mapKey = mapIter.next(); assertNotNull("key in sorted list may not be null", expectedKey); assertNotNull("key in map may not be null", mapKey); assertEquals("key from sorted list and map must be equal", expectedKey, mapKey); http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java b/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java index 42028c6..66def22 100644 --- a/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java +++ b/src/test/org/apache/commons/collections/bidimap/TestTreeBidiMap.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections.bidimap; -import java.util.Map; import java.util.TreeMap; import junit.framework.Test; @@ -32,7 +31,7 @@ import org.apache.commons.collections.BulkTest; * * @author Stephen Colebourne */ -public class TestTreeBidiMap extends AbstractTestOrderedBidiMap { +public class TestTreeBidiMap<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestOrderedBidiMap<K, V> { public static void main(String[] args) { TestRunner.run(suite()); @@ -46,12 +45,12 @@ public class TestTreeBidiMap extends AbstractTestOrderedBidiMap { super(testName); } - public BidiMap makeEmptyBidiMap() { - return new TreeBidiMap(); + public BidiMap<K, V> makeObject() { + return new TreeBidiMap<K, V>(); } - public Map makeConfirmedMap() { - return new TreeMap(); + public TreeMap<K, V> makeConfirmedMap() { + return new TreeMap<K, V>(); } /** http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java b/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java index e8da77c..8af3f17 100644 --- a/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java +++ b/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableBidiMap.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You 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. @@ -27,17 +27,17 @@ import org.apache.commons.collections.BulkTest; /** * JUnit tests. - * + * * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public class TestUnmodifiableBidiMap extends AbstractTestBidiMap { +public class TestUnmodifiableBidiMap<K, V> extends AbstractTestBidiMap<K, V> { public static void main(String[] args) { TestRunner.run(suite()); } - + public static Test suite() { return BulkTest.makeSuite(TestUnmodifiableBidiMap.class); } @@ -46,24 +46,18 @@ public class TestUnmodifiableBidiMap extends AbstractTestBidiMap { super(testName); } - public BidiMap makeEmptyBidiMap() { - return UnmodifiableBidiMap.decorate(new DualHashBidiMap()); - } - public BidiMap makeFullBidiMap() { - BidiMap bidi = new DualHashBidiMap(); - for (int i = 0; i < entries.length; i++) { - bidi.put(entries[i][0], entries[i][1]); - } - return UnmodifiableBidiMap.decorate(bidi); + public BidiMap<K, V> makeObject() { + return UnmodifiableBidiMap.decorate(new DualHashBidiMap<K, V>()); } - public Map makeFullMap() { - BidiMap bidi = new DualHashBidiMap(); + + public BidiMap<K, V> makeFullMap() { + BidiMap<K, V> bidi = new DualHashBidiMap<K, V>(); addSampleMappings(bidi); return UnmodifiableBidiMap.decorate(bidi); } - - public Map makeConfirmedMap() { - return new HashMap(); + + public Map<K, V> makeConfirmedMap() { + return new HashMap<K, V>(); } /** @@ -76,11 +70,13 @@ public class TestUnmodifiableBidiMap extends AbstractTestBidiMap { public boolean isPutAddSupported() { return false; } + public boolean isPutChangeSupported() { return false; } + public boolean isRemoveSupported() { return false; } - + } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java b/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java index 1a84417..6c732e7 100644 --- a/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java +++ b/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableOrderedBidiMap.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You 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. @@ -28,17 +28,17 @@ import org.apache.commons.collections.OrderedBidiMap; /** * JUnit tests. - * + * * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public class TestUnmodifiableOrderedBidiMap extends AbstractTestOrderedBidiMap { +public class TestUnmodifiableOrderedBidiMap<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestOrderedBidiMap<K, V> { public static void main(String[] args) { TestRunner.run(suite()); } - + public static Test suite() { return BulkTest.makeSuite(TestUnmodifiableOrderedBidiMap.class); } @@ -47,24 +47,18 @@ public class TestUnmodifiableOrderedBidiMap extends AbstractTestOrderedBidiMap { super(testName); } - public BidiMap makeEmptyBidiMap() { - return UnmodifiableOrderedBidiMap.decorate(new TreeBidiMap()); - } - public BidiMap makeFullBidiMap() { - OrderedBidiMap bidi = new TreeBidiMap(); - for (int i = 0; i < entries.length; i++) { - bidi.put(entries[i][0], entries[i][1]); - } - return UnmodifiableOrderedBidiMap.decorate(bidi); + public OrderedBidiMap<K, V> makeObject() { + return UnmodifiableOrderedBidiMap.decorate(new TreeBidiMap<K, V>()); } - public Map makeFullMap() { - OrderedBidiMap bidi = new TreeBidiMap(); + + public BidiMap<K, V> makeFullMap() { + OrderedBidiMap<K, V> bidi = new TreeBidiMap<K, V>(); addSampleMappings(bidi); return UnmodifiableOrderedBidiMap.decorate(bidi); } - - public Map makeConfirmedMap() { - return new TreeMap(); + + public Map<K, V> makeConfirmedMap() { + return new TreeMap<K, V>(); } /** @@ -73,21 +67,25 @@ public class TestUnmodifiableOrderedBidiMap extends AbstractTestOrderedBidiMap { public String[] ignoredTests() { return new String[] {"TestUnmodifiableOrderedBidiMap.bulkTestInverseMap.bulkTestInverseMap"}; } - + public boolean isAllowNullKey() { return false; } + public boolean isAllowNullValue() { return false; } + public boolean isPutAddSupported() { return false; } + public boolean isPutChangeSupported() { return false; } + public boolean isRemoveSupported() { return false; } - + } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java b/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java index b4ae163..7b4597c 100644 --- a/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java +++ b/src/test/org/apache/commons/collections/bidimap/TestUnmodifiableSortedBidiMap.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You 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. @@ -16,29 +16,28 @@ */ package org.apache.commons.collections.bidimap; -import java.util.Map; +import java.util.SortedMap; import java.util.TreeMap; import junit.framework.Test; import junit.textui.TestRunner; -import org.apache.commons.collections.BidiMap; import org.apache.commons.collections.BulkTest; import org.apache.commons.collections.SortedBidiMap; /** * JUnit tests. - * + * * @version $Revision$ $Date$ - * + * * @author Stephen Colebourne */ -public class TestUnmodifiableSortedBidiMap extends AbstractTestSortedBidiMap { +public class TestUnmodifiableSortedBidiMap<K extends Comparable<K>, V extends Comparable<V>> extends AbstractTestSortedBidiMap<K, V> { public static void main(String[] args) { TestRunner.run(suite()); } - + public static Test suite() { return BulkTest.makeSuite(TestUnmodifiableSortedBidiMap.class); } @@ -48,30 +47,25 @@ public class TestUnmodifiableSortedBidiMap extends AbstractTestSortedBidiMap { } //----------------------------------------------------------------------- - public BidiMap makeEmptyBidiMap() { - return UnmodifiableSortedBidiMap.decorate(new DualTreeBidiMap()); - } - public BidiMap makeFullBidiMap() { - SortedBidiMap bidi = new DualTreeBidiMap(); - for (int i = 0; i < entries.length; i++) { - bidi.put(entries[i][0], entries[i][1]); - } - return UnmodifiableSortedBidiMap.decorate(bidi); + public SortedBidiMap<K, V> makeObject() { + return UnmodifiableSortedBidiMap.decorate(new DualTreeBidiMap<K, V>()); } - public Map makeFullMap() { - SortedBidiMap bidi = new DualTreeBidiMap(); + + public SortedBidiMap<K, V> makeFullMap() { + SortedBidiMap<K, V> bidi = new DualTreeBidiMap<K, V>(); addSampleMappings(bidi); return UnmodifiableSortedBidiMap.decorate(bidi); } - - public Map makeConfirmedMap() { - return new TreeMap(); + + public SortedMap<K, V> makeConfirmedMap() { + return new TreeMap<K, V>(); } public boolean isSubMapViewsSerializable() { // TreeMap sub map views have a bug in deserialization. return false; } + public String[] ignoredTests() { // Override to prevent infinite recursion of tests. return new String[] {"TestUnmodifiableSortedBidiMap.bulkTestInverseMap.bulkTestInverseMap"}; @@ -81,17 +75,21 @@ public class TestUnmodifiableSortedBidiMap extends AbstractTestSortedBidiMap { public boolean isAllowNullKey() { return false; } + public boolean isAllowNullValue() { return false; } + public boolean isPutAddSupported() { return false; } + public boolean isPutChangeSupported() { return false; } + public boolean isRemoveSupported() { return false; } - + } http://git-wip-us.apache.org/repos/asf/commons-collections/blob/884baf0d/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java ---------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java b/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java index e5ea282..2860de5 100644 --- a/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java +++ b/src/test/org/apache/commons/collections/buffer/TestBlockingBuffer.java @@ -29,30 +29,31 @@ import java.util.LinkedList; import java.util.Set; /** - * Extension of {@link AbstractTestObject} for exercising the {@link BlockingBuffer} implementation. - * + * Extension of {@link AbstractTestObject} for exercising the + * {@link BlockingBuffer} implementation. + * * @author Janek Bogucki * @author Phil Steitz * @version $Revision$ * @since Commons Collections 3.0 */ -public class TestBlockingBuffer extends AbstractTestObject { +public class TestBlockingBuffer<E> extends AbstractTestObject { - public TestBlockingBuffer( String testName ) { - super( testName ); + public TestBlockingBuffer(String testName) { + super(testName); } public static Test suite() { - return new TestSuite( TestBlockingBuffer.class ); + return new TestSuite(TestBlockingBuffer.class); } - public static void main( String args[] ) { - String[] testCaseName = {TestBlockingBuffer.class.getName()}; - junit.textui.TestRunner.main( testCaseName ); + public static void main(String args[]) { + String[] testCaseName = { TestBlockingBuffer.class.getName() }; + junit.textui.TestRunner.main(testCaseName); } - public Object makeObject() { - return BlockingBuffer.decorate( new MyBuffer() ); + public Buffer<E> makeObject() { + return BlockingBuffer.decorate(new MyBuffer<E>()); } public boolean isEqualsCheckable() { @@ -61,113 +62,122 @@ public class TestBlockingBuffer extends AbstractTestObject { //----------------------------------------------------------------------- + @SuppressWarnings("unchecked") + protected E makeElement() { + return (E) new Object(); + } + /** - * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)}. + * Tests {@link BlockingBuffer#get()} in combination with + * {@link BlockingBuffer#add(Object)}. */ public void testGetWithAdd() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); - new DelayedAdd( blockingBuffer, obj ).start(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); + new DelayedAdd<E>(blockingBuffer, obj).start(); // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer . - assertSame( obj, blockingBuffer.get() ); + assertSame(obj, blockingBuffer.get()); } public void testGetWithAddTimeout() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 500 ); - Object obj = new Object(); - new DelayedAdd( blockingBuffer, obj, 100 ).start(); + Buffer<E> blockingBuffer = BlockingBuffer.decorate(new MyBuffer<E>(), 500); + E obj = makeElement(); + new DelayedAdd<E>(blockingBuffer, obj, 100).start(); // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer . - assertSame( obj, blockingBuffer.get() ); + assertSame(obj, blockingBuffer.get()); } //----------------------------------------------------------------------- /** - * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}. + * Tests {@link BlockingBuffer#get()} in combination with + * {@link BlockingBuffer#addAll(java.util.Collection)}. */ public void testGetWithAddAll() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); - new DelayedAddAll( blockingBuffer, obj ).start(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); + new DelayedAddAll<E>(blockingBuffer, obj).start(); // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer . - assertSame( obj, blockingBuffer.get() ); + assertSame(obj, blockingBuffer.get()); } public void testGetWithAddAllTimeout() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 500 ); - Object obj = new Object(); - new DelayedAddAll( blockingBuffer, obj, 100 ).start(); + Buffer<E> blockingBuffer = BlockingBuffer.decorate(new MyBuffer<E>(), 500); + E obj = makeElement(); + new DelayedAddAll<E>(blockingBuffer, obj, 100).start(); // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer . - assertSame( obj, blockingBuffer.get() ); + assertSame(obj, blockingBuffer.get()); } //----------------------------------------------------------------------- /** - * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add(Object)}. + * Tests {@link BlockingBuffer#remove()} in combination with + * {@link BlockingBuffer#add(Object)}. */ public void testRemoveWithAdd() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); - new DelayedAdd( blockingBuffer, obj ).start(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); + new DelayedAdd<E>(blockingBuffer, obj).start(); // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer . - assertSame( obj, blockingBuffer.remove() ); + assertSame(obj, blockingBuffer.remove()); } public void testRemoveWithAddTimeout() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 100 ); - Object obj = new Object(); - new DelayedAdd( blockingBuffer, obj, 500 ).start(); + Buffer<E> blockingBuffer = BlockingBuffer.decorate(new MyBuffer<E>(), 100); + E obj = makeElement(); + new DelayedAdd<E>(blockingBuffer, obj, 500).start(); try { blockingBuffer.remove(); - } - catch( BufferUnderflowException e ) { + } catch (BufferUnderflowException e) { } } + //----------------------------------------------------------------------- /** - * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}. + * Tests {@link BlockingBuffer#remove()} in combination with + * {@link BlockingBuffer#addAll(java.util.Collection)}. */ public void testRemoveWithAddAll() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); - new DelayedAddAll( blockingBuffer, obj ).start(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); + new DelayedAddAll<E>(blockingBuffer, obj).start(); // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer . - assertSame( obj, blockingBuffer.remove() ); + assertSame(obj, blockingBuffer.remove()); } public void testRemoveWithAddAllTimeout() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 100 ); - Object obj = new Object(); - new DelayedAddAll( blockingBuffer, obj, 500 ).start(); + Buffer<E> blockingBuffer = BlockingBuffer.decorate(new MyBuffer<E>(), 100); + E obj = makeElement(); + new DelayedAddAll<E>(blockingBuffer, obj, 500).start(); try { blockingBuffer.remove(); - } - catch( BufferUnderflowException e ) { + } catch (BufferUnderflowException e) { } } + //----------------------------------------------------------------------- /** - * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)} using multiple read - * threads. - * <p/> - * Two read threads should block on an empty buffer until one object is added then both threads should complete. + * Tests {@link BlockingBuffer#get()} in combination with + * {@link BlockingBuffer#add(Object)} using multiple read threads. <p/> Two + * read threads should block on an empty buffer until one object is added + * then both threads should complete. */ public void testBlockedGetWithAdd() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); // run methods will get and compare -- must wait for add - Thread thread1 = new ReadThread( blockingBuffer, obj ); - Thread thread2 = new ReadThread( blockingBuffer, obj ); + Thread thread1 = new ReadThread<E>(blockingBuffer, obj); + Thread thread2 = new ReadThread<E>(blockingBuffer, obj); thread1.start(); thread2.start(); @@ -175,32 +185,32 @@ public class TestBlockingBuffer extends AbstractTestObject { delay(); // notifyAll should allow both read threads to complete - blockingBuffer.add( obj ); + blockingBuffer.add(obj); // allow notified threads to complete delay(); // There should not be any threads waiting. - if( thread1.isAlive() || thread2.isAlive() ) { - fail( "Live thread(s) when both should be dead." ); + if (thread1.isAlive() || thread2.isAlive()) { + fail("Live thread(s) when both should be dead."); } } //----------------------------------------------------------------------- /** - * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)} using - * multiple read threads. - * <p/> - * Two read threads should block on an empty buffer until a singleton is added then both threads should complete. + * Tests {@link BlockingBuffer#get()} in combination with + * {@link BlockingBuffer#addAll(java.util.Collection)} using multiple read + * threads. <p/> Two read threads should block on an empty buffer until a + * singleton is added then both threads should complete. */ public void testBlockedGetWithAddAll() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); // run methods will get and compare -- must wait for addAll - Thread thread1 = new ReadThread( blockingBuffer, obj ); - Thread thread2 = new ReadThread( blockingBuffer, obj ); + Thread thread1 = new ReadThread<E>(blockingBuffer, obj); + Thread thread2 = new ReadThread<E>(blockingBuffer, obj); thread1.start(); thread2.start(); @@ -208,14 +218,14 @@ public class TestBlockingBuffer extends AbstractTestObject { delay(); // notifyAll should allow both read threads to complete - blockingBuffer.addAll( Collections.singleton( obj ) ); + blockingBuffer.addAll(Collections.singleton(obj)); // allow notified threads to complete delay(); // There should not be any threads waiting. - if( thread1.isAlive() || thread2.isAlive() ) { - fail( "Live thread(s) when both should be dead." ); + if (thread1.isAlive() || thread2.isAlive()) { + fail("Live thread(s) when both should be dead."); } } @@ -225,12 +235,12 @@ public class TestBlockingBuffer extends AbstractTestObject { * Tests interrupted {@link BlockingBuffer#get()}. */ public void testInterruptedGet() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); // spawn a read thread to wait on the empty buffer - ArrayList exceptionList = new ArrayList(); - Thread thread = new ReadThread( blockingBuffer, obj, exceptionList ); + ArrayList<String> exceptionList = new ArrayList<String>(); + Thread thread = new ReadThread<E>(blockingBuffer, obj, exceptionList); thread.start(); // Interrupting the thread should cause it to throw BufferUnderflowException @@ -238,10 +248,10 @@ public class TestBlockingBuffer extends AbstractTestObject { // Chill, so thread can throw and add message to exceptionList delay(); - assertTrue( "Thread interrupt should have led to underflow", - exceptionList.contains( "BufferUnderFlow" ) ); - if( thread.isAlive() ) { - fail( "Read thread has hung." ); + assertTrue("Thread interrupt should have led to underflow", exceptionList + .contains("BufferUnderFlow")); + if (thread.isAlive()) { + fail("Read thread has hung."); } } @@ -249,115 +259,116 @@ public class TestBlockingBuffer extends AbstractTestObject { //----------------------------------------------------------------------- /** - * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add(Object)} using multiple read - * threads. - * <p/> - * Two read threads should block on an empty buffer until one object is added then one thread should complete. The - * remaining thread should complete after the addition of a second object. + * Tests {@link BlockingBuffer#remove()} in combination with + * {@link BlockingBuffer#add(Object)} using multiple read threads. <p/> Two + * read threads should block on an empty buffer until one object is added + * then one thread should complete. The remaining thread should complete + * after the addition of a second object. */ public void testBlockedRemoveWithAdd() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); // run methods will remove and compare -- must wait for add - Thread thread1 = new ReadThread( blockingBuffer, obj, null, "remove" ); - Thread thread2 = new ReadThread( blockingBuffer, obj, null, "remove" ); + Thread thread1 = new ReadThread<E>(blockingBuffer, obj, null, "remove"); + Thread thread2 = new ReadThread<E>(blockingBuffer, obj, null, "remove"); thread1.start(); thread2.start(); // give hungry read threads ample time to hang delay(); - blockingBuffer.add( obj ); + blockingBuffer.add(obj); // allow notified threads to complete delay(); // There should be one thread waiting. - assertTrue( "There is one thread waiting", thread1.isAlive() ^ thread2.isAlive() ); - blockingBuffer.add( obj ); + assertTrue("There is one thread waiting", thread1.isAlive() ^ thread2.isAlive()); + blockingBuffer.add(obj); // allow notified thread to complete delay(); // There should not be any threads waiting. - if( thread1.isAlive() || thread2.isAlive() ) { - fail( "Live thread(s) when both should be dead." ); + if (thread1.isAlive() || thread2.isAlive()) { + fail("Live thread(s) when both should be dead."); } } //----------------------------------------------------------------------- /** - * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)} - * using multiple read threads. - * <p/> - * Two read threads should block on an empty buffer until a singleton collection is added then one thread should - * complete. The remaining thread should complete after the addition of a second singleton. + * Tests {@link BlockingBuffer#remove()} in combination with + * {@link BlockingBuffer#addAll(java.util.Collection)} using multiple read + * threads. <p/> Two read threads should block on an empty buffer until a + * singleton collection is added then one thread should complete. The + * remaining thread should complete after the addition of a second + * singleton. */ public void testBlockedRemoveWithAddAll1() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); // run methods will remove and compare -- must wait for addAll - Thread thread1 = new ReadThread( blockingBuffer, obj, null, "remove" ); - Thread thread2 = new ReadThread( blockingBuffer, obj, null, "remove" ); + Thread thread1 = new ReadThread<E>(blockingBuffer, obj, null, "remove"); + Thread thread2 = new ReadThread<E>(blockingBuffer, obj, null, "remove"); thread1.start(); thread2.start(); // give hungry read threads ample time to hang delay(); - blockingBuffer.addAll( Collections.singleton( obj ) ); + blockingBuffer.addAll(Collections.singleton(obj)); // allow notified threads to complete delay(); // There should be one thread waiting. - assertTrue( "There is one thread waiting", thread1.isAlive() ^ thread2.isAlive() ); - blockingBuffer.addAll( Collections.singleton( obj ) ); + assertTrue("There is one thread waiting", thread1.isAlive() ^ thread2.isAlive()); + blockingBuffer.addAll(Collections.singleton(obj)); // allow notified thread to complete delay(); // There should not be any threads waiting. - if( thread1.isAlive() || thread2.isAlive() ) { - fail( "Live thread(s) when both should be dead." ); + if (thread1.isAlive() || thread2.isAlive()) { + fail("Live thread(s) when both should be dead."); } } //----------------------------------------------------------------------- /** - * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)} - * using multiple read threads. - * <p/> - * Two read threads should block on an empty buffer until a collection with two distinct objects is added then both - * threads should complete. Each thread should have read a different object. + * Tests {@link BlockingBuffer#remove()} in combination with + * {@link BlockingBuffer#addAll(java.util.Collection)} using multiple read + * threads. <p/> Two read threads should block on an empty buffer until a + * collection with two distinct objects is added then both threads should + * complete. Each thread should have read a different object. */ public void testBlockedRemoveWithAddAll2() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj1 = new Object(); - Object obj2 = new Object(); - Set objs = Collections.synchronizedSet( new HashSet() ); - objs.add( obj1 ); - objs.add( obj2 ); + Buffer<E> blockingBuffer = makeObject(); + E obj1 = makeElement(); + E obj2 = makeElement(); + Set<E> objs = Collections.synchronizedSet(new HashSet<E>()); + objs.add(obj1); + objs.add(obj2); // run methods will remove and compare -- must wait for addAll - Thread thread1 = new ReadThread( blockingBuffer, objs, "remove" ); - Thread thread2 = new ReadThread( blockingBuffer, objs, "remove" ); + Thread thread1 = new ReadThread<E>(blockingBuffer, objs, "remove"); + Thread thread2 = new ReadThread<E>(blockingBuffer, objs, "remove"); thread1.start(); thread2.start(); // give hungry read threads ample time to hang delay(); - blockingBuffer.addAll( objs ); + blockingBuffer.addAll(objs); // allow notified threads to complete delay(); - assertEquals( "Both objects were removed", 0, objs.size() ); + assertEquals("Both objects were removed", 0, objs.size()); // There should not be any threads waiting. - if( thread1.isAlive() || thread2.isAlive() ) { - fail( "Live thread(s) when both should be dead." ); + if (thread1.isAlive() || thread2.isAlive()) { + fail("Live thread(s) when both should be dead."); } } @@ -367,12 +378,12 @@ public class TestBlockingBuffer extends AbstractTestObject { * Tests interrupted remove. */ public void testInterruptedRemove() { - Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() ); - Object obj = new Object(); + Buffer<E> blockingBuffer = makeObject(); + E obj = makeElement(); // spawn a read thread to wait on the empty buffer - ArrayList exceptionList = new ArrayList(); - Thread thread = new ReadThread( blockingBuffer, obj, exceptionList, "remove" ); + ArrayList<String> exceptionList = new ArrayList<String>(); + Thread thread = new ReadThread<E>(blockingBuffer, obj, exceptionList, "remove"); thread.start(); // Interrupting the thread should cause it to throw BufferUnderflowException @@ -380,49 +391,47 @@ public class TestBlockingBuffer extends AbstractTestObject { // Chill, so thread can throw and add message to exceptionList delay(); - assertTrue( "Thread interrupt should have led to underflow", - exceptionList.contains( "BufferUnderFlow" ) ); - if( thread.isAlive() ) { - fail( "Read thread has hung." ); + assertTrue("Thread interrupt should have led to underflow", exceptionList + .contains("BufferUnderFlow")); + if (thread.isAlive()) { + fail("Read thread has hung."); } } public void testTimeoutGet() { - final BlockingBuffer buffer = new BlockingBuffer( new MyBuffer() ); + final BlockingBuffer<E> buffer = new BlockingBuffer<E>(new MyBuffer<E>()); try { - buffer.get( 100 ); - fail( "Get should have timed out." ); - } - catch( BufferUnderflowException e ) { + buffer.get(100); + fail("Get should have timed out."); + } catch (BufferUnderflowException e) { } } public void testTimeoutRemove() { - final BlockingBuffer buffer = new BlockingBuffer( new MyBuffer() ); + final BlockingBuffer<E> buffer = new BlockingBuffer<E>(new MyBuffer<E>()); try { - buffer.remove( 100 ); - fail( "Get should have timed out." ); - } - catch( BufferUnderflowException e ) { + buffer.remove(100); + fail("Get should have timed out."); + } catch (BufferUnderflowException e) { } } - protected static class DelayedAdd extends Thread { + protected static class DelayedAdd<E> extends Thread { - Buffer buffer; + Buffer<E> buffer; - Object obj; + E obj; long delay = 1000; - public DelayedAdd( Buffer buffer, Object obj, long delay ) { + public DelayedAdd(Buffer<E> buffer, E obj, long delay) { this.buffer = buffer; this.obj = obj; this.delay = delay; } - DelayedAdd( Buffer buffer, Object obj ) { + DelayedAdd(Buffer<E> buffer, E obj) { super(); this.buffer = buffer; this.obj = obj; @@ -431,29 +440,28 @@ public class TestBlockingBuffer extends AbstractTestObject { public void run() { try { // wait for other thread to block on get() or remove() - Thread.sleep( delay ); - } - catch( InterruptedException e ) { + Thread.sleep(delay); + } catch (InterruptedException e) { } - buffer.add( obj ); + buffer.add(obj); } } - protected static class DelayedAddAll extends Thread { + protected static class DelayedAddAll<E> extends Thread { - Buffer buffer; + Buffer<E> buffer; - Object obj; + E obj; long delay = 100; - public DelayedAddAll( Buffer buffer, Object obj, long delay ) { + public DelayedAddAll(Buffer<E> buffer, E obj, long delay) { this.buffer = buffer; this.obj = obj; this.delay = delay; } - DelayedAddAll( Buffer buffer, Object obj ) { + DelayedAddAll(Buffer<E> buffer, E obj) { super(); this.buffer = buffer; this.obj = obj; @@ -462,40 +470,39 @@ public class TestBlockingBuffer extends AbstractTestObject { public void run() { try { // wait for other thread to block on get() or remove() - Thread.sleep( delay ); - } - catch( InterruptedException e ) { + Thread.sleep(delay); + } catch (InterruptedException e) { } - buffer.addAll( Collections.singleton( obj ) ); + buffer.addAll(Collections.singleton(obj)); } } - protected static class ReadThread extends Thread { + protected static class ReadThread<E> extends Thread { - Buffer buffer; + Buffer<E> buffer; Object obj; - ArrayList exceptionList = null; + ArrayList<String> exceptionList = null; String action = "get"; - Set objs; + Set<E> objs; - ReadThread( Buffer buffer, Object obj ) { + ReadThread(Buffer<E> buffer, Object obj) { super(); this.buffer = buffer; this.obj = obj; } - ReadThread( Buffer buffer, Object obj, ArrayList exceptionList ) { + ReadThread(Buffer<E> buffer, Object obj, ArrayList<String> exceptionList) { super(); this.buffer = buffer; this.obj = obj; this.exceptionList = exceptionList; } - ReadThread( Buffer buffer, Object obj, ArrayList exceptionList, String action ) { + ReadThread(Buffer<E> buffer, Object obj, ArrayList<String> exceptionList, String action) { super(); this.buffer = buffer; this.obj = obj; @@ -503,7 +510,7 @@ public class TestBlockingBuffer extends AbstractTestObject { this.action = action; } - ReadThread( Buffer buffer, Set objs, String action ) { + ReadThread(Buffer<E> buffer, Set<E> objs, String action) { super(); this.buffer = buffer; this.objs = objs; @@ -512,46 +519,43 @@ public class TestBlockingBuffer extends AbstractTestObject { public void run() { try { - if( action == "get" ) { - assertSame( obj, buffer.get() ); - } - else { - if( null != obj ) { - assertSame( obj, buffer.remove() ); - } - else { - assertTrue( objs.remove( buffer.remove() ) ); + if (action == "get") { + assertSame(obj, buffer.get()); + } else { + if (null != obj) { + assertSame(obj, buffer.remove()); + } else { + assertTrue(objs.remove(buffer.remove())); } } - } - catch( BufferUnderflowException ex ) { - exceptionList.add( "BufferUnderFlow" ); + } catch (BufferUnderflowException ex) { + exceptionList.add("BufferUnderFlow"); } } } - protected static class MyBuffer extends LinkedList implements Buffer { + @SuppressWarnings("serial") + protected static class MyBuffer<E> extends LinkedList<E> implements Buffer<E> { - public Object get() { - if( isEmpty() ) { + public E get() { + if (isEmpty()) { throw new BufferUnderflowException(); } - return get( 0 ); + return get(0); } - public Object remove() { - if( isEmpty() ) { + public E remove() { + if (isEmpty()) { throw new BufferUnderflowException(); } - return remove( 0 ); + return remove(0); } } private void delay() { try { - Thread.sleep( 100 ); - } - catch( InterruptedException e ) { + Thread.sleep(100); + } catch (InterruptedException e) { } } @@ -559,15 +563,15 @@ public class TestBlockingBuffer extends AbstractTestObject { return "3.1"; } -// public void testCreate() throws Exception { -// Buffer buffer = BlockingBuffer.decorate(new UnboundedFifoBuffer()); -// writeExternalFormToDisk((java.io.Serializable) buffer, -// "D:/dev/collections/data/test/BlockingBuffer.emptyCollection.version3.1.obj"); -// buffer = BlockingBuffer.decorate(new UnboundedFifoBuffer()); -// buffer.add("A"); -// buffer.add("B"); -// buffer.add("C"); -// writeExternalFormToDisk((java.io.Serializable) buffer, -// "D:/dev/collections/data/test/BlockingBuffer.fullCollection.version3.1.obj"); -// } + // public void testCreate() throws Exception { + // Buffer buffer = BlockingBuffer.decorate(new UnboundedFifoBuffer()); + // writeExternalFormToDisk((java.io.Serializable) buffer, + // "D:/dev/collections/data/test/BlockingBuffer.emptyCollection.version3.1.obj"); + // buffer = BlockingBuffer.decorate(new UnboundedFifoBuffer()); + // buffer.add("A"); + // buffer.add("B"); + // buffer.add("C"); + // writeExternalFormToDisk((java.io.Serializable) buffer, + // "D:/dev/collections/data/test/BlockingBuffer.fullCollection.version3.1.obj"); + // } }