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/branches/COLLECTIONS_3_2_BRANCH@1079602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ef4dd46dbd
commit
a0603b1547
5
pom.xml
5
pom.xml
|
@ -148,11 +148,14 @@
|
||||||
<name>Janek Bogucki</name>
|
<name>Janek Bogucki</name>
|
||||||
</contributor>
|
</contributor>
|
||||||
<contributor>
|
<contributor>
|
||||||
<name>Chuck Burdick</name>
|
<name>Maarten Brak</name>
|
||||||
</contributor>
|
</contributor>
|
||||||
<contributor>
|
<contributor>
|
||||||
<name>Dave Bryson</name>
|
<name>Dave Bryson</name>
|
||||||
</contributor>
|
</contributor>
|
||||||
|
<contributor>
|
||||||
|
<name>Chuck Burdick</name>
|
||||||
|
</contributor>
|
||||||
<contributor>
|
<contributor>
|
||||||
<name>Julien Buret</name>
|
<name>Julien Buret</name>
|
||||||
</contributor>
|
</contributor>
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class AbstractHashedMap extends AbstractMap implements IterableMap {
|
||||||
* default load factor.
|
* default load factor.
|
||||||
*
|
*
|
||||||
* @param initialCapacity the 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 AbstractHashedMap(int initialCapacity) {
|
protected AbstractHashedMap(int initialCapacity) {
|
||||||
this(initialCapacity, DEFAULT_LOAD_FACTOR);
|
this(initialCapacity, DEFAULT_LOAD_FACTOR);
|
||||||
|
@ -135,13 +135,13 @@ public class AbstractHashedMap extends AbstractMap implements IterableMap {
|
||||||
*
|
*
|
||||||
* @param initialCapacity the initial capacity
|
* @param initialCapacity the initial capacity
|
||||||
* @param loadFactor the load factor
|
* @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
|
* @throws IllegalArgumentException if the load factor is less than or equal to zero
|
||||||
*/
|
*/
|
||||||
protected AbstractHashedMap(int initialCapacity, float loadFactor) {
|
protected AbstractHashedMap(int initialCapacity, float loadFactor) {
|
||||||
super();
|
super();
|
||||||
if (initialCapacity < 1) {
|
if (initialCapacity < 0) {
|
||||||
throw new IllegalArgumentException("Initial capacity must be greater than 0");
|
throw new IllegalArgumentException("Initial capacity must be a non negative number");
|
||||||
}
|
}
|
||||||
if (loadFactor <= 0.0f || Float.isNaN(loadFactor)) {
|
if (loadFactor <= 0.0f || Float.isNaN(loadFactor)) {
|
||||||
throw new IllegalArgumentException("Load factor must be greater than 0");
|
throw new IllegalArgumentException("Load factor must be greater than 0");
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class AbstractLinkedMap extends AbstractHashedMap implements OrderedMap {
|
||||||
* Constructs a new, empty map with the specified initial capacity.
|
* Constructs a new, empty map with the specified initial capacity.
|
||||||
*
|
*
|
||||||
* @param initialCapacity the 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) {
|
protected AbstractLinkedMap(int initialCapacity) {
|
||||||
super(initialCapacity);
|
super(initialCapacity);
|
||||||
|
@ -102,7 +102,7 @@ public class AbstractLinkedMap extends AbstractHashedMap implements OrderedMap {
|
||||||
*
|
*
|
||||||
* @param initialCapacity the initial capacity
|
* @param initialCapacity the initial capacity
|
||||||
* @param loadFactor the load factor
|
* @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
|
* @throws IllegalArgumentException if the load factor is less than zero
|
||||||
*/
|
*/
|
||||||
protected AbstractLinkedMap(int initialCapacity, float loadFactor) {
|
protected AbstractLinkedMap(int initialCapacity, float loadFactor) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class CaseInsensitiveMap extends AbstractHashedMap implements Serializabl
|
||||||
* Constructs a new, empty map with the specified initial capacity.
|
* Constructs a new, empty map with the specified initial capacity.
|
||||||
*
|
*
|
||||||
* @param initialCapacity the 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) {
|
public CaseInsensitiveMap(int initialCapacity) {
|
||||||
super(initialCapacity);
|
super(initialCapacity);
|
||||||
|
@ -90,7 +90,7 @@ public class CaseInsensitiveMap extends AbstractHashedMap implements Serializabl
|
||||||
*
|
*
|
||||||
* @param initialCapacity the initial capacity
|
* @param initialCapacity the initial capacity
|
||||||
* @param loadFactor the load factor
|
* @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
|
* @throws IllegalArgumentException if the load factor is less than zero
|
||||||
*/
|
*/
|
||||||
public CaseInsensitiveMap(int initialCapacity, float loadFactor) {
|
public CaseInsensitiveMap(int initialCapacity, float loadFactor) {
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class HashedMap
|
||||||
* Constructs a new, empty map with the specified initial capacity.
|
* Constructs a new, empty map with the specified initial capacity.
|
||||||
*
|
*
|
||||||
* @param initialCapacity the 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) {
|
public HashedMap(int initialCapacity) {
|
||||||
super(initialCapacity);
|
super(initialCapacity);
|
||||||
|
@ -70,7 +70,7 @@ public class HashedMap
|
||||||
*
|
*
|
||||||
* @param initialCapacity the initial capacity
|
* @param initialCapacity the initial capacity
|
||||||
* @param loadFactor the load factor
|
* @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
|
* @throws IllegalArgumentException if the load factor is less than zero
|
||||||
*/
|
*/
|
||||||
public HashedMap(int initialCapacity, float loadFactor) {
|
public HashedMap(int initialCapacity, float loadFactor) {
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class IdentityMap
|
||||||
* Constructs a new, empty map with the specified initial capacity.
|
* Constructs a new, empty map with the specified initial capacity.
|
||||||
*
|
*
|
||||||
* @param initialCapacity the 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) {
|
public IdentityMap(int initialCapacity) {
|
||||||
super(initialCapacity);
|
super(initialCapacity);
|
||||||
|
@ -72,7 +72,7 @@ public class IdentityMap
|
||||||
*
|
*
|
||||||
* @param initialCapacity the initial capacity
|
* @param initialCapacity the initial capacity
|
||||||
* @param loadFactor the load factor
|
* @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
|
* @throws IllegalArgumentException if the load factor is less than zero
|
||||||
*/
|
*/
|
||||||
public IdentityMap(int initialCapacity, float loadFactor) {
|
public IdentityMap(int initialCapacity, float loadFactor) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class LinkedMap
|
||||||
* Constructs a new, empty map with the specified initial capacity.
|
* Constructs a new, empty map with the specified initial capacity.
|
||||||
*
|
*
|
||||||
* @param initialCapacity the 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) {
|
public LinkedMap(int initialCapacity) {
|
||||||
super(initialCapacity);
|
super(initialCapacity);
|
||||||
|
@ -91,7 +91,7 @@ public class LinkedMap
|
||||||
*
|
*
|
||||||
* @param initialCapacity the initial capacity
|
* @param initialCapacity the initial capacity
|
||||||
* @param loadFactor the load factor
|
* @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
|
* @throws IllegalArgumentException if the load factor is less than zero
|
||||||
*/
|
*/
|
||||||
public LinkedMap(int initialCapacity, float loadFactor) {
|
public LinkedMap(int initialCapacity, float loadFactor) {
|
||||||
|
|
|
@ -117,4 +117,12 @@ public class TestCaseInsensitiveMap extends AbstractTestIterableMap {
|
||||||
writeExternalFormToDisk((java.io.Serializable) map, "/home/phil/jakarta-commons/collections/data/test/CaseInsensitiveMap.fullCollection.version3.obj");
|
writeExternalFormToDisk((java.io.Serializable) map, "/home/phil/jakarta-commons/collections/data/test/CaseInsensitiveMap.fullCollection.version3.obj");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for <a href="https://issues.apache.org/jira/browse/COLLECTIONS-323">COLLECTIONS-323</a>.
|
||||||
|
*/
|
||||||
|
public void testInitialCapacityZero() {
|
||||||
|
final CaseInsensitiveMap map = new CaseInsensitiveMap(0);
|
||||||
|
assertEquals(1, map.data.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,4 +75,12 @@ public class TestHashedMap extends AbstractTestIterableMap {
|
||||||
// resetFull();
|
// resetFull();
|
||||||
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/HashedMap.fullCollection.version3.obj");
|
// 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 map = new HashedMap(0);
|
||||||
|
assertEquals(1, map.data.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,4 +143,12 @@ public class TestIdentityMap extends AbstractTestObject {
|
||||||
// map.put(I2A, I2B);
|
// map.put(I2A, I2B);
|
||||||
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/IdentityMap.fullCollection.version3.obj");
|
// 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 map = new IdentityMap(0);
|
||||||
|
assertEquals(1, map.data.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,4 +272,12 @@ public class TestLinkedMap extends AbstractTestOrderedMap {
|
||||||
// resetFull();
|
// resetFull();
|
||||||
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/LinkedMap.fullCollection.version3.obj");
|
// writeExternalFormToDisk((java.io.Serializable) map, "D:/dev/collections/data/test/LinkedMap.fullCollection.version3.obj");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for <a href="https://issues.apache.org/jira/browse/COLLECTIONS-323">COLLECTIONS-323</a>.
|
||||||
|
*/
|
||||||
|
public void testInitialCapacityZero() {
|
||||||
|
final LinkedMap map = new LinkedMap(0);
|
||||||
|
assertEquals(1, map.data.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue