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:
parent
e7da7acc08
commit
27ad01657d
|
@ -18,7 +18,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = 'Primitive Collections'
|
archivesBaseName = 'Primitive Collections'
|
||||||
version = '0.6.1.10';
|
version = '0.6.1.17-SNAPSHOT';
|
||||||
|
|
||||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = JavaVersion.current();
|
||||||
|
|
||||||
|
|
|
@ -362,11 +362,11 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
int length = to - from;
|
int length = to - from;
|
||||||
if(length <= 0) return;
|
if(length <= 0) return;
|
||||||
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
||||||
|
size -= length;
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
for(int i = 0;i<length;i++)
|
for(int i = 0;i<length;i++)
|
||||||
data[i+to] = null;
|
data[i+size] = null;
|
||||||
#endif
|
#endif
|
||||||
size -= length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TYPE_OBJECT
|
#if TYPE_OBJECT
|
||||||
|
@ -382,13 +382,13 @@ public class ARRAY_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
checkRange(from);
|
checkRange(from);
|
||||||
checkAddRange(to);
|
checkAddRange(to);
|
||||||
int length = to - from;
|
int length = to - from;
|
||||||
|
if(length <= 0) return ARRAYS.newArray(type, 0);
|
||||||
K[] a = ARRAYS.newArray(type, length);
|
K[] a = ARRAYS.newArray(type, length);
|
||||||
if(length <= 0) return a;
|
|
||||||
System.arraycopy(data, from, a, 0, length);
|
System.arraycopy(data, from, a, 0, length);
|
||||||
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
if(to != size) System.arraycopy(data, to, data, from, size - to);
|
||||||
|
size -= length;
|
||||||
for(int i = 0;i<length;i++)
|
for(int i = 0;i<length;i++)
|
||||||
data[i+to] = null;
|
data[i+size] = null;
|
||||||
size -= length;
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -722,8 +722,8 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE
|
||||||
checkRange(from);
|
checkRange(from);
|
||||||
checkAddRange(to);
|
checkAddRange(to);
|
||||||
int length = to - from;
|
int length = to - from;
|
||||||
|
if(length <= 0) return ARRAYS.newArray(type, 0);
|
||||||
K[] a = ARRAYS.newArray(type, length);
|
K[] a = ARRAYS.newArray(type, length);
|
||||||
if(length <= 0) return a;
|
|
||||||
if(from < size - to) {
|
if(from < size - to) {
|
||||||
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
Entry KEY_GENERIC_TYPE entry = getNode(from);
|
||||||
for(int i = 0;length > 0;i++, length--) {
|
for(int i = 0;length > 0;i++, length--) {
|
||||||
|
|
|
@ -408,7 +408,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
||||||
if(tree == null) return EMPTY_KEY_VALUE;
|
if(tree == null) return getDefaultMinValue();
|
||||||
KEY_TYPE result = first.key;
|
KEY_TYPE result = first.key;
|
||||||
removeNode(first);
|
removeNode(first);
|
||||||
return result;
|
return result;
|
||||||
|
@ -422,7 +422,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
||||||
if(tree == null) return EMPTY_KEY_VALUE;
|
if(tree == null) return getDefaultMaxValue();
|
||||||
KEY_TYPE result = last.key;
|
KEY_TYPE result = last.key;
|
||||||
removeNode(last);
|
removeNode(last);
|
||||||
return result;
|
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); }
|
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
|
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
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||||
@Override
|
@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 BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
|
||||||
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
||||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
|
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 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 ? EMPTY_KEY_VALUE : 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 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(); }
|
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);
|
map.removeNode(entry);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return getDefaultMinValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1544,7 +1571,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||||
map.removeNode(entry);
|
map.removeNode(entry);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return getDefaultMaxValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1632,7 +1659,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
|
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
|
#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)
|
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
this.forwardFence = forwardFence == null ? null : forwardFence.key;
|
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||||
this.backwardFence = backwardFence == null ? null : backwardFence.key;
|
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||||
unboundForwardFence = forwardFence == null;
|
unboundForwardFence = forwardFence == null;
|
||||||
unboundBackwardFence = backwardFence == null;
|
unboundBackwardFence = backwardFence == null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,7 +411,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
public KEY_TYPE POLL_FIRST_ENTRY_KEY() {
|
||||||
if(tree == null) return EMPTY_KEY_VALUE;
|
if(tree == null) return getDefaultMinValue();
|
||||||
KEY_TYPE result = first.key;
|
KEY_TYPE result = first.key;
|
||||||
removeNode(first);
|
removeNode(first);
|
||||||
return result;
|
return result;
|
||||||
|
@ -425,7 +425,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
public KEY_TYPE POLL_LAST_ENTRY_KEY() {
|
||||||
if(tree == null) return EMPTY_KEY_VALUE;
|
if(tree == null) return getDefaultMaxValue();
|
||||||
KEY_TYPE result = last.key;
|
KEY_TYPE result = last.key;
|
||||||
removeNode(last);
|
removeNode(last);
|
||||||
return result;
|
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); }
|
public KEY_TYPE ceiling(KEY_TYPE e) { return map.ceilingKey(e); }
|
||||||
@Override
|
@Override
|
||||||
public KEY_TYPE higher(KEY_TYPE e) { return map.higherKey(e); }
|
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
|
@Override
|
||||||
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
public KEY_TYPE POLL_FIRST_KEY() { return map.POLL_FIRST_ENTRY_KEY(); }
|
||||||
@Override
|
@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 BI_ITERATOR KEY_GENERIC_TYPE keyIterator(KEY_TYPE element);
|
||||||
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
protected abstract VALUE_BI_ITERATOR VALUE_GENERIC_TYPE valueIterator();
|
||||||
protected abstract BI_ITERATOR KEY_GENERIC_TYPE descendingKeyIterator();
|
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 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 ? EMPTY_KEY_VALUE : 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 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(); }
|
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);
|
map.removeNode(entry);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return getDefaultMinValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1601,7 +1628,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||||
map.removeNode(entry);
|
map.removeNode(entry);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return EMPTY_KEY_VALUE;
|
return getDefaultMaxValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1689,7 +1716,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VALUE_TYPE REMOVE_VALUEOrDefault(KEY_TYPE key, VALUE_TYPE defaultValue) {
|
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
|
#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)
|
public SubMapEntryIterator(Node KEY_VALUE_GENERIC_TYPE first, Node KEY_VALUE_GENERIC_TYPE forwardFence, Node KEY_VALUE_GENERIC_TYPE backwardFence)
|
||||||
{
|
{
|
||||||
next = first;
|
next = first;
|
||||||
this.forwardFence = forwardFence == null ? null : forwardFence.key;
|
this.forwardFence = forwardFence == null ? EMPTY_KEY_VALUE : forwardFence.key;
|
||||||
this.backwardFence = backwardFence == null ? null : backwardFence.key;
|
this.backwardFence = backwardFence == null ? EMPTY_KEY_VALUE : backwardFence.key;
|
||||||
unboundForwardFence = forwardFence == null;
|
unboundForwardFence = forwardFence == null;
|
||||||
unboundBackwardFence = backwardFence == null;
|
unboundBackwardFence = backwardFence == null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue