PR: COLLECTIONS-323
Submitted-By: Maarten Brak <maarten.brak@quinity.com> Allow to use an initial capacity of 0 on certain maps. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1079602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e4ba77b3b1
commit
cb19f2d73f
5
pom.xml
5
pom.xml
|
@ -129,11 +129,14 @@
|
|||
<name>Janek Bogucki</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Chuck Burdick</name>
|
||||
<name>Maarten Brak</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Dave Bryson</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Chuck Burdick</name>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Julien Buret</name>
|
||||
</contributor>
|
||||
|
|
|
@ -124,7 +124,7 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
* default load factor.
|
||||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
*/
|
||||
protected AbstractHashedMap(int initialCapacity) {
|
||||
this(initialCapacity, DEFAULT_LOAD_FACTOR);
|
||||
|
@ -136,14 +136,14 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @param loadFactor the load factor
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IlleagalArgumentException if the initial capacity is negative
|
||||
* @throws IllegalArgumentException if the load factor is less than or equal to zero
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected AbstractHashedMap(int initialCapacity, float loadFactor) {
|
||||
super();
|
||||
if (initialCapacity < 1) {
|
||||
throw new IllegalArgumentException("Initial capacity must be greater than 0");
|
||||
if (initialCapacity < 0) {
|
||||
throw new IllegalArgumentException("Initial capacity must be a non negative number");
|
||||
}
|
||||
if (loadFactor <= 0.0f || Float.isNaN(loadFactor)) {
|
||||
throw new IllegalArgumentException("Load factor must be greater than 0");
|
||||
|
|
|
@ -89,7 +89,7 @@ public abstract class AbstractLinkedMap<K, V> extends AbstractHashedMap<K, V> im
|
|||
* Constructs a new, empty map with the specified initial capacity.
|
||||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
*/
|
||||
protected AbstractLinkedMap(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
|
@ -101,7 +101,7 @@ public abstract class AbstractLinkedMap<K, V> extends AbstractHashedMap<K, V> im
|
|||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @param loadFactor the load factor
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
* @throws IllegalArgumentException if the load factor is less than zero
|
||||
*/
|
||||
protected AbstractLinkedMap(int initialCapacity, float loadFactor) {
|
||||
|
|
|
@ -78,7 +78,7 @@ public class CaseInsensitiveMap<K, V> extends AbstractHashedMap<K, V> implements
|
|||
* Constructs a new, empty map with the specified initial capacity.
|
||||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
*/
|
||||
public CaseInsensitiveMap(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
|
@ -90,7 +90,7 @@ public class CaseInsensitiveMap<K, V> extends AbstractHashedMap<K, V> implements
|
|||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @param loadFactor the load factor
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
* @throws IllegalArgumentException if the load factor is less than zero
|
||||
*/
|
||||
public CaseInsensitiveMap(int initialCapacity, float loadFactor) {
|
||||
|
|
|
@ -58,7 +58,7 @@ public class HashedMap<K, V>
|
|||
* Constructs a new, empty map with the specified initial capacity.
|
||||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
*/
|
||||
public HashedMap(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
|
@ -70,7 +70,7 @@ public class HashedMap<K, V>
|
|||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @param loadFactor the load factor
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
* @throws IllegalArgumentException if the load factor is less than zero
|
||||
*/
|
||||
public HashedMap(int initialCapacity, float loadFactor) {
|
||||
|
|
|
@ -60,7 +60,7 @@ public class IdentityMap<K, V>
|
|||
* Constructs a new, empty map with the specified initial capacity.
|
||||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
*/
|
||||
public IdentityMap(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
|
@ -72,7 +72,7 @@ public class IdentityMap<K, V>
|
|||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @param loadFactor the load factor
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
* @throws IllegalArgumentException if the load factor is less than zero
|
||||
*/
|
||||
public IdentityMap(int initialCapacity, float loadFactor) {
|
||||
|
|
|
@ -78,7 +78,7 @@ public class LinkedMap<K, V> extends AbstractLinkedMap<K, V> implements Serializ
|
|||
* Constructs a new, empty map with the specified initial capacity.
|
||||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
*/
|
||||
public LinkedMap(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
|
@ -90,7 +90,7 @@ public class LinkedMap<K, V> extends AbstractLinkedMap<K, V> implements Serializ
|
|||
*
|
||||
* @param initialCapacity the initial capacity
|
||||
* @param loadFactor the load factor
|
||||
* @throws IllegalArgumentException if the initial capacity is less than one
|
||||
* @throws IllegalArgumentException if the initial capacity is negative
|
||||
* @throws IllegalArgumentException if the load factor is less than zero
|
||||
*/
|
||||
public LinkedMap(int initialCapacity, float loadFactor) {
|
||||
|
|
|
@ -146,4 +146,11 @@ public class TestCaseInsensitiveMap<K, V> extends AbstractTestIterableMap<K, V>
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for <a href="https://issues.apache.org/jira/browse/COLLECTIONS-323">COLLECTIONS-323</a>.
|
||||
*/
|
||||
public void testInitialCapacityZero() {
|
||||
final CaseInsensitiveMap<String,String> map = new CaseInsensitiveMap<String,String>(0);
|
||||
assertEquals(1, map.data.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,4 +70,12 @@ public class TestHashedMap<K, V> extends AbstractTestIterableMap<K, V> {
|
|||
// resetFull();
|
||||
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/HashedMap.fullCollection.version3.obj");
|
||||
// }
|
||||
|
||||
/**
|
||||
* Test for <a href="https://issues.apache.org/jira/browse/COLLECTIONS-323">COLLECTIONS-323</a>.
|
||||
*/
|
||||
public void testInitialCapacityZero() {
|
||||
final HashedMap<String,String> map = new HashedMap<String,String>(0);
|
||||
assertEquals(1, map.data.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,4 +143,12 @@ public class TestIdentityMap<K, V> extends AbstractTestObject {
|
|||
// map.put(I2A, I2B);
|
||||
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/IdentityMap.fullCollection.version3.obj");
|
||||
// }
|
||||
|
||||
/**
|
||||
* Test for <a href="https://issues.apache.org/jira/browse/COLLECTIONS-323">COLLECTIONS-323</a>.
|
||||
*/
|
||||
public void testInitialCapacityZero() {
|
||||
final IdentityMap<String,String> map = new IdentityMap<String,String>(0);
|
||||
assertEquals(1, map.data.length);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -295,4 +295,12 @@ public class TestLinkedMap<K, V> extends AbstractTestOrderedMap<K, V> {
|
|||
public LinkedMap<K, V> getMap() {
|
||||
return (LinkedMap<K, V>) super.getMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for <a href="https://issues.apache.org/jira/browse/COLLECTIONS-323">COLLECTIONS-323</a>.
|
||||
*/
|
||||
public void testInitialCapacityZero() {
|
||||
final LinkedMap<String,String> map = new LinkedMap<String,String>(0);
|
||||
assertEquals(1, map.data.length);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue