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 2025/08/20 10:52:51 UTC
(commons-collections) branch master updated (845c0e540 -> 5ae4fb9b9)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
from 845c0e540 [collections-722] deeply nested chainedIterator performance problems fixed (#628)
new 7ab92fa0c Sort members
new 5ae4fb9b9 Javadoc
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:
.../map/ConcurrentReferenceHashMap.java | 26 ++--
.../collections4/iterators/IteratorChainTest.java | 132 ++++++++++-----------
2 files changed, 79 insertions(+), 79 deletions(-)
(commons-collections) 02/02: Javadoc
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
commit 5ae4fb9b954f2ec15e304c6653edcef9104f4723
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 06:52:45 2025 -0400
Javadoc
---
.../map/ConcurrentReferenceHashMap.java | 26 +++++++++++-----------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java b/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java
index 61419309e..979c15c23 100644
--- a/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java
@@ -194,7 +194,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Sets the estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads.
*
* @param concurrencyLevel estimated number of concurrently updating threads
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> setConcurrencyLevel(final int concurrencyLevel) {
this.concurrencyLevel = concurrencyLevel;
@@ -205,7 +205,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Sets the initial capacity. The implementation performs internal sizing to accommodate this many elements.
*
* @param initialCapacity the initial capacity.
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> setInitialCapacity(final int initialCapacity) {
this.initialCapacity = initialCapacity;
@@ -216,7 +216,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Sets the reference type to use for keys.
*
* @param keyReferenceType the reference type to use for keys.
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> setKeyReferenceType(final ReferenceType keyReferenceType) {
this.keyReferenceType = keyReferenceType;
@@ -227,7 +227,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Sets the load factor factor, used to control resizing. Resizing may be performed when the average number of elements per bin exceeds this threshold.
*
* @param loadFactor the load factor factor, used to control resizing
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> setLoadFactor(final float loadFactor) {
this.loadFactor = loadFactor;
@@ -238,7 +238,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Sets the behavioral options.
*
* @param options the behavioral options.
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> setOptions(final EnumSet<Option> options) {
this.options = options;
@@ -249,7 +249,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Sets the values to load into a new map.
*
* @param sourceMap the values to load into a new map.
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> setSourceMap(final Map<? extends K, ? extends V> sourceMap) {
this.sourceMap = sourceMap;
@@ -260,7 +260,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Sets the reference type to use for values.
*
* @param valueReferenceType the reference type to use for values.
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> setValueReferenceType(final ReferenceType valueReferenceType) {
this.valueReferenceType = valueReferenceType;
@@ -270,7 +270,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Sets key reference type to {@link ReferenceType#SOFT}.
*
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> softKeys() {
setKeyReferenceType(ReferenceType.SOFT);
@@ -280,7 +280,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Sets value reference type to {@link ReferenceType#SOFT}.
*
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> softValues() {
setValueReferenceType(ReferenceType.SOFT);
@@ -290,7 +290,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Sets key reference type to {@link ReferenceType#STRONG}.
*
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> strongKeys() {
setKeyReferenceType(ReferenceType.STRONG);
@@ -300,7 +300,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Sets value reference type to {@link ReferenceType#STRONG}.
*
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> strongValues() {
setValueReferenceType(ReferenceType.STRONG);
@@ -310,7 +310,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Sets key reference type to {@link ReferenceType#WEAK}.
*
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> weakKeys() {
setKeyReferenceType(ReferenceType.WEAK);
@@ -320,7 +320,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Sets value reference type to {@link ReferenceType#WEAK}.
*
- * @return this instance.
+ * @return {@code this} instance.
*/
public Builder<K, V> weakValues() {
setValueReferenceType(ReferenceType.WEAK);
(commons-collections) 01/02: Sort members
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
commit 7ab92fa0c5ed356b4f395320724c096a063425b4
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 20 06:51:33 2025 -0400
Sort members
---
.../collections4/iterators/IteratorChainTest.java | 132 ++++++++++-----------
1 file changed, 66 insertions(+), 66 deletions(-)
diff --git a/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java b/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java
index 8d642e774..4ada92c66 100644
--- a/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java
+++ b/src/test/java/org/apache/commons/collections4/iterators/IteratorChainTest.java
@@ -150,6 +150,51 @@ public class IteratorChainTest extends AbstractIteratorTest<String> {
});
}
+ @Test
+ public void testChainOfChains() {
+ final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator());
+ final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator());
+ final Iterator<String> iteratorChainOfChains = new IteratorChain<>(iteratorChain1, iteratorChain2);
+
+ for (final String testValue : testArray1234) {
+ final String iterValue = (String) iteratorChainOfChains.next();
+ assertEquals(testValue, iterValue, "Iteration value is correct");
+ }
+
+ assertFalse(iteratorChainOfChains.hasNext(), "Iterator should now be empty");
+ assertThrows(NoSuchElementException.class, iteratorChainOfChains::next, "NoSuchElementException must be thrown");
+ }
+
+ @Test
+ public void testChainOfUnmodifiableChains() {
+ final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator());
+ final Iterator<String> unmodifiableChain1 = IteratorUtils.unmodifiableIterator(iteratorChain1);
+ final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator());
+ final Iterator<String> unmodifiableChain2 = IteratorUtils.unmodifiableIterator(iteratorChain2);
+ final Iterator<String> iteratorChainOfChains = new IteratorChain<>(unmodifiableChain1, unmodifiableChain2);
+
+ for (final String testValue : testArray1234) {
+ final String iterValue = (String) iteratorChainOfChains.next();
+ assertEquals(testValue, iterValue, "Iteration value is correct");
+ }
+
+ assertFalse(iteratorChainOfChains.hasNext(), "Iterator should now be empty");
+ assertThrows(NoSuchElementException.class, iteratorChainOfChains::next, "NoSuchElementException must be thrown");
+ }
+
+ @Test
+ public void testChainOfUnmodifiableChainsRetainsUnmodifiableBehaviourOfNestedIterator() {
+ final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator());
+ final Iterator<String> unmodifiableChain1 = IteratorUtils.unmodifiableIterator(iteratorChain1);
+ final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator());
+ final Iterator<String> unmodifiableChain2 = IteratorUtils.unmodifiableIterator(iteratorChain2);
+ final Iterator<String> iteratorChainOfChains = new IteratorChain<>(unmodifiableChain1, unmodifiableChain2);
+
+ iteratorChainOfChains.next();
+ assertThrows(UnsupportedOperationException.class, iteratorChainOfChains::remove,
+ "Calling remove must fail when nested iterator is unmodifiable");
+ }
+
@Test
void testConstructList() {
final List<Iterator<String>> list = new ArrayList<>();
@@ -226,6 +271,27 @@ public class IteratorChainTest extends AbstractIteratorTest<String> {
assertThrows(NoSuchElementException.class, iter::next);
}
+ @Test
+ public void testMultipleChainedIteratorPerformWellCollections722() {
+ final Map<Integer, List<Integer>> source = new HashMap<>();
+ for (int i = 0; i < 50; i++) {
+ source.put(i, Arrays.asList(1, 2, 3));
+ }
+
+ Iterator<Integer> iterator = IteratorUtils.emptyIterator();
+ final Set<Entry<Integer, List<Integer>>> entries = source.entrySet();
+ for (final Entry<Integer, List<Integer>> entry : entries) {
+ final Iterator<Integer> next = entry.getValue().iterator();
+ iterator = IteratorUtils.chainedIterator(iterator, next);
+ }
+ final Iterator<Integer> lastIterator = iterator;
+ assertTimeoutPreemptively(Duration.ofSeconds(2), () -> {
+ while (lastIterator.hasNext()) {
+ lastIterator.next().toString();
+ }
+ });
+ }
+
@Test
@Override
public void testRemove() {
@@ -278,70 +344,4 @@ public class IteratorChainTest extends AbstractIteratorTest<String> {
assertEquals(0, list1.size());
assertEquals(1, list2.size());
}
-
- @Test
- public void testChainOfChains() {
- final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator());
- final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator());
- final Iterator<String> iteratorChainOfChains = new IteratorChain<>(iteratorChain1, iteratorChain2);
-
- for (final String testValue : testArray1234) {
- final String iterValue = (String) iteratorChainOfChains.next();
- assertEquals(testValue, iterValue, "Iteration value is correct");
- }
-
- assertFalse(iteratorChainOfChains.hasNext(), "Iterator should now be empty");
- assertThrows(NoSuchElementException.class, iteratorChainOfChains::next, "NoSuchElementException must be thrown");
- }
-
- @Test
- public void testChainOfUnmodifiableChains() {
- final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator());
- final Iterator<String> unmodifiableChain1 = IteratorUtils.unmodifiableIterator(iteratorChain1);
- final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator());
- final Iterator<String> unmodifiableChain2 = IteratorUtils.unmodifiableIterator(iteratorChain2);
- final Iterator<String> iteratorChainOfChains = new IteratorChain<>(unmodifiableChain1, unmodifiableChain2);
-
- for (final String testValue : testArray1234) {
- final String iterValue = (String) iteratorChainOfChains.next();
- assertEquals(testValue, iterValue, "Iteration value is correct");
- }
-
- assertFalse(iteratorChainOfChains.hasNext(), "Iterator should now be empty");
- assertThrows(NoSuchElementException.class, iteratorChainOfChains::next, "NoSuchElementException must be thrown");
- }
-
- @Test
- public void testChainOfUnmodifiableChainsRetainsUnmodifiableBehaviourOfNestedIterator() {
- final Iterator<String> iteratorChain1 = new IteratorChain<>(list1.iterator(), list2.iterator());
- final Iterator<String> unmodifiableChain1 = IteratorUtils.unmodifiableIterator(iteratorChain1);
- final Iterator<String> iteratorChain2 = new IteratorChain<>(list3.iterator(), list4.iterator());
- final Iterator<String> unmodifiableChain2 = IteratorUtils.unmodifiableIterator(iteratorChain2);
- final Iterator<String> iteratorChainOfChains = new IteratorChain<>(unmodifiableChain1, unmodifiableChain2);
-
- iteratorChainOfChains.next();
- assertThrows(UnsupportedOperationException.class, iteratorChainOfChains::remove,
- "Calling remove must fail when nested iterator is unmodifiable");
- }
-
- @Test
- public void testMultipleChainedIteratorPerformWellCollections722() {
- final Map<Integer, List<Integer>> source = new HashMap<>();
- for (int i = 0; i < 50; i++) {
- source.put(i, Arrays.asList(1, 2, 3));
- }
-
- Iterator<Integer> iterator = IteratorUtils.emptyIterator();
- final Set<Entry<Integer, List<Integer>>> entries = source.entrySet();
- for (final Entry<Integer, List<Integer>> entry : entries) {
- final Iterator<Integer> next = entry.getValue().iterator();
- iterator = IteratorUtils.chainedIterator(iterator, next);
- }
- final Iterator<Integer> lastIterator = iterator;
- assertTimeoutPreemptively(Duration.ofSeconds(2), () -> {
- while (lastIterator.hasNext()) {
- lastIterator.next().toString();
- }
- });
- }
}