From 31b34f5de1dbccccfa2392ecf3787cead1a6774b Mon Sep 17 00:00:00 2001 From: Speiger Date: Tue, 17 May 2022 07:59:57 +0200 Subject: [PATCH] Fixed a couple bugs. -Fixed: TreeMap.subMap().entrySet().remove() wouldn't check primitives properly. -Fixed: SortedMap.sub/tail/headMap were looping into themselves. -Changed: LinkedList.addBulk variable definition was triggering a false positive. --- .../templates/lists/LinkedList.template | 56 +++++++++++++------ .../maps/impl/tree/AVLTreeMap.template | 2 +- .../maps/impl/tree/RBTreeMap.template | 2 +- .../maps/interfaces/SortedMap.template | 6 +- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template b/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template index 1f77b1d..7264d35 100644 --- a/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template +++ b/src/builder/resources/speiger/assets/collections/templates/lists/LinkedList.template @@ -152,10 +152,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE int length = c.size(); if(length == 0) return false; checkAddRange(index); - Entry KEY_GENERIC_TYPE next = null; - Entry KEY_GENERIC_TYPE prev = null; - if(index == size) prev = last; - else if(index == 0) next = first; + Entry KEY_GENERIC_TYPE next; + Entry KEY_GENERIC_TYPE prev; + if(index == size) { + prev = last; + next = null; + } + else if(index == 0) { + next = first; + prev = null; + } else { next = getNode(index); prev = next.prev; @@ -180,10 +186,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE int length = c.size(); if(length == 0) return false; checkAddRange(index); - Entry KEY_GENERIC_TYPE next = null; - Entry KEY_GENERIC_TYPE prev = null; - if(index == size) prev = last; - else if(index == 0) next = first; + Entry KEY_GENERIC_TYPE next; + Entry KEY_GENERIC_TYPE prev; + if(index == size) { + prev = last; + next = null; + } + else if(index == 0) { + next = first; + prev = null; + } else { next = getNode(index); prev = next.prev; @@ -210,10 +222,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE int length = c.size(); if(length == 0) return false; checkAddRange(index); - Entry KEY_GENERIC_TYPE next = null; - Entry KEY_GENERIC_TYPE prev = null; - if(index == size) prev = last; - else if(index == 0) next = first; + Entry KEY_GENERIC_TYPE next; + Entry KEY_GENERIC_TYPE prev; + if(index == size) { + prev = last; + next = null; + } + else if(index == 0) { + next = first; + prev = null; + } else { next = getNode(index); prev = next.prev; @@ -260,10 +278,16 @@ public class LINKED_LIST KEY_GENERIC_TYPE extends ABSTRACT_LIST KEY_GENERIC_TYPE public void addElements(int from, KEY_TYPE[] a, int offset, int length) { SanityChecks.checkArrayCapacity(a.length, offset, length); checkAddRange(from); - Entry KEY_GENERIC_TYPE next = null; - Entry KEY_GENERIC_TYPE prev = null; - if(from == size) prev = last; - else if(from == 0) next = first; + Entry KEY_GENERIC_TYPE next; + Entry KEY_GENERIC_TYPE prev; + if(from == size) { + prev = last; + next = null; + } + else if(from == 0) { + next = first; + prev = null; + } else { next = getNode(from); prev = next.prev; diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template index 4b27525..a610ae2 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/AVLTreeMap.template @@ -1778,7 +1778,7 @@ public class AVL_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_ KEY_TYPE key = entry.ENTRY_KEY(); if (!inRange(key)) return false; Node KEY_VALUE_GENERIC_TYPE node = map.findNode(key); - if (node != null && VALUE_EQUALS(node.getValue(), entry.getValue())) { + if (node != null && VALUE_EQUALS(node.ENTRY_VALUE(), entry.ENTRY_VALUE())) { map.removeNode(node); return true; } diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template index 2eb7d9a..479c7ce 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/impl/tree/RBTreeMap.template @@ -1835,7 +1835,7 @@ public class RB_TREE_MAP KEY_VALUE_GENERIC_TYPE extends ABSTRACT_MAP KEY_VALUE_G KEY_TYPE key = entry.ENTRY_KEY(); if (!inRange(key)) return false; Node KEY_VALUE_GENERIC_TYPE node = map.findNode(key); - if (node != null && VALUE_EQUALS(node.getValue(), entry.getValue())) { + if (node != null && VALUE_EQUALS(node.ENTRY_VALUE(), entry.ENTRY_VALUE())) { map.removeNode(node); return true; } diff --git a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template index 42296d6..edcf681 100644 --- a/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template +++ b/src/builder/resources/speiger/assets/collections/templates/maps/interfaces/SortedMap.template @@ -155,11 +155,11 @@ public interface SORTED_MAP KEY_VALUE_GENERIC_TYPE extends SortedMap