You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/07/17 14:43:00 UTC

(commons-collections) branch master updated (14375bdba -> 541936df6)

This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git


    from 14375bdba Fix Flat3Map entrySet remove ignoring the entry value (#714)
     new 670382189 Sort members.
     new 541936df6 Fix Flat3Map entrySet remove ignoring the entry value (#714).

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |   2 +-
 .../commons/collections4/map/Flat3MapTest.java     |  30 +--
 .../collections4/trie/PatriciaTrieTest.java        | 242 ++++++++++-----------
 3 files changed, 137 insertions(+), 137 deletions(-)


(commons-collections) 01/02: Sort members.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit 670382189c3f6a692deb3d658edffae245a91c59
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 17 07:42:49 2026 -0700

    Sort members.
---
 .../commons/collections4/map/Flat3MapTest.java     |  30 +--
 .../collections4/trie/PatriciaTrieTest.java        | 242 ++++++++++-----------
 2 files changed, 136 insertions(+), 136 deletions(-)

diff --git a/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java b/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java
index 31080f92d..ee29b6a3f 100644
--- a/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java
@@ -278,21 +278,6 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
         assertTrue(contains);
     }
 
-    @Test
-    void testEntrySetRemoveChecksValue() {
-        final Flat3Map<Integer, String> m = new Flat3Map<>();
-        m.put(ONE, TEN);
-        m.put(TWO, TWENTY);
-        // key present but value differs: entrySet().remove must not remove
-        assertFalse(m.entrySet().remove(new AbstractMap.SimpleEntry<>(ONE, TWENTY)));
-        assertEquals(2, m.size());
-        assertEquals(TEN, m.get(ONE));
-        // matching key and value: removes
-        assertTrue(m.entrySet().remove(new AbstractMap.SimpleEntry<>(ONE, TEN)));
-        assertFalse(m.containsKey(ONE));
-        assertEquals(1, m.size());
-    }
-
     @Test
     @SuppressWarnings("unchecked")
     void testEntryIteratorSetValue1() throws Exception {
@@ -364,6 +349,21 @@ public class Flat3MapTest<K, V> extends AbstractIterableMapTest<K, V> {
         putAndRemove(new Flat3Map<>());
     }
 
+    @Test
+    void testEntrySetRemoveChecksValue() {
+        final Flat3Map<Integer, String> m = new Flat3Map<>();
+        m.put(ONE, TEN);
+        m.put(TWO, TWENTY);
+        // key present but value differs: entrySet().remove must not remove
+        assertFalse(m.entrySet().remove(new AbstractMap.SimpleEntry<>(ONE, TWENTY)));
+        assertEquals(2, m.size());
+        assertEquals(TEN, m.get(ONE));
+        // matching key and value: removes
+        assertTrue(m.entrySet().remove(new AbstractMap.SimpleEntry<>(ONE, TEN)));
+        assertFalse(m.containsKey(ONE));
+        assertEquals(1, m.size());
+    }
+
     @Test
     @SuppressWarnings("unchecked")
     void testEquals1() {
diff --git a/src/test/java/org/apache/commons/collections4/trie/PatriciaTrieTest.java b/src/test/java/org/apache/commons/collections4/trie/PatriciaTrieTest.java
index 46f1bef91..9ac993ab7 100644
--- a/src/test/java/org/apache/commons/collections4/trie/PatriciaTrieTest.java
+++ b/src/test/java/org/apache/commons/collections4/trie/PatriciaTrieTest.java
@@ -136,6 +136,102 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
         }
     }
 
+    @Test
+    public void testControlCharactersRegression() {
+        final String[] keys = {
+            "",
+            "\u0000",
+            "\u0001",
+            "\u0002",
+            "\u001F",
+            "\u007F",
+            "x",
+            "x\u0000",
+            "x\u0001",
+            "x\u0002",
+            "x\u001F",
+            "x\u007F",
+            "x\u0000y",
+            "x\u0001y"
+        };
+
+        // 1. Insertion, Retrieval, containsKey, size compared with HashMap
+        final java.util.Map<String, String> hashMap = new java.util.HashMap<>();
+        final PatriciaTrie<String> trie = new PatriciaTrie<>();
+
+        for (int i = 0; i < keys.length; i++) {
+            final String key = keys[i];
+            final String value = "val_" + i;
+
+            assertFalse(trie.containsKey(key));
+            assertNull(trie.get(key));
+
+            trie.put(key, value);
+            hashMap.put(key, value);
+
+            assertEquals(hashMap.size(), trie.size());
+            assertTrue(trie.containsKey(key));
+            assertEquals(value, trie.get(key));
+        }
+
+        // Verify all elements present and distinct
+        for (int i = 0; i < keys.length; i++) {
+            final String key = keys[i];
+            assertTrue(trie.containsKey(key));
+            assertEquals("val_" + i, trie.get(key));
+        }
+
+        // 2. Iteration order (compared with TreeMap)
+        final java.util.TreeMap<String, String> treeMap = new java.util.TreeMap<>(hashMap);
+        final java.util.List<String> trieKeys = new java.util.ArrayList<>(trie.keySet());
+        final java.util.List<String> expectedKeys = new java.util.ArrayList<>(treeMap.keySet());
+        assertEquals(expectedKeys, trieKeys);
+
+        // 3. prefixMap
+        final String[] prefixes = {"", "x", "x\u0000", "x\u0001", "x\u0002", "x\u001F", "x\u007F", "y"};
+        for (final String prefix : prefixes) {
+            final java.util.SortedMap<String, String> prefixMap = trie.prefixMap(prefix);
+            final java.util.TreeMap<String, String> expectedPrefixMap = new java.util.TreeMap<>();
+            for (final java.util.Map.Entry<String, String> entry : treeMap.entrySet()) {
+                if (entry.getKey().startsWith(prefix)) {
+                    expectedPrefixMap.put(entry.getKey(), entry.getValue());
+                }
+            }
+            assertEquals(expectedPrefixMap.size(), prefixMap.size());
+            assertEquals(expectedPrefixMap, new java.util.TreeMap<>(prefixMap));
+        }
+
+        // 4. headMap, tailMap, subMap (compared with TreeMap)
+        for (final String k1 : keys) {
+            assertEquals(new java.util.TreeMap<>(treeMap.headMap(k1)), new java.util.TreeMap<>(trie.headMap(k1)));
+            assertEquals(new java.util.TreeMap<>(treeMap.tailMap(k1)), new java.util.TreeMap<>(trie.tailMap(k1)));
+            for (final String k2 : keys) {
+                if (k1.compareTo(k2) <= 0) {
+                    assertEquals(new java.util.TreeMap<>(treeMap.subMap(k1, k2)), new java.util.TreeMap<>(trie.subMap(k1, k2)));
+                } else {
+                    assertThrows(IllegalArgumentException.class, () -> trie.subMap(k1, k2));
+                }
+            }
+        }
+
+        // 5. Remove (compared with HashMap)
+        for (int i = 0; i < keys.length; i++) {
+            final String key = keys[i];
+            final String value = "val_" + i;
+
+            assertTrue(trie.containsKey(key));
+            assertEquals(value, trie.remove(key));
+            assertFalse(trie.containsKey(key));
+            assertNull(trie.get(key));
+
+            hashMap.remove(key);
+            assertEquals(hashMap.size(), trie.size());
+        }
+
+        assertTrue(trie.isEmpty());
+        assertEquals(0, trie.size());
+    }
+
     @Test
     void testHeadMap() {
         final PatriciaTrie<String> trie = new PatriciaTrie<>();
@@ -187,6 +283,30 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
         assertNull(headMap.get("ge"));
     }
 
+    @Test
+    void testNullTerminatedKey1() {
+        final PatriciaTrie<Integer> trie = new PatriciaTrie<>();
+        trie.put("x", 0);
+        trie.put("x\u0000", 1);
+        assertTrue(trie.containsKey("x"));
+        assertTrue(trie.containsKey("x\u0000"));
+        assertEquals(2, trie.size());
+        assertEquals(0, trie.get("x"));
+        assertEquals(1, trie.get("x\u0000"));
+    }
+
+    @Test
+    void testNullTerminatedKey2() {
+        final PatriciaTrie<Integer> trie = new PatriciaTrie<>();
+        trie.put("x\u0000", 1);
+        trie.put("x", 0);
+        assertTrue(trie.containsKey("x"));
+        assertTrue(trie.containsKey("x\u0000"));
+        assertEquals(2, trie.size());
+        assertEquals(0, trie.get("x"));
+        assertEquals(1, trie.get("x\u0000"));
+    }
+
     @Test
     void testPrefixMap() {
         final PatriciaTrie<String> trie = new PatriciaTrie<>();
@@ -521,6 +641,7 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
         assertFalse(iter.hasNext());
     }
 
+
     @Test
     void testPrefixMapSizes() {
         // COLLECTIONS-525
@@ -624,7 +745,6 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
         assertNull(subMap.get("ge"));
     }
 
-
     @Test
     void testTailMap() {
         final PatriciaTrie<String> trie = new PatriciaTrie<>();
@@ -667,126 +787,6 @@ public class PatriciaTrieTest<V> extends AbstractSortedMapTest<String, V> {
         assertEquals("ge", tailMap.get("ge"));
     }
 
-    @Test
-    void testNullTerminatedKey1() {
-        final PatriciaTrie<Integer> trie = new PatriciaTrie<>();
-        trie.put("x", 0);
-        trie.put("x\u0000", 1);
-        assertTrue(trie.containsKey("x"));
-        assertTrue(trie.containsKey("x\u0000"));
-        assertEquals(2, trie.size());
-        assertEquals(0, trie.get("x"));
-        assertEquals(1, trie.get("x\u0000"));
-    }
-
-    @Test
-    void testNullTerminatedKey2() {
-        final PatriciaTrie<Integer> trie = new PatriciaTrie<>();
-        trie.put("x\u0000", 1);
-        trie.put("x", 0);
-        assertTrue(trie.containsKey("x"));
-        assertTrue(trie.containsKey("x\u0000"));
-        assertEquals(2, trie.size());
-        assertEquals(0, trie.get("x"));
-        assertEquals(1, trie.get("x\u0000"));
-    }
-
-    @Test
-    public void testControlCharactersRegression() {
-        final String[] keys = {
-            "",
-            "\u0000",
-            "\u0001",
-            "\u0002",
-            "\u001F",
-            "\u007F",
-            "x",
-            "x\u0000",
-            "x\u0001",
-            "x\u0002",
-            "x\u001F",
-            "x\u007F",
-            "x\u0000y",
-            "x\u0001y"
-        };
-
-        // 1. Insertion, Retrieval, containsKey, size compared with HashMap
-        final java.util.Map<String, String> hashMap = new java.util.HashMap<>();
-        final PatriciaTrie<String> trie = new PatriciaTrie<>();
-
-        for (int i = 0; i < keys.length; i++) {
-            final String key = keys[i];
-            final String value = "val_" + i;
-
-            assertFalse(trie.containsKey(key));
-            assertNull(trie.get(key));
-
-            trie.put(key, value);
-            hashMap.put(key, value);
-
-            assertEquals(hashMap.size(), trie.size());
-            assertTrue(trie.containsKey(key));
-            assertEquals(value, trie.get(key));
-        }
-
-        // Verify all elements present and distinct
-        for (int i = 0; i < keys.length; i++) {
-            final String key = keys[i];
-            assertTrue(trie.containsKey(key));
-            assertEquals("val_" + i, trie.get(key));
-        }
-
-        // 2. Iteration order (compared with TreeMap)
-        final java.util.TreeMap<String, String> treeMap = new java.util.TreeMap<>(hashMap);
-        final java.util.List<String> trieKeys = new java.util.ArrayList<>(trie.keySet());
-        final java.util.List<String> expectedKeys = new java.util.ArrayList<>(treeMap.keySet());
-        assertEquals(expectedKeys, trieKeys);
-
-        // 3. prefixMap
-        final String[] prefixes = {"", "x", "x\u0000", "x\u0001", "x\u0002", "x\u001F", "x\u007F", "y"};
-        for (final String prefix : prefixes) {
-            final java.util.SortedMap<String, String> prefixMap = trie.prefixMap(prefix);
-            final java.util.TreeMap<String, String> expectedPrefixMap = new java.util.TreeMap<>();
-            for (final java.util.Map.Entry<String, String> entry : treeMap.entrySet()) {
-                if (entry.getKey().startsWith(prefix)) {
-                    expectedPrefixMap.put(entry.getKey(), entry.getValue());
-                }
-            }
-            assertEquals(expectedPrefixMap.size(), prefixMap.size());
-            assertEquals(expectedPrefixMap, new java.util.TreeMap<>(prefixMap));
-        }
-
-        // 4. headMap, tailMap, subMap (compared with TreeMap)
-        for (final String k1 : keys) {
-            assertEquals(new java.util.TreeMap<>(treeMap.headMap(k1)), new java.util.TreeMap<>(trie.headMap(k1)));
-            assertEquals(new java.util.TreeMap<>(treeMap.tailMap(k1)), new java.util.TreeMap<>(trie.tailMap(k1)));
-            for (final String k2 : keys) {
-                if (k1.compareTo(k2) <= 0) {
-                    assertEquals(new java.util.TreeMap<>(treeMap.subMap(k1, k2)), new java.util.TreeMap<>(trie.subMap(k1, k2)));
-                } else {
-                    assertThrows(IllegalArgumentException.class, () -> trie.subMap(k1, k2));
-                }
-            }
-        }
-
-        // 5. Remove (compared with HashMap)
-        for (int i = 0; i < keys.length; i++) {
-            final String key = keys[i];
-            final String value = "val_" + i;
-
-            assertTrue(trie.containsKey(key));
-            assertEquals(value, trie.remove(key));
-            assertFalse(trie.containsKey(key));
-            assertNull(trie.get(key));
-
-            hashMap.remove(key);
-            assertEquals(hashMap.size(), trie.size());
-        }
-
-        assertTrue(trie.isEmpty());
-        assertEquals(0, trie.size());
-    }
-
 //    void testCreate() throws Exception {
 //        resetEmpty();
 //        writeExternalFormToDisk(


(commons-collections) 02/02: Fix Flat3Map entrySet remove ignoring the entry value (#714).

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git

commit 541936df69ca55bd7981b1e73d95fb9fd6c2b7e0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 17 07:42:54 2026 -0700

    Fix Flat3Map entrySet remove ignoring the entry value (#714).
---
 src/changes/changes.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 840b76a1f..5b7045aaf 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -82,7 +82,7 @@
     <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary Gregory">Clamp size() int overflow in composite and multi-valued classes (#710).</action>
     <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary Gregory">Fix AbstractDualBidiMap.MapEntry.setValue returning new value (#711).</action>
     <action type="fix" dev="ggregory" due-to="sankalp suman, Gary Gregory" issue="COLLECTIONS-714">PatriciaTrie ignores trailing null characters in keys (#712).</action>
-    <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary Gregory">Flat3Map entrySet().remove(Object) removes a mapping when only the key matches, ignoring the entry value.</action>
+    <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary Gregory">Flat3Map entrySet().remove(Object) removes a mapping when only the key matches, ignoring the entry value (#714).</action>
     <action type="fix" dev="ggregory" due-to="Naveed Khan, Gary Gregory">SetUniqueList and ListOrderedSet leave the backing collection inconsistent when add(int, Object) or addAll(int, Collection) is called with an out-of-range index.</action>
     <!-- ADD -->
     <action type="add" dev="ggregory" due-to="Gary Gregory">Add generics to UnmodifiableIterator for the wrapped type.</action>