More fixes from Unit tests.

-Fixed: ArrayList/LinkedList extractElements crashing when 0 or less elements are desired.
-Fixed: TreeMap pollFirst/LastKey should return the defaultMin/max value instead of a Empty value.
-Fixed: TreeMap keySet implementation was missing the class type implementations to pass keySet tests.
-Fixed: TreeMap.SubMap Iterator (primitive Keys) was crashing because a Null was set on to a primitive.
This commit is contained in:
Speiger 2022-05-27 16:35:41 +02:00
parent e7da7acc08
commit 27ad01657d
5 changed files with 79 additions and 25 deletions

View File

@ -18,7 +18,7 @@ repositories {
}
archivesBaseName = 'Primitive Collections'
version = '0.6.1.10';
version = '0.6.1.17-SNAPSHOT';
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();

View File

@ -362,11 +362,11 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
int length = to - from;
if(length <= 0) return;
if(to != size) System.arraycopy(data, to, data, from, size - to);
size -= length;
#if TYPE_OBJECT
for(int i = 0;i<length;i++)
data[i+to] = null;
data[i+size] = null;
#endif
size -= length;
}
#if TYPE_OBJECT
@ -382,13 +382,13 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
checkRange(from);
checkAddRange(to);
int length = to - from;
if(length <= 0) return ARRAYS.newArray(type, 0);
K[] a = ARRAYS.newArray(type, length);
if(length <= 0) return a;
System.arraycopy(data, from, a, 0, length);
if(to != size) System.arraycopy(data, to, data, from, size - to);
for(int i = 0;i<length;i++)
data[i+to] = null;
size -= length;
for(int i = 0;i<length;i++)
data[i+size] = null;
return a;
}

View File

@ -722,8 +722,8 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
checkRange(from);
checkAddRange(to);
int length = to - from;
if(length <= 0) return ARRAYS.newArray(type, 0);
K[] a = ARRAYS.newArray(type, length);
if(length <= 0) return a;
if(from < size - to) {
Entry KEY_GENERIC_TYPE entry = getNode(from);
for(int i = 0;length > 0;i++, length--) {

View File

@ -408,7 +408,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
@Override
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
if(tree == null) return EMPTY_KEY_VALUE;
if(tree == null) return getDefaultMinValue();
KEY_TYPE result = first.key;
removeNode(first);
return result;
@ -422,7 +422,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
@Override
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
if(tree == null) return EMPTY_KEY_VALUE;
if(tree == null) return getDefaultMaxValue();
KEY_TYPE result = last.key;
removeNode(last);
return result;
@ -1022,6 +1022,33 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
@Override
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
#if !TYPE_OBJECT
@Override
public CLASS_TYPE lower(CLASS_TYPE e) {
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.lowerEntry(OBJ_TO_KEY(e));
return node != null ? node.getKey() : null;
}
@Override
public CLASS_TYPE floor(CLASS_TYPE e) {
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.floorEntry(OBJ_TO_KEY(e));
return node != null ? node.getKey() : null;
}
@Override
public CLASS_TYPE higher(CLASS_TYPE e) {
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.higherEntry(OBJ_TO_KEY(e));
return node != null ? node.getKey() : null;
}
@Override
public CLASS_TYPE ceiling(CLASS_TYPE e) {
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.ceilingEntry(OBJ_TO_KEY(e));
return node != null ? node.getKey() : null;
}
#endif
@Override
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
@Override
@ -1461,8 +1488,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
protected abstract BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMinValue() : entry.key; }
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMaxValue() : entry.key; }
protected Node KEY_VALUE_GENERIC_TYPE next(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.next(); }
protected Node KEY_VALUE_GENERIC_TYPE previous(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.previous(); }
@ -1533,7 +1560,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
map.removeNode(entry);
return result;
}
return EMPTY_KEY_VALUE;
return getDefaultMinValue();
}
@Override
@ -1544,7 +1571,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
map.removeNode(entry);
return result;
}
return EMPTY_KEY_VALUE;
return getDefaultMaxValue();
}
@Override
@ -1632,7 +1659,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
@Override
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
return inRange(key) ? map.REMOVE_VALUE(key) : defaultValue;
return inRange(key) ? map.REMOVE_VALUEOrDefault(key, defaultValue) : defaultValue;
}
#if TYPE_OBJECT && VALUE_OBJECT
@ -2147,8 +2174,8 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence)
{
next = first;
this.forwardFence = forwardFence == null ? null : forwardFence.key;
this.backwardFence = backwardFence == null ? null : backwardFence.key;
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
unboundForwardFence = forwardFence == null;
unboundBackwardFence = backwardFence == null;
}

View File

@ -411,7 +411,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
@Override
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
if(tree == null) return EMPTY_KEY_VALUE;
if(tree == null) return getDefaultMinValue();
KEY_TYPE result = first.key;
removeNode(first);
return result;
@ -425,7 +425,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
@Override
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
if(tree == null) return EMPTY_KEY_VALUE;
if(tree == null) return getDefaultMaxValue();
KEY_TYPE result = last.key;
removeNode(last);
return result;
@ -1080,6 +1080,33 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
@Override
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
#if !TYPE_OBJECT
@Override
public CLASS_TYPE lower(CLASS_TYPE e) {
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.lowerEntry(OBJ_TO_KEY(e));
return node != null ? node.getKey() : null;
}
@Override
public CLASS_TYPE floor(CLASS_TYPE e) {
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.floorEntry(OBJ_TO_KEY(e));
return node != null ? node.getKey() : null;
}
@Override
public CLASS_TYPE higher(CLASS_TYPE e) {
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.higherEntry(OBJ_TO_KEY(e));
return node != null ? node.getKey() : null;
}
@Override
public CLASS_TYPE ceiling(CLASS_TYPE e) {
MAP.Entry KEY_VALUE_GENERIC_TYPE node = map.ceilingEntry(OBJ_TO_KEY(e));
return node != null ? node.getKey() : null;
}
#endif
@Override
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
@Override
@ -1518,8 +1545,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
protected abstract BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? EMPTY_KEY_VALUE : entry.key; }
protected KEY_TYPE lowKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMinValue() : entry.key; }
protected KEY_TYPE highKeyOrNull(Node KEY_VALUE_GENERIC_TYPE entry) { return entry == null ? getDefaultMaxValue() : entry.key; }
protected Node KEY_VALUE_GENERIC_TYPE next(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.next(); }
protected Node KEY_VALUE_GENERIC_TYPE previous(Node KEY_VALUE_GENERIC_TYPE entry) { return entry.previous(); }
@ -1590,7 +1617,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
map.removeNode(entry);
return result;
}
return EMPTY_KEY_VALUE;
return getDefaultMinValue();
}
@Override
@ -1601,7 +1628,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
map.removeNode(entry);
return result;
}
return EMPTY_KEY_VALUE;
return getDefaultMaxValue();
}
@Override
@ -1689,7 +1716,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
@Override
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
return inRange(key) ? map.REMOVE_VALUE(key) : defaultValue;
return inRange(key) ? map.REMOVE_VALUEOrDefault(key, defaultValue) : defaultValue;
}
#if TYPE_OBJECT && VALUE_OBJECT
@ -2204,8 +2231,8 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence)
{
next = first;
this.forwardFence = forwardFence == null ? null : forwardFence.key;
this.backwardFence = backwardFence == null ? null : backwardFence.key;
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
unboundForwardFence = forwardFence == null;
unboundBackwardFence = backwardFence == null;
}