diff --git a/.asf.yaml b/.asf.yaml
index 4184f1a69a..52eef86cbf 100644
--- a/.asf.yaml
+++ b/.asf.yaml
@@ -23,7 +23,8 @@ notifications:
pullrequests: issues@commons.apache.org
jira_options: link label
jobs: notifications@commons.apache.org
- issues_bot_dependabot: notifications@commons.apache.org
- pullrequests_bot_dependabot: notifications@commons.apache.org
+ # commits_bot_dependabot: dependabot@commons.apache.org
+ issues_bot_dependabot: dependabot@commons.apache.org
+ pullrequests_bot_dependabot: dependabot@commons.apache.org
issues_bot_codecov-commenter: notifications@commons.apache.org
pullrequests_bot_codecov-commenter: notifications@commons.apache.org
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 00079caf1b..90ec55f742 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -18,10 +18,8 @@ updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
- interval: "weekly"
- day: "friday"
+ interval: "quarterly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
- interval: "weekly"
- day: "friday"
+ interval: "quarterly"
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index 7578b4da03..9ff35c83e7 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -23,8 +23,8 @@ Before you push a pull request, review this list:
- [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [ ] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI).
-- [ ] I used AI to create any part of, or all of, this pull request.
+- [ ] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute?
- [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself.
-- [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best-practice.
+- [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [ ] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 6ab048dec7..e072e3dd79 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -37,6 +37,7 @@ jobs:
security-events: write
strategy:
+ max-parallel: 20
fail-fast: false
matrix:
language: [ 'java' ]
@@ -45,10 +46,10 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
+ - uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 #v5.0.3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
@@ -57,7 +58,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
- uses: github/codeql-action/init@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.29.5
+ uses: github/codeql-action/init@c6f931105cb2c34c8f901cc885ba1e2e259cf745 # v4.34.0
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -68,7 +69,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
- uses: github/codeql-action/autobuild@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.29.5
+ uses: github/codeql-action/autobuild@c6f931105cb2c34c8f901cc885ba1e2e259cf745 # v4.34.0
# âšī¸ Command-line programs to run using the OS shell.
# đ https://git.io/JvXDl
@@ -82,4 +83,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.29.5
+ uses: github/codeql-action/analyze@c6f931105cb2c34c8f901cc885ba1e2e259cf745 # v4.34.0
diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml
index edfe875664..a04da50909 100644
--- a/.github/workflows/dependency-review.yml
+++ b/.github/workflows/dependency-review.yml
@@ -26,6 +26,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: 'Dependency Review PR'
- uses: actions/dependency-review-action@56339e523c0409420f6c2c9a2f4292bbb3c07dd3 # v4.8.0
+ uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # v4.8.2
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index f1bf6bd174..70680be10f 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -26,6 +26,7 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
+ max-parallel: 20
matrix:
java: [ 8, 11, 17, 21, 25 ]
experimental: [false]
@@ -34,17 +35,17 @@ jobs:
experimental: true
steps:
- - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
+ - uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 #v5.0.3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK ${{ matrix.java }}
- uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
+ uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml
index 6ae094550f..7182c34001 100644
--- a/.github/workflows/scorecards-analysis.yml
+++ b/.github/workflows/scorecards-analysis.yml
@@ -40,7 +40,7 @@ jobs:
steps:
- name: "Checkout code"
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
@@ -57,13 +57,13 @@ jobs:
publish_results: true
- name: "Upload artifact"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+ uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: SARIF file
path: results.sarif
retention-days: 5
- name: "Upload to code-scanning"
- uses: github/codeql-action/upload-sarif@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # 3.29.5
+ uses: github/codeql-action/upload-sarif@c6f931105cb2c34c8f901cc885ba1e2e259cf745 # v4.34.0
with:
sarif_file: results.sarif
diff --git a/.gitignore b/.gitignore
index 50cf2cd0f0..db02a5a6c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,3 +19,7 @@ site-content
# Mac files
.DS_Store
+
+# NetBeans files
+nb-configuration.xml
+nbactions.xml
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a52fd2e465..6167c6dd26 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -69,7 +69,7 @@ Making Changes
+ Respect the original code style:
+ Only use spaces for indentation; you can check for unnecessary whitespace with `git diff` before committing.
+ Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first.
-+ Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice.
++ Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best practice.
Unit tests are typically in the `src/test/java` directory.
+ Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself.
+ Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
diff --git a/NOTICE.txt b/NOTICE.txt
index 518b76e2c9..8c3e93e4e8 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
Apache Commons Collections
-Copyright 2001-2025 The Apache Software Foundation
+Copyright 2001-2026 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (https://www.apache.org/).
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index d615e65a9a..473141ccfe 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -266,7 +266,7 @@ Fixed Bugs
* COLLECTIONS-836: Correct test of BidiMap to optionally ignore testing the key set matches the values order.
Ordering is not specified for some BidiMaps such as DualHashBidiMaps. Thanks to Anant Dahiya.
* COLLECTIONS-737: Return 0 immediately if the given iterable is null in IterableUtils#size. Update tests. Thanks to Prodigysov.
-* COLLECTIONS-697: JavaDoc for FixedSizeList should warn that modifying underlying list is still allowed and is not prevented Thanks to Ranjan George.
+* COLLECTIONS-697: Javadoc for FixedSizeList should warn that modifying underlying list is still allowed and is not prevented Thanks to Ranjan George.
* Fill in some map test cases #104. Thanks to dota17.
* COLLECTIONS-738: Remove the redundant assertNull in IterableUtilsTest.find and update Javadocs. Thanks to Pengyu Nie.
* COLLECTIONS-724: Simplify two remove-if loops #77. Thanks to Eitan Adler.
diff --git a/pom.xml b/pom.xml
index d102a5ed2f..df28581c9a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
org.apache.commonscommons-parent
- 89
+ 974.0.0commons-collections4
@@ -28,10 +28,6 @@
2001The Apache Commons Collections package contains types that extend and augment the Java Collections Framework.https://commons.apache.org/proper/commons-collections/
-
- jira
- https://issues.apache.org/jira/browse/COLLECTIONS
- scm:git:https://gitbox.apache.org/repos/asf/commons-collections.gitscm:git:https://gitbox.apache.org/repos/asf/commons-collections.git
@@ -66,19 +62,19 @@
org.apache.commonscommons-lang3
- 3.19.0
+ 3.20.0testcommons-iocommons-io
- 2.20.0
+ 2.21.0testcommons-codeccommons-codec
- 1.19.0
+ 1.21.0true
@@ -87,6 +83,12 @@
33.5.0-jretest
+
+ org.openjdk.jmh
+ jmh-core
+ ${commons.jmh.version}
+ test
+
@@ -184,11 +186,11 @@
org.apache.ratapache-rat-plugin
-
- .asf.yaml
- site-content/**/*
- src/test/resources/org/apache/commons/collections4/data/test/*
-
+
+ .asf.yaml
+ site-content/**/*
+ src/test/resources/org/apache/commons/collections4/data/test/*
+
@@ -257,35 +259,6 @@
-
- org.apache.maven.plugins
- maven-changes-plugin
- ${commons.changes.version}
-
-
- %URL%/%ISSUE%
-
-
- false
- Fix Version,Key,Summary,Type,Resolution,Status
-
- Key DESC,Type,Fix Version DESC
- Fixed
- Resolved,Closed
-
- Bug,New Feature,Task,Improvement,Wish,Test
- ${commons.release.version}
- 500
-
-
-
-
- changes-report
- jira-report
-
-
-
- maven-checkstyle-plugin
@@ -305,11 +278,11 @@
org.apache.ratapache-rat-plugin
-
- .asf.yaml
- site-content/**/*
- src/test/resources/org/apache/commons/collections4/data/test/*
-
+
+ .asf.yaml
+ site-content/**/*
+ src/test/resources/org/apache/commons/collections4/data/test/*
+
@@ -398,6 +371,70 @@
+
+
+ benchmark
+
+ true
+ org.apache
+
+
+
+ org.openjdk.jmh
+ jmh-core
+ ${commons.jmh.version}
+ test
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ ${commons.jmh.version}
+ test
+
+
+
+
+
+
+ maven-compiler-plugin
+ ${commons.compiler.version}
+
+
+ **/*
+
+
+
+
+
+ org.codehaus.mojo
+ exec-maven-plugin
+
+
+ benchmark
+ test
+
+ exec
+
+
+ test
+ java
+
+ -classpath
+
+ org.openjdk.jmh.Main
+ -rf
+ json
+ -rff
+ target/jmh-result.json
+ ${benchmark}
+
+
+
+
+
+
+
+
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1c12696ad0..70967d8b4f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -35,16 +35,25 @@
Calling SetUtils.union on multiple instances of SetView causes JVM to hangImprove IteratorUtils.chainedIterator() performance.Fix UselessOverridingMethod in org.apache.commons.collections4.properties.PropertiesFactory.
+ OrderedProperties.stringPropertyNames() returns an unordered Set.
+ Fix SortedProperties.keySet() returned an unsorted Set.
+ Fix SortedProperties.propertyNames() returned an unsorted Enumeration.
+ Fix SortedProperties.stringPropertyNames() returned an unsorted Set.
+ Fix SortedProperties.forEach() called its consumer out of order.
+ Fix Apache RAT plugin console warnings.
+ Add MultiValuedMap.inverted() #665.Add generics to UnmodifiableIterator for the wrapped type.
+ Add a Maven benchmark profile for JMH.
+ Add a Maven benchmark profile for JMH.
- Bump org.apache.commons:commons-parent from 81 to 89 #612, #645.
+ Bump org.apache.commons:commons-parent from 81 to 97 #612, #645, #662, #663.Bump com.google.guava:guava-testlib from 33.3.1-jre to 33.5.0-jre #644.Bump PMD from 7.8.0 to 7.13.0 (now inherited from parent POM).Bump org.easymock:easymock from 5.5.0 to 5.6.0 #617.
- [test] Bump org.apache.commons:commons-lang3 from 3.17.0 to 3.19.0 #625.
- [test] Bump commons-io:commons-io from 2.19.0 to 2.20.0.
- Bump commons-codec:commons-codec from 1.18.0 to 1.19.0.
+ [test] Bump org.apache.commons:commons-lang3 from 3.17.0 to 3.20.0 #625.
+ [test] Bump commons-io:commons-io from 2.19.0 to 2.21.0.
+ Bump commons-codec:commons-codec from 1.18.0 to 1.21.0.
@@ -263,7 +272,7 @@
Return 0 immediately if the given iterable is null in IterableUtils#size. Update tests.
- JavaDoc for FixedSizeList should warn that modifying underlying list is still allowed and is not prevented
+ Javadoc for FixedSizeList should warn that modifying underlying list is still allowed and is not prevented
Fill in some map test cases #104.
diff --git a/src/main/java/org/apache/commons/collections4/ArrayUtils.java b/src/main/java/org/apache/commons/collections4/ArrayUtils.java
index a6e6cd7855..8fdbab1447 100644
--- a/src/main/java/org/apache/commons/collections4/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/collections4/ArrayUtils.java
@@ -46,7 +46,7 @@ final class ArrayUtils {
*
* @param array the array to search, may be {@code null}.
* @param objectToFind the object to find, may be {@code null}.
- * @return {@code true} if the array contains the object
+ * @return {@code true} if the array contains the object.
*/
static boolean contains(final Object[] array, final Object objectToFind) {
return indexOf(array, objectToFind) != CollectionUtils.INDEX_NOT_FOUND;
@@ -65,9 +65,9 @@ static boolean contains(final Object[] array, final Object objectToFind) {
*
* @param array the array to search for the object, may be {@code null}.
* @param objectToFind the object to find, may be {@code null}.
- * @param startIndex the index to start searching at
+ * @param startIndex the index to start searching.
* @return the index of the object within the array starting at the index, {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null}
- * array input
+ * array input.
*/
static int indexOf(final Object[] array, final Object objectToFind, int startIndex) {
if (array == null) {
@@ -102,7 +102,7 @@ static int indexOf(final Object[] array, final Object objectToFind, int startInd
*
* @param array the array to search for the object, may be {@code null}.
* @param objectToFind the object to find, may be {@code null}.
- * @return the index of the object within the array, {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
+ * @return the index of the object within the array, {@link CollectionUtils#INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input.
*/
static int indexOf(final T[] array, final Object objectToFind) {
return indexOf(array, objectToFind, 0);
diff --git a/src/main/java/org/apache/commons/collections4/ClosureUtils.java b/src/main/java/org/apache/commons/collections4/ClosureUtils.java
index d65472f177..4ad525c4dd 100644
--- a/src/main/java/org/apache/commons/collections4/ClosureUtils.java
+++ b/src/main/java/org/apache/commons/collections4/ClosureUtils.java
@@ -35,25 +35,25 @@
* {@code ClosureUtils} provides reference implementations and utilities
* for the Closure functor interface. The supplied closures are:
*
- *
Invoker - invokes a method on the input object
- *
For - repeatedly calls a closure for a fixed number of times
- *
While - repeatedly calls a closure while a predicate is true
- *
Chained - chains two or more closures together
- *
If - calls one closure or another based on a predicate
- *
Switch - calls one closure based on one or more predicates
- *
SwitchMap - calls one closure looked up from a Map
- *
Transformer - wraps a Transformer as a Closure
- *
NOP - does nothing
- *
Exception - always throws an exception
+ *
Invoker - invokes a method on the input object
+ *
For - repeatedly calls a closure for a fixed number of times
+ *
While - repeatedly calls a closure while a predicate is true
+ *
Chained - chains two or more closures together
+ *
If - calls one closure or another based on a predicate
+ *
Switch - calls one closure based on one or more predicates
+ *
SwitchMap - calls one closure looked up from a Map
+ *
Transformer - wraps a Transformer as a Closure
+ *
NOP - does nothing
+ *
Exception - always throws an exception
*
*
* Since v4.1 only closures which are considered to be safe are
* Serializable. Closures considered to be unsafe for serialization are:
*
*
- *
Invoker
- *
For
- *
While
+ *
Invoker
+ *
For
+ *
While
*
*
* @since 3.0
diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java
index 3c7adc6a1f..9cc1b80e60 100644
--- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java
+++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java
@@ -58,6 +58,7 @@ public class CollectionUtils {
/**
* Helper class to easily access cardinality properties of two collections.
+ *
* @param the element type
*/
private static class CardinalityHelper {
@@ -169,6 +170,7 @@ public int hashCode() {
/**
* Helper class for set-related operations, for example union, subtract, intersection.
+ *
* @param the element type
*/
private static final class SetOperationCardinalityHelper extends CardinalityHelper implements Iterable {
@@ -181,6 +183,7 @@ private static final class SetOperationCardinalityHelper extends CardinalityH
/**
* Create a new set operation helper from the two collections.
+ *
* @param a the first collection
* @param b the second collection
*/
@@ -200,6 +203,7 @@ public Iterator iterator() {
/**
* Returns the resulting collection.
+ *
* @return the result
*/
public Collection list() {
@@ -208,6 +212,7 @@ public Collection list() {
/**
* Add the object {@code count} times to the result collection.
+ *
* @param obj the object to add
* @param count the count
*/
@@ -363,7 +368,7 @@ public static boolean addIgnoreNull(final Collection collection, final T
* @param the type of object that the {@link Iterable} may contain.
* @return the number of occurrences of obj in coll
* @throws NullPointerException if collection is null
- * @deprecated since 4.1, use {@link IterableUtils#frequency(Iterable, Object)} instead.
+ * @deprecated Since 4.1, use {@link IterableUtils#frequency(Iterable, Object)} instead.
* Be aware that the order of parameters has changed.
*/
@Deprecated
@@ -373,6 +378,7 @@ public static int cardinality(final O obj, final Iterable super O> collect
/**
* Ensures an index is not negative.
+ *
* @param index the index to check.
* @throws IndexOutOfBoundsException if the index is negative.
*/
@@ -718,7 +724,7 @@ public static boolean containsAny(final Collection> coll1, @SuppressWarnin
* @param input the {@link Iterable} to get the input from, may be null
* @param predicate the predicate to use, may be null
* @return the number of matches for the predicate in the collection
- * @deprecated since 4.1, use {@link IterableUtils#countMatches(Iterable, Predicate)} instead
+ * @deprecated Since 4.1, use {@link IterableUtils#countMatches(Iterable, Predicate)} instead
*/
@Deprecated
public static int countMatches(final Iterable input, final Predicate super C> predicate) {
@@ -736,9 +742,9 @@ public static int countMatches(final Iterable input, final Predicate su
*
*
* @param a the first collection, must not be null
@@ -794,7 +800,7 @@ public static Collection emptyIfNull(final Collection collection) {
* @param input the {@link Iterable} to get the input from, may be null
* @param predicate the predicate to use, may be null
* @return true if at least one element of the collection matches the predicate
- * @deprecated since 4.1, use {@link IterableUtils#matchesAny(Iterable, Predicate)} instead
+ * @deprecated Since 4.1, use {@link IterableUtils#matchesAny(Iterable, Predicate)} instead
*/
@Deprecated
public static boolean exists(final Iterable input, final Predicate super C> predicate) {
@@ -875,7 +881,7 @@ public static boolean filterInverse(final Iterable collection, final Pred
* @param collection the collection to search, may be null
* @param predicate the predicate to use, may be null
* @return the first element of the collection which matches the predicate or null if none could be found
- * @deprecated since 4.1, use {@link IterableUtils#find(Iterable, Predicate)} instead
+ * @deprecated Since 4.1, use {@link IterableUtils#find(Iterable, Predicate)} instead
*/
@Deprecated
public static T find(final Iterable collection, final Predicate super T> predicate) {
@@ -894,7 +900,7 @@ public static T find(final Iterable collection, final Predicate super T
* @param closure the closure to perform, may be null
* @return the last element in the collection, or null if either collection or closure is null
* @since 4.0
- * @deprecated since 4.1, use {@link IterableUtils#forEachButLast(Iterable, Closure)} instead
+ * @deprecated Since 4.1, use {@link IterableUtils#forEachButLast(Iterable, Closure)} instead
*/
@Deprecated
public static > T forAllButLastDo(final Iterable collection,
@@ -914,7 +920,7 @@ public static super T>> T forAllButLastDo(final Iterable
* @param closure the closure to perform, may be null
* @return the last element in the collection, or null if either iterator or closure is null
* @since 4.0
- * @deprecated since 4.1, use {@link IteratorUtils#forEachButLast(Iterator, Closure)} instead
+ * @deprecated Since 4.1, use {@link IteratorUtils#forEachButLast(Iterator, Closure)} instead
*/
@Deprecated
public static super T>> T forAllButLastDo(final Iterator iterator, final C closure) {
@@ -932,7 +938,7 @@ public static super T>> T forAllButLastDo(final Iterator
* @param collection the collection to get the input from, may be null
* @param closure the closure to perform, may be null
* @return closure
- * @deprecated since 4.1, use {@link IterableUtils#forEach(Iterable, Closure)} instead
+ * @deprecated Since 4.1, use {@link IterableUtils#forEach(Iterable, Closure)} instead
*/
@Deprecated
public static super T>> C forAllDo(final Iterable collection, final C closure) {
@@ -954,7 +960,7 @@ public static super T>> C forAllDo(final Iterable col
* @param closure the closure to perform, may be null
* @return closure
* @since 4.0
- * @deprecated since 4.1, use {@link IteratorUtils#forEach(Iterator, Closure)} instead
+ * @deprecated Since 4.1, use {@link IteratorUtils#forEach(Iterator, Closure)} instead
*/
@Deprecated
public static super T>> C forAllDo(final Iterator iterator, final C closure) {
@@ -976,7 +982,7 @@ public static super T>> C forAllDo(final Iterator ite
* @param the type of object in the {@link Iterable}.
* @return the object at the specified index
* @throws IndexOutOfBoundsException if the index is invalid
- * @deprecated since 4.1, use {@code IterableUtils.get(Iterable, int)} instead
+ * @deprecated Since 4.1, use {@code IterableUtils.get(Iterable, int)} instead
*/
@Deprecated
public static T get(final Iterable iterable, final int index) {
@@ -999,7 +1005,7 @@ public static T get(final Iterable iterable, final int index) {
* @throws IndexOutOfBoundsException if the index is invalid
* @throws IllegalArgumentException if the object type is invalid
* @throws NullPointerException if iterator is null
- * @deprecated since 4.1, use {@code IteratorUtils.get(Iterator, int)} instead
+ * @deprecated Since 4.1, use {@code IteratorUtils.get(Iterator, int)} instead
*/
@Deprecated
public static T get(final Iterator iterator, final int index) {
@@ -1361,7 +1367,7 @@ public static boolean isSubCollection(final Collection> a, final Collection>
* @return true if every element of the collection matches the predicate or if the
* collection is empty, false otherwise
* @since 4.0
- * @deprecated since 4.1, use {@link IterableUtils#matchesAll(Iterable, Predicate)} instead
+ * @deprecated Since 4.1, use {@link IterableUtils#matchesAll(Iterable, Predicate)} instead
*/
@Deprecated
public static boolean matchesAll(final Iterable input, final Predicate super C> predicate) {
@@ -1838,11 +1844,11 @@ public static super O>> R selectRejected(final Iterab
* This method can handles objects as follows
*
*
- *
Collection - the collection size
- *
Map - the map size
- *
Array - the array size
- *
Iterator - the number of elements remaining in the iterator
- *
Enumeration - the number of elements remaining in the enumeration
+ *
Collection - the collection size
+ *
Map - the map size
+ *
Array - the array size
+ *
Iterator - the number of elements remaining in the iterator
+ *
Enumeration - the number of elements remaining in the enumeration
*
*
* @param object the object to get the size of, may be null
@@ -1887,11 +1893,11 @@ public static int size(final Object object) {
* This method can handles objects as follows
*
*
- *
Collection - via collection isEmpty
- *
Map - via map isEmpty
- *
Array - using array size
- *
Iterator - via hasNext
- *
Enumeration - via hasMoreElements
+ *
Collection - via collection isEmpty
+ *
Map - via map isEmpty
+ *
Array - using array size
+ *
Iterator - via hasNext
+ *
Enumeration - via hasMoreElements
*
*
* Note: This method is named to avoid clashing with
@@ -2020,7 +2026,7 @@ public static Collection subtract(final Iterable extends O> a,
* @param collection the collection to synchronize, must not be null
* @return a synchronized collection backed by the given collection
* @throws NullPointerException if the collection is null
- * @deprecated since 4.1, use {@link java.util.Collections#synchronizedCollection(Collection)} instead
+ * @deprecated Since 4.1, use {@link java.util.Collections#synchronizedCollection(Collection)} instead
*/
@Deprecated
public static Collection synchronizedCollection(final Collection collection) {
@@ -2127,7 +2133,7 @@ public static Collection union(final Iterable extends O> a, final Itera
* @param collection the collection to make unmodifiable, must not be null
* @return an unmodifiable collection backed by the given collection
* @throws NullPointerException if the collection is null
- * @deprecated since 4.1, use {@link java.util.Collections#unmodifiableCollection(Collection)} instead
+ * @deprecated Since 4.1, use {@link java.util.Collections#unmodifiableCollection(Collection)} instead
*/
@Deprecated
public static Collection unmodifiableCollection(final Collection extends C> collection) {
diff --git a/src/main/java/org/apache/commons/collections4/Equator.java b/src/main/java/org/apache/commons/collections4/Equator.java
index c43ab1d748..9d99322ffc 100644
--- a/src/main/java/org/apache/commons/collections4/Equator.java
+++ b/src/main/java/org/apache/commons/collections4/Equator.java
@@ -27,6 +27,7 @@
* @since 4.0
*/
public interface Equator {
+
/**
* Evaluates the two arguments for their equality.
*
diff --git a/src/main/java/org/apache/commons/collections4/FactoryUtils.java b/src/main/java/org/apache/commons/collections4/FactoryUtils.java
index 74628112ee..b80c7faf56 100644
--- a/src/main/java/org/apache/commons/collections4/FactoryUtils.java
+++ b/src/main/java/org/apache/commons/collections4/FactoryUtils.java
@@ -25,19 +25,19 @@
* {@code FactoryUtils} provides reference implementations and utilities
* for the Factory functor interface. The supplied factories are:
*
- *
Prototype - clones a specified object
- *
Instantiate - creates objects using reflection
- *
Constant - always returns the same object
- *
Null - always returns null
- *
Exception - always throws an exception
+ *
Prototype - clones a specified object
+ *
Instantiate - creates objects using reflection
+ *
Constant - always returns the same object
+ *
Null - always returns null
+ *
Exception - always throws an exception
*
*
* Since v4.1 only factories which are considered to be safe are
* Serializable. Factories considered to be unsafe for serialization are:
*
fluent methods which return a new {@code FluentIterable} instance,
- * providing a view of the original iterable (for example filter(Predicate));
+ * providing a view of the original iterable (for example filter(Predicate));
*
conversion methods which copy the FluentIterable's contents into a
- * new collection or array (for example toList());
+ * new collection or array (for example toList());
*
utility methods which answer questions about the FluentIterable's
- * contents (for example size(), anyMatch(Predicate)).
- *
+ * contents (for example size(), anyMatch(Predicate)).
*
*
* The following example outputs the first 3 even numbers in the range [1, 10]
@@ -139,6 +138,7 @@ public static FluentIterable of(final T... elements) {
/**
* Create a new FluentIterable by wrapping the provided iterable.
+ *
* @param iterable the iterable to wrap
*/
private FluentIterable(final Iterable iterable) {
@@ -218,8 +218,8 @@ public Enumeration asEnumeration() {
* Example: natural ordering
*
*
- *
this contains elements [1, 3, 5, 7]
- *
other contains elements [2, 4, 6, 8]
+ *
this contains elements [1, 3, 5, 7]
+ *
other contains elements [2, 4, 6, 8]
*
*
* The returned iterable will traverse the elements in the following
@@ -243,8 +243,8 @@ public FluentIterable collate(final Iterable extends E> other) {
* Example: descending order
*
*
- *
this contains elements [7, 5, 3, 1]
- *
other contains elements [8, 6, 4, 2]
+ *
this contains elements [7, 5, 3, 1]
+ *
other contains elements [8, 6, 4, 2]
*
*
* The returned iterable will traverse the elements in the following
diff --git a/src/main/java/org/apache/commons/collections4/IterableGet.java b/src/main/java/org/apache/commons/collections4/IterableGet.java
index 85aca7634b..0c3b893729 100644
--- a/src/main/java/org/apache/commons/collections4/IterableGet.java
+++ b/src/main/java/org/apache/commons/collections4/IterableGet.java
@@ -25,6 +25,7 @@
* @see Put
*/
public interface IterableGet extends Get {
+
/**
* Obtains a {@code MapIterator} over the map.
*
All decorator methods are not null-safe for the provided Iterable argument; for example, they will throw a {@link NullPointerException} if a
- * null Iterable is passed as argument.
+ * null Iterable is passed as argument.
*
All other utility methods are null-safe for the provided Iterable argument; for example, they will treat a null Iterable the same way as an empty one.
* For other arguments which are null, a {@link Predicate} will result in a {@link NullPointerException}. Exception: passing a null {@link Comparator} is
- * equivalent to a Comparator with natural ordering.
+ * equivalent to a Comparator with natural ordering.
*
*
* @since 4.1
@@ -624,7 +624,7 @@ public Iterator iterator() {
return new LazyIteratorChain() {
@Override
protected Iterator extends E> nextIterator(final int count) {
- if (IterableUtils.isEmpty(iterable)) {
+ if (IterableUtils.isEmpty(iterable)) { //NOPMD: qualifier is needed here
return null;
}
return iterable.iterator();
diff --git a/src/main/java/org/apache/commons/collections4/IteratorUtils.java b/src/main/java/org/apache/commons/collections4/IteratorUtils.java
index ac11f21abc..6a7e53d0de 100644
--- a/src/main/java/org/apache/commons/collections4/IteratorUtils.java
+++ b/src/main/java/org/apache/commons/collections4/IteratorUtils.java
@@ -112,6 +112,7 @@ public class IteratorUtils {
*/
@SuppressWarnings("rawtypes")
public static final OrderedMapIterator EMPTY_ORDERED_MAP_ITERATOR = EmptyOrderedMapIterator.INSTANCE;
+
/**
* Default delimiter used to delimit elements while converting an Iterator
* to its String representation.
@@ -392,7 +393,6 @@ public static Iterable asMultipleUseIterable(final Iterator extends E>
return new IteratorIterable<>(iterator, true);
}
- // Bounded
/**
* Decorates the specified iterator to return at most the given number
* of elements.
@@ -759,6 +759,7 @@ private static E find(final Iterator iterator, final Predicate super E>
* The Iterator is advanced to {@code 0} (or to the end, if
* {@code 0} exceeds the number of entries) as a side effect of this method.
*
+ *
* @param the type of object in the {@link Iterator}
* @param iterator the iterator to get a value from
* @return the first object
@@ -866,17 +867,17 @@ static E get(final Iterator iterator, final int index, final IntFunction<
* This method can handle objects as follows
*
*
- *
null - empty iterator
- *
Iterator - returned directly
- *
Enumeration - wrapped
- *
Collection - iterator from collection returned
- *
Map - values iterator returned
- *
Dictionary - values (elements) enumeration returned as iterator
- *
array - iterator over array returned
- *
object with iterator() public method accessed by reflection
- *
object - singleton iterator
- *
NodeList - iterator over the list
- *
Node - iterator over the child nodes
+ *
null - empty iterator
+ *
Iterator - returned directly
+ *
Enumeration - wrapped
+ *
Collection - iterator from collection returned
+ *
Map - values iterator returned
+ *
Dictionary - values (elements) enumeration returned as iterator
+ *
array - iterator over array returned
+ *
object with iterator() public method accessed by reflection
+ *
object - singleton iterator
+ *
NodeList - iterator over the list
+ *
Node - iterator over the child nodes
*
*
* @param obj the object to convert to an iterator
diff --git a/src/main/java/org/apache/commons/collections4/ListUtils.java b/src/main/java/org/apache/commons/collections4/ListUtils.java
index 1fb90acc69..7d658cb434 100644
--- a/src/main/java/org/apache/commons/collections4/ListUtils.java
+++ b/src/main/java/org/apache/commons/collections4/ListUtils.java
@@ -96,6 +96,7 @@ public void visitKeepCommand(final E object) {
/**
* Provides a partition view on a {@link List}.
+ *
* @since 4.0
*/
private static final class Partition extends AbstractList> {
diff --git a/src/main/java/org/apache/commons/collections4/MapUtils.java b/src/main/java/org/apache/commons/collections4/MapUtils.java
index 052375da27..800199dfe2 100644
--- a/src/main/java/org/apache/commons/collections4/MapUtils.java
+++ b/src/main/java/org/apache/commons/collections4/MapUtils.java
@@ -60,19 +60,19 @@
*
*
*
*
* @since 1.0
@@ -1417,7 +1417,7 @@ public static SortedMap lazySortedMap(final SortedMap map,
* @return a multi-value map backed by the given map which returns ArrayLists of values.
* @see MultiValueMap
* @since 3.2
- * @deprecated since 4.1, use {@link MultiValuedMap} instead
+ * @deprecated Since 4.1, use {@link MultiValuedMap} instead
*/
@Deprecated
public static MultiValueMap multiValueMap(final Map> map) {
@@ -1436,7 +1436,7 @@ public static MultiValueMap multiValueMap(final Map> MultiValueMap multiValueMap(final Map map,
@@ -1457,7 +1457,7 @@ public static > MultiValueMap multiValueMap(
* factory
* @see MultiValueMap
* @since 3.2
- * @deprecated since 4.1, use {@link MultiValuedMap} instead
+ * @deprecated Since 4.1, use {@link MultiValuedMap} instead
*/
@Deprecated
public static > MultiValueMap multiValueMap(final Map map,
diff --git a/src/main/java/org/apache/commons/collections4/MultiMap.java b/src/main/java/org/apache/commons/collections4/MultiMap.java
index 3b42d5764d..afb5f54e79 100644
--- a/src/main/java/org/apache/commons/collections4/MultiMap.java
+++ b/src/main/java/org/apache/commons/collections4/MultiMap.java
@@ -46,7 +46,7 @@
* @param the type of the keys in this map
* @param the type of the values in this map
* @since 2.0
- * @deprecated since 4.1, use {@link MultiValuedMap} instead
+ * @deprecated Since 4.1, use {@link MultiValuedMap} instead
*/
@Deprecated
public interface MultiMap extends IterableMap {
diff --git a/src/main/java/org/apache/commons/collections4/MultiMapUtils.java b/src/main/java/org/apache/commons/collections4/MultiMapUtils.java
index ef7fc8c96c..226f1dc522 100644
--- a/src/main/java/org/apache/commons/collections4/MultiMapUtils.java
+++ b/src/main/java/org/apache/commons/collections4/MultiMapUtils.java
@@ -20,6 +20,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.apache.commons.collections4.bag.HashBag;
@@ -157,6 +158,29 @@ public static Set getValuesAsSet(final MultiValuedMap map, final
return null;
}
+ /**
+ * Inverts the mappings from an input MultiValuedMap by adding entries to an output MultiValuedMap. The input is unchanged.
+ *
+ * Use this method to have complete control of the output MultiValuedMap or when merging several inverse mappings. In simple cases, consider using
+ * {@link MultiValuedMap#inverted()} method.
+ *
+ *
+ * @param the input value type and output key type.
+ * @param the input key type and output value type.
+ * @param the output MultiValuedMap type where {@code K} is the key type and {@code V} is the value type.
+ * @param input The input key-value mappings of type {@code }.
+ * @param output The output value-key mappings of type {@code }.
+ * @return The updated output MultiValuedMap of type {@code }
+ * @see MultiValuedMap#inverted()
+ * @since 4.6.0
+ */
+ public static > M invert(final MultiValuedMap extends V, ? extends K> input, final M output) {
+ for (final Map.Entry extends V, ? extends K> e : input.entries()) {
+ output.put(e.getValue(), e.getKey());
+ }
+ return output;
+ }
+
/**
* Null-safe check if the specified {@code MultiValuedMap} is empty.
*
diff --git a/src/main/java/org/apache/commons/collections4/MultiValuedMap.java b/src/main/java/org/apache/commons/collections4/MultiValuedMap.java
index 96d2f6b086..31ae1f005d 100644
--- a/src/main/java/org/apache/commons/collections4/MultiValuedMap.java
+++ b/src/main/java/org/apache/commons/collections4/MultiValuedMap.java
@@ -140,6 +140,18 @@ public interface MultiValuedMap {
*/
Collection get(K key);
+ /**
+ * Returns a new MultiValuedMap with inverted mappings.
+ * The new multimap will have a value-to-key mapping
+ * for each key-to-value mapping in the original.
+ *
+ * @return a new MultiValuedMap with inverted mappings
+ * @since 4.6.0
+ */
+ default MultiValuedMap inverted() {
+ throw new UnsupportedOperationException(getClass() + ".inverted()");
+ }
+
/**
* Returns {@code true} if this map contains no key-value mappings.
*
diff --git a/src/main/java/org/apache/commons/collections4/PredicateUtils.java b/src/main/java/org/apache/commons/collections4/PredicateUtils.java
index bce080858b..0229f05037 100644
--- a/src/main/java/org/apache/commons/collections4/PredicateUtils.java
+++ b/src/main/java/org/apache/commons/collections4/PredicateUtils.java
@@ -45,24 +45,24 @@
* {@code PredicateUtils} provides reference implementations and utilities
* for the Predicate functor interface. The supplied predicates are:
*
- *
Invoker - returns the result of a method call on the input object
- *
InstanceOf - true if the object is an instanceof a class
- *
Equal - true if the object equals() a specified object
- *
Identity - true if the object == a specified object
- *
Null - true if the object is null
- *
NotNull - true if the object is not null
- *
Unique - true if the object has not already been evaluated
- *
And/All - true if all of the predicates are true
- *
Or/Any - true if any of the predicates is true
- *
Either/One - true if only one of the predicate is true
- *
Neither/None - true if none of the predicates are true
- *
Not - true if the predicate is false, and vice versa
- *
Transformer - wraps a Transformer as a Predicate
- *
True - always return true
- *
False - always return false
- *
Exception - always throws an exception
- *
NullIsException/NullIsFalse/NullIsTrue - check for null input
- *
Transformed - transforms the input before calling the predicate
+ *
Invoker - returns the result of a method call on the input object
+ *
InstanceOf - true if the object is an instanceof a class
+ *
Equal - true if the object equals() a specified object
+ *
Identity - true if the object == a specified object
+ *
Null - true if the object is null
+ *
NotNull - true if the object is not null
+ *
Unique - true if the object has not already been evaluated
+ *
And/All - true if all of the predicates are true
+ *
Or/Any - true if any of the predicates is true
+ *
Either/One - true if only one of the predicate is true
+ *
Neither/None - true if none of the predicates are true
+ *
Not - true if the predicate is false, and vice versa
+ *
Transformer - wraps a Transformer as a Predicate
+ *
True - always return true
+ *
False - always return false
+ *
Exception - always throws an exception
+ *
NullIsException/NullIsFalse/NullIsTrue - check for null input
+ *
Transformed - transforms the input before calling the predicate
*
*
* All the supplied predicates are Serializable.
diff --git a/src/main/java/org/apache/commons/collections4/SetUtils.java b/src/main/java/org/apache/commons/collections4/SetUtils.java
index bc375cfe4a..9b77528dfa 100644
--- a/src/main/java/org/apache/commons/collections4/SetUtils.java
+++ b/src/main/java/org/apache/commons/collections4/SetUtils.java
@@ -81,6 +81,7 @@ public > void copyInto(final S set) {
/**
* Return an iterator for this view; the returned iterator is
* not required to be unmodifiable.
+ *
* @return a new iterator for this view
*/
protected abstract Iterator createIterator();
@@ -479,7 +480,6 @@ public static Set synchronizedSet(final Set set) {
return Collections.synchronizedSet(set);
}
- // SortedSet
/**
* Returns a synchronized sorted set backed by the given sorted set.
*
@@ -644,6 +644,7 @@ public static SortedSet unmodifiableNavigableSet(final NavigableSet se
/**
* Creates an unmodifiable set from the given items. If the passed var-args argument is {@code
* null}, then the method returns {@code null}.
+ *
* @param the element type
* @param items the elements that make up the new set
* @return a set
diff --git a/src/main/java/org/apache/commons/collections4/SortedBidiMap.java b/src/main/java/org/apache/commons/collections4/SortedBidiMap.java
index 5d175aaf08..72cd7e779c 100644
--- a/src/main/java/org/apache/commons/collections4/SortedBidiMap.java
+++ b/src/main/java/org/apache/commons/collections4/SortedBidiMap.java
@@ -56,6 +56,7 @@ public interface SortedBidiMap extends OrderedBidiMap, SortedMap super V> valueComparator();
diff --git a/src/main/java/org/apache/commons/collections4/TransformerUtils.java b/src/main/java/org/apache/commons/collections4/TransformerUtils.java
index 9fd16482ab..3b1bdceabe 100644
--- a/src/main/java/org/apache/commons/collections4/TransformerUtils.java
+++ b/src/main/java/org/apache/commons/collections4/TransformerUtils.java
@@ -40,31 +40,31 @@
* {@code TransformerUtils} provides reference implementations and
* utilities for the Transformer functor interface. The supplied transformers are:
*
- *
Invoker - returns the result of a method call on the input object
- *
Clone - returns a clone of the input object
- *
Constant - always returns the same object
- *
Closure - performs a Closure and returns the input object
- *
Predicate - returns the result of the predicate as a Boolean
- *
Factory - returns a new object from a factory
- *
Chained - chains two or more transformers together
- *
If - calls one transformer or another based on a predicate
- *
Switch - calls one transformer based on one or more predicates
- *
SwitchMap - calls one transformer looked up from a Map
- *
Instantiate - the Class input object is instantiated
- *
Map - returns an object from a supplied Map
- *
Null - always returns null
- *
NOP - returns the input object, which should be immutable
- *
Exception - always throws an exception
- *
StringValue - returns a {@link String} representation of the input object
+ *
Invoker - returns the result of a method call on the input object
+ *
Clone - returns a clone of the input object
+ *
Constant - always returns the same object
+ *
Closure - performs a Closure and returns the input object
+ *
Predicate - returns the result of the predicate as a Boolean
+ *
Factory - returns a new object from a factory
+ *
Chained - chains two or more transformers together
+ *
If - calls one transformer or another based on a predicate
+ *
Switch - calls one transformer based on one or more predicates
+ *
SwitchMap - calls one transformer looked up from a Map
+ *
Instantiate - the Class input object is instantiated
+ *
Map - returns an object from a supplied Map
+ *
Null - always returns null
+ *
NOP - returns the input object, which should be immutable
+ *
Exception - always throws an exception
+ *
StringValue - returns a {@link String} representation of the input object
*
*
* Since v4.1 only transformers which are considered to be safe are
* Serializable. Transformers considered to be unsafe for serialization are:
*
*
- *
Invoker
- *
Clone
- *
Instantiate
+ *
Invoker
+ *
Clone
+ *
Instantiate
*
*
* @since 3.0
diff --git a/src/main/java/org/apache/commons/collections4/bag/AbstractBagDecorator.java b/src/main/java/org/apache/commons/collections4/bag/AbstractBagDecorator.java
index ea94dd2012..a932fcff2c 100644
--- a/src/main/java/org/apache/commons/collections4/bag/AbstractBagDecorator.java
+++ b/src/main/java/org/apache/commons/collections4/bag/AbstractBagDecorator.java
@@ -38,6 +38,7 @@ public abstract class AbstractBagDecorator
/**
* Constructor only used in deserialization, do not use otherwise.
+ *
* @since 3.1
*/
protected AbstractBagDecorator() {
diff --git a/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java b/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java
index 4619afc92d..f64d19c933 100644
--- a/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java
+++ b/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java
@@ -121,6 +121,7 @@ protected static class MutableInteger {
/**
* Constructs a new instance.
+ *
* @param value the initial value
*/
MutableInteger(final int value) {
@@ -479,6 +480,7 @@ public boolean removeAll(final Collection> coll) {
/**
* Remove any members of the bag that are not in the given bag, respecting
* cardinality.
+ *
* @see #retainAll(Collection)
* @param other the bag to retain
* @return {@code true} if this call changed the collection
diff --git a/src/main/java/org/apache/commons/collections4/bag/AbstractSortedBagDecorator.java b/src/main/java/org/apache/commons/collections4/bag/AbstractSortedBagDecorator.java
index d73a5569b0..723fc65f9e 100644
--- a/src/main/java/org/apache/commons/collections4/bag/AbstractSortedBagDecorator.java
+++ b/src/main/java/org/apache/commons/collections4/bag/AbstractSortedBagDecorator.java
@@ -37,6 +37,7 @@ public abstract class AbstractSortedBagDecorator
/**
* Constructor only used in deserialization, do not use otherwise.
+ *
* @since 3.1
*/
protected AbstractSortedBagDecorator() {
diff --git a/src/main/java/org/apache/commons/collections4/bag/SynchronizedBag.java b/src/main/java/org/apache/commons/collections4/bag/SynchronizedBag.java
index 1313f1cc62..ea95fb28ff 100644
--- a/src/main/java/org/apache/commons/collections4/bag/SynchronizedBag.java
+++ b/src/main/java/org/apache/commons/collections4/bag/SynchronizedBag.java
@@ -41,11 +41,13 @@ public class SynchronizedBag extends SynchronizedCollection implements Bag
* Synchronized Set for the Bag class.
*/
final class SynchronizedBagSet extends SynchronizedCollection implements Set {
+
/** Serialization version */
private static final long serialVersionUID = 2990565892366827855L;
/**
* Constructs a new instance.
+ *
* @param set the set to decorate
* @param lock the lock to use, shared with the bag
*/
diff --git a/src/main/java/org/apache/commons/collections4/bag/package-info.java b/src/main/java/org/apache/commons/collections4/bag/package-info.java
index d28e0b1974..cb8284af79 100644
--- a/src/main/java/org/apache/commons/collections4/bag/package-info.java
+++ b/src/main/java/org/apache/commons/collections4/bag/package-info.java
@@ -23,18 +23,18 @@
* The following implementations are provided in the package:
*
*
- *
HashBag - implementation that uses a HashMap to store the data
- *
TreeBag - implementation that uses a TreeMap to store the data
+ *
HashBag - implementation that uses a HashMap to store the data
+ *
TreeBag - implementation that uses a TreeMap to store the data
*
*
* The following decorators are provided in the package:
*
*
- *
Synchronized - synchronizes method access for multithreaded environments
- *
Unmodifiable - ensures the bag cannot be altered
- *
Predicated - ensures that only elements that are valid according to a predicate can be added
- *
Transformed - transforms each element added to the bag
- *
Collection - ensures compliance with the java.util.Collection contract
+ *
Synchronized - synchronizes method access for multithreaded environments
+ *
Unmodifiable - ensures the bag cannot be altered
+ *
Predicated - ensures that only elements that are valid according to a predicate can be added
+ *
Transformed - transforms each element added to the bag
+ *
Collection - ensures compliance with the java.util.Collection contract
*
*/
package org.apache.commons.collections4.bag;
diff --git a/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java
index 67c20c236c..333179cc4a 100644
--- a/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java
+++ b/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java
@@ -67,6 +67,7 @@ protected static class BidiMapIterator implements MapIterator, Reset
/**
* Constructs a new instance.
+ *
* @param parent the parent map
*/
protected BidiMapIterator(final AbstractDualBidiMap parent) {
@@ -210,6 +211,7 @@ protected static class EntrySetIterator extends AbstractIteratorDecorator<
/**
* Constructs a new instance.
+ *
* @param iterator the iterator to decorate
* @param parent the parent map
*/
@@ -298,6 +300,7 @@ protected static class KeySetIterator extends AbstractIteratorDecorator {
/**
* Constructs a new instance.
+ *
* @param iterator the iterator to decorate
* @param parent the parent map
*/
@@ -339,6 +342,7 @@ protected static class MapEntry extends AbstractMapEntryDecorator {
/**
* Constructs a new instance.
+ *
* @param entry the entry to decorate
* @param parent the parent map
*/
@@ -419,6 +423,7 @@ protected static class ValuesIterator extends AbstractIteratorDecorator {
/**
* Constructs a new instance.
+ *
* @param iterator the iterator to decorate
* @param parent the parent map
*/
@@ -742,6 +747,7 @@ public boolean isEmpty() {
}
// Map views
+
/**
* Gets a keySet view of the map.
* Changes made on the view are reflected in the map.
@@ -758,6 +764,7 @@ public Set keySet() {
}
// BidiMap
+
/**
* Obtains a {@code MapIterator} over the map.
* The iterator implements {@link BidiMapIterator}.
diff --git a/src/main/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java
index f539081ca4..e1fcbe5c94 100644
--- a/src/main/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java
+++ b/src/main/java/org/apache/commons/collections4/bidimap/DualTreeBidiMap.java
@@ -78,6 +78,7 @@ protected static class BidiOrderedMapIterator implements OrderedMapIterato
/**
* Constructs a new instance.
+ *
* @param parent the parent map
*/
protected BidiOrderedMapIterator(final AbstractDualBidiMap parent) {
@@ -172,8 +173,10 @@ public String toString() {
* @param the type of the values.
*/
protected static class ViewMap extends AbstractSortedMapDecorator {
+
/**
* Constructs a new instance.
+ *
* @param bidi the parent bidi map
* @param sm the subMap sorted map
*/
diff --git a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java
index c7ed23ff94..f04dcf93a9 100644
--- a/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java
+++ b/src/main/java/org/apache/commons/collections4/bidimap/TreeBidiMap.java
@@ -95,6 +95,7 @@ abstract class AbstractView extends AbstractSet {
/**
* Constructs a new instance.
+ *
* @param orderType the KEY or VALUE int for the order
*/
AbstractView(final DataElement orderType) {
@@ -119,17 +120,22 @@ abstract class AbstractViewIterator {
/** Whether to return KEY or VALUE order. */
private final DataElement orderType;
+
/** The last node returned by the iterator. */
Node lastReturnedNode;
+
/** The next node to be returned by the iterator. */
private Node nextNode;
+
/** The previous node in the sequence returned by the iterator. */
private Node previousNode;
+
/** The modification count. */
private int expectedModifications;
/**
* Constructs a new instance.
+ *
* @param orderType the KEY or VALUE int for the order
*/
AbstractViewIterator(final DataElement orderType) {
@@ -214,6 +220,7 @@ public String toString() {
return description;
}
}
+
/**
* A view of this map.
*/
@@ -254,6 +261,7 @@ public boolean remove(final Object obj) {
return false;
}
}
+
/**
* The inverse map implementation.
*/
@@ -261,8 +269,10 @@ final class Inverse implements OrderedBidiMap {
/** Store the keySet once created. */
private Set inverseKeySet;
+
/** Store the valuesSet once created. */
private Set inverseValuesSet;
+
/** Store the entrySet once created. */
private Set> inverseEntrySet;
@@ -407,6 +417,7 @@ public Set values() {
return inverseValuesSet;
}
}
+
/**
* A view of this map.
*/
@@ -447,6 +458,7 @@ public boolean remove(final Object obj) {
return false;
}
}
+
/**
* An iterator over the inverse map entries.
*/
@@ -473,6 +485,7 @@ public Map.Entry previous() {
return createEntry(navigatePrevious());
}
}
+
/**
* An iterator over the map.
*/
diff --git a/src/main/java/org/apache/commons/collections4/bidimap/package-info.java b/src/main/java/org/apache/commons/collections4/bidimap/package-info.java
index 28983f2811..3b447054a7 100644
--- a/src/main/java/org/apache/commons/collections4/bidimap/package-info.java
+++ b/src/main/java/org/apache/commons/collections4/bidimap/package-info.java
@@ -27,16 +27,16 @@
* The following implementations are provided in the package:
*
*
- *
DualHashBidiMap - uses two HashMaps to implement BidiMap
- *
DualLinkedHashBidiMap - uses two LinkedHashMaps to implement BidiMap
- *
DualTreeBidiMap - uses two TreeMaps to implement SortedBidiMap
- *
TreeBidiMap - red-black tree implementation of OrderedBidiMap
+ *
DualHashBidiMap - uses two HashMaps to implement BidiMap
+ *
DualLinkedHashBidiMap - uses two LinkedHashMaps to implement BidiMap
+ *
DualTreeBidiMap - uses two TreeMaps to implement SortedBidiMap
+ *
TreeBidiMap - red-black tree implementation of OrderedBidiMap
*
*
* The following decorators are provided in the package:
*
*
- *
Unmodifiable - ensures the map cannot be altered
+ *
Unmodifiable - ensures the map cannot be altered
*
*/
package org.apache.commons.collections4.bidimap;
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapExtractor.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapExtractor.java
index 343d6b1338..fcb101e757 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapExtractor.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapExtractor.java
@@ -94,6 +94,7 @@ static BitMapExtractor fromIndexExtractor(final IndexExtractor extractor, final
* The default implementation of this method is slow. It is recommended
* that implementing classes reimplement this method.
*
+ *
* @return An array of bit map data.
*/
default long[] asBitMapArray() {
@@ -131,7 +132,7 @@ long[] toArray() {
* arrays reimplement this method.
*
*
- * @param other The other BitMapExtractor that provides the y values in the (x,y) pair.
+ * @param other The other BitMapExtractor that provides the y values in the (x, y) pair.
* @param func The function to apply.
* @return A LongPredicate that tests this BitMapExtractor's bitmap values in order.
*/
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java
index 7f89b26e91..b006e5317c 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java
@@ -232,6 +232,7 @@ default int estimateUnion(final BloomFilter> other) {
/**
* Gets the shape that was used when the filter was built.
+ *
* @return The shape the filter was built with.
*/
Shape getShape();
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractor.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractor.java
index 88a24166e1..a7e27fc0ef 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractor.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractor.java
@@ -120,7 +120,7 @@ default BloomFilter flatten() {
* instances, or references to the filters in the collection.
*
*
- * @param other The other BloomFilterExtractor that provides the y values in the (x,y) pair.
+ * @param other The other BloomFilterExtractor that provides the y values in the (x, y) pair.
* @param func The function to apply.
* @return {@code true} if the {@code func} returned {@code true} for every pair, {@code false} otherwise.
*/
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CellExtractor.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CellExtractor.java
index f6c8e574fc..2536d94b19 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/CellExtractor.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CellExtractor.java
@@ -51,6 +51,7 @@ public interface CellExtractor extends IndexExtractor {
*/
@FunctionalInterface
interface CellPredicate {
+
/**
* Performs an operation on the given {@code } pair.
*
@@ -70,7 +71,7 @@ interface CellPredicate {
*
The CellExtractor aggregates duplicate indices from the IndexExtractor.
*
*
- *
A CellExtractor that outputs the mapping [(1,2),(2,3),(3,1)] can be created from many combinations
+ *
A CellExtractor that outputs the mapping [(1, 2),(2, 3),(3, 1)] can be created from many combinations
* of indices including:
*
* [1, 1, 2, 2, 2, 3]
@@ -84,6 +85,7 @@ interface CellPredicate {
*/
static CellExtractor from(final IndexExtractor indexExtractor) {
return new CellExtractor() {
+
/**
* Class to track cell values in the TreeMap.
*/
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java
index cdad5286e6..0a1dbed676 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java
@@ -234,6 +234,7 @@ default boolean merge(final Hasher hasher) {
* to a CellExtractor and add that.
*
Implementations should throw {@code IllegalArgumentException} and no other exception on bad input.
*
+ *
* @param indexExtractor the IndexExtractor
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
@@ -348,6 +349,7 @@ default boolean remove(final IndexExtractor indexExtractor) {
/**
* The default implementation is a no-op since the counting bloom filter returns an unique IndexExtractor by default.
+ *
* @return this counting Bloom filter.
*/
@Override
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java
index a494ee9aa2..646093f298 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java
@@ -32,6 +32,7 @@ public final class IndexFilter {
/**
* An IndexTracker implementation that uses an array of integers to track whether or not a
* number has been seen. Suitable for Shapes that have few hash functions.
+ *
* @since 4.5.0
*/
static class ArrayTracker implements IntPredicate {
@@ -40,6 +41,7 @@ static class ArrayTracker implements IntPredicate {
/**
* Constructs the tracker based on the shape.
+ *
* @param shape the shape to build the tracker for.
*/
ArrayTracker(final Shape shape) {
@@ -70,6 +72,7 @@ static class BitMapTracker implements IntPredicate {
/**
* Constructs a bit map based tracker for the specified shape.
+ *
* @param shape The shape that is being generated.
*/
BitMapTracker(final Shape shape) {
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java b/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java
index 1cb64ded8f..7aa9b1c590 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java
@@ -138,7 +138,7 @@ public static > Consumer> noCleanup() {
}
/**
- * Removes the earliest filters in the list when the the number of filters
+ * Removes the earliest filters in the list when the number of filters
* exceeds maxSize.
*
* @param Type of BloomFilter.
@@ -292,7 +292,7 @@ public static > Builder builder() {
/**
* Constructs a new instance.
*
- * @param filterSupplier the non-null supplier of new Bloom filters to add the the list
+ * @param filterSupplier the non-null supplier of new Bloom filters to add the list
* when necessary.
* @param extendCheck The non-null predicate that checks if a new filter should be
* added to the list.
@@ -361,6 +361,7 @@ public LayerManager copy() {
/**
* Gets the Bloom filter from the first layer.
* No extension check is performed during this call.
+ *
* @return The Bloom filter from the first layer.
* @see #getTarget()
*/
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilter.java
index b47b9a462c..5d0531c50e 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilter.java
@@ -45,7 +45,7 @@
*
*
Level 0 is the oldest layer and the highest level is the newest.
*
There is always at least one enclosed filter.
- *
The newest filter is the {@code target} into which merges are performed.
+ *
The newest filter is the {@code target} into which merges are performed.
*
Whenever the target is retrieved, or a {@code merge} operation is performed the code checks if any older layers should be removed, and if so removes
* them. It also checks it a new layer should be added, and if so adds it and sets the {@code target} before the operation.
*
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/LongBiPredicate.java b/src/main/java/org/apache/commons/collections4/bloomfilter/LongBiPredicate.java
index ff2f3b49d7..9d36ed692c 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/LongBiPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/LongBiPredicate.java
@@ -20,7 +20,7 @@
* Represents a function that accepts a two long-valued argument and produces a binary result.
* This is the long-consuming primitive specialization for {@code BiPredicate}.
*
- * This is a functional interface whose functional method is {@code test(long,long)}.
+ * This is a functional interface whose functional method is {@code test(long, long)}.
*
*
* @since 4.5.0-M1
diff --git a/src/main/java/org/apache/commons/collections4/collection/AbstractCollectionDecorator.java b/src/main/java/org/apache/commons/collections4/collection/AbstractCollectionDecorator.java
index 34ce3d3d70..e764eb5566 100644
--- a/src/main/java/org/apache/commons/collections4/collection/AbstractCollectionDecorator.java
+++ b/src/main/java/org/apache/commons/collections4/collection/AbstractCollectionDecorator.java
@@ -67,6 +67,7 @@ public abstract class AbstractCollectionDecorator
/**
* Constructor only used in deserialization, do not use otherwise.
+ *
* @since 3.1
*/
protected AbstractCollectionDecorator() {
diff --git a/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java b/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java
index 1b21ab3332..d89db8d669 100644
--- a/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java
+++ b/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java
@@ -37,6 +37,7 @@
* Add and remove operations require the use of a pluggable strategy. If no
* strategy is provided then add and remove are unsupported.
*
+ *
* @param the type of the elements in the collection
* @since 3.0
*/
@@ -228,6 +229,7 @@ public void addComposited(final Collection compositeCollection1,
*
* This implementation calls {@code clear()} on each collection.
*
+ *
* @throws UnsupportedOperationException if clear is unsupported
*/
@Override
@@ -242,6 +244,7 @@ public void clear() {
*
* This implementation calls {@code contains()} on each collection.
*
+ *
* @param obj the object to search for
* @return true if obj is contained in any of the contained collections
*/
@@ -261,6 +264,7 @@ public boolean contains(final Object obj) {
* This implementation calls {@code contains()} for each element in the
* specified collection.
*
+ *
* @param coll the collection to check for
* @return true if all elements contained
*/
@@ -288,6 +292,7 @@ public List> getCollections() {
/**
* Gets the collection mutator to be used for this CompositeCollection.
+ *
* @return CollectionMutator<E>
*/
protected CollectionMutator getMutator() {
@@ -299,6 +304,7 @@ protected CollectionMutator getMutator() {
*
* This implementation calls {@code isEmpty()} on each collection.
*
+ *
* @return true if all of the contained collections are empty
*/
@Override
@@ -316,6 +322,7 @@ public boolean isEmpty() {
*
* This implementation uses an {@code IteratorChain}.
*
+ *
* @return an {@code IteratorChain} instance which supports
* {@code remove()}. Iteration occurs over contained collections in
* the order they were added, but this behavior should not be relied upon.
@@ -356,6 +363,7 @@ public boolean remove(final Object obj) {
*
* This implementation calls {@code removeAll} on each collection.
*
+ *
* @param coll the collection to remove
* @return true if the collection was modified
* @throws UnsupportedOperationException if removeAll is unsupported
@@ -386,6 +394,7 @@ public void removeComposited(final Collection coll) {
*
* This implementation calls {@code removeIf} on each collection.
*
+ *
* @param filter a predicate which returns true for elements to be removed
* @return true if the collection was modified
* @throws UnsupportedOperationException if removeIf is unsupported
@@ -409,6 +418,7 @@ public boolean removeIf(final Predicate super E> filter) {
*
* This implementation calls {@code retainAll()} on each collection.
*
+ *
* @param coll the collection to remove
* @return true if the collection was modified
* @throws UnsupportedOperationException if retainAll is unsupported
@@ -438,6 +448,7 @@ public void setMutator(final CollectionMutator mutator) {
*
* This implementation calls {@code size()} on each collection.
*
+ *
* @return total number of elements in all contained containers
*/
@Override
diff --git a/src/main/java/org/apache/commons/collections4/collection/SynchronizedCollection.java b/src/main/java/org/apache/commons/collections4/collection/SynchronizedCollection.java
index 820727fed5..dbe9d50d9f 100644
--- a/src/main/java/org/apache/commons/collections4/collection/SynchronizedCollection.java
+++ b/src/main/java/org/apache/commons/collections4/collection/SynchronizedCollection.java
@@ -58,6 +58,7 @@ public class SynchronizedCollection implements Collection, Serializable {
public static SynchronizedCollection synchronizedCollection(final Collection coll) {
return new SynchronizedCollection<>(coll);
}
+
/** The collection to decorate */
private final Collection collection;
diff --git a/src/main/java/org/apache/commons/collections4/collection/package-info.java b/src/main/java/org/apache/commons/collections4/collection/package-info.java
index 912a520b1b..6958e97e23 100644
--- a/src/main/java/org/apache/commons/collections4/collection/package-info.java
+++ b/src/main/java/org/apache/commons/collections4/collection/package-info.java
@@ -20,16 +20,19 @@
* {@link java.util.Collection Collection} interface.
*
* The following implementations are provided in the package:
+ *
*
- *
CompositeCollection - a collection that combines multiple collections into one
+ *
CompositeCollection - a collection that combines multiple collections into one
*
+ *
* The following decorators are provided in the package:
+ *
*
- *
Synchronized - synchronizes method access for multithreaded environments
- *
Unmodifiable - ensures the collection cannot be altered
- *
Predicated - ensures that only elements that are valid according to a predicate can be added
- *
Transformed - transforms elements as they are added
- *
Indexed - provides a map-like view onto another collection
+ *
Synchronized - synchronizes method access for multithreaded environments
+ *
Unmodifiable - ensures the collection cannot be altered
+ *
Predicated - ensures that only elements that are valid according to a predicate can be added
+ *
Transformed - transforms elements as they are added
+ *
Indexed - provides a map-like view onto another collection
*
*/
package org.apache.commons.collections4.collection;
diff --git a/src/main/java/org/apache/commons/collections4/comparators/BooleanComparator.java b/src/main/java/org/apache/commons/collections4/comparators/BooleanComparator.java
index aca9fe7bb6..429c1af745 100644
--- a/src/main/java/org/apache/commons/collections4/comparators/BooleanComparator.java
+++ b/src/main/java/org/apache/commons/collections4/comparators/BooleanComparator.java
@@ -176,7 +176,7 @@ public int hashCode() {
* I sort {@code true} values before
* {@code false} values. In other words,
* returns {@code true} iff
- * {@link #compare(Boolean,Boolean) compare(Boolean.FALSE,Boolean.TRUE)}
+ * {@link #compare(Boolean,Boolean) compare(Boolean.FALSE, Boolean.TRUE)}
* returns a positive value.
*
* @return the trueFirst flag
diff --git a/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java b/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java
index 05fa8acabd..253ddce5b3 100644
--- a/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java
+++ b/src/main/java/org/apache/commons/collections4/comparators/ComparatorChain.java
@@ -58,15 +58,17 @@ public class ComparatorChain implements Comparator, Serializable {
/** The list of comparators in the chain. */
private final List> comparatorChain;
+
/** Order - false (clear) = ascend; true (set) = descend. */
private final BitSet orderingBits;
- /** Whether the chain has been "locked". */
+
+ /** Whether the chain has been "locked". */
private boolean isLocked;
/**
* Constructs a ComparatorChain with no Comparators.
* You must add at least one Comparator before calling
- * the compare(Object,Object) method, or an
+ * the compare(Object, Object) method, or an
* UnsupportedOperationException is thrown
*/
public ComparatorChain() {
@@ -182,7 +184,7 @@ private void checkLocked() {
/**
* Perform comparisons on the Objects as per
- * Comparator.compare(o1,o2).
+ * Comparator.compare(o1, o2).
*
* @param o1 the first object to compare
* @param o2 the second object to compare
diff --git a/src/main/java/org/apache/commons/collections4/comparators/FixedOrderComparator.java b/src/main/java/org/apache/commons/collections4/comparators/FixedOrderComparator.java
index 42490a70f0..fa9b3a25a6 100644
--- a/src/main/java/org/apache/commons/collections4/comparators/FixedOrderComparator.java
+++ b/src/main/java/org/apache/commons/collections4/comparators/FixedOrderComparator.java
@@ -90,7 +90,6 @@ public enum UnknownObjectBehavior {
/** The behavior in the case of an unknown object */
private UnknownObjectBehavior unknownObjectBehavior = UnknownObjectBehavior.EXCEPTION;
- // Constructors
/**
* Constructs an empty FixedOrderComparator.
*/
@@ -127,7 +126,6 @@ public FixedOrderComparator(final T... items) {
}
}
- // Methods for adding items
/**
* Adds an item, which compares as after all items known to the Comparator.
* If the item is already known to the Comparator, its old position is
@@ -178,7 +176,6 @@ protected void checkLocked() {
}
}
- // Comparator methods
/**
* Compares two objects according to the order of this Comparator.
*
@@ -245,7 +242,6 @@ public int hashCode() {
return Objects.hash(counter, isLocked, map, unknownObjectBehavior);
}
- // Bean methods / state querying methods
/**
* Returns true if modifications cannot be made to the FixedOrderComparator.
* FixedOrderComparators cannot be modified once they have performed a comparison.
diff --git a/src/main/java/org/apache/commons/collections4/comparators/NullComparator.java b/src/main/java/org/apache/commons/collections4/comparators/NullComparator.java
index 882fc9fc50..b38c6203b1 100644
--- a/src/main/java/org/apache/commons/collections4/comparators/NullComparator.java
+++ b/src/main/java/org/apache/commons/collections4/comparators/NullComparator.java
@@ -35,99 +35,96 @@ public class NullComparator implements Comparator, Serializable {
private static final long serialVersionUID = -5820772575483504339L;
/**
- * The comparator to use when comparing two non-{@code null} objects.
- **/
+ * The comparator to use when comparing two non-{@code null} objects.
+ */
private final Comparator super E> nonNullComparator;
/**
- * Specifies whether a {@code null} are compared as higher than
- * non-{@code null} objects.
- **/
+ * Specifies whether a {@code null} are compared as higher than
+ * non-{@code null} objects.
+ */
private final boolean nullsAreHigh;
/**
- * Construct an instance that sorts {@code null} higher than any
- * non-{@code null} object it is compared with. When comparing two
- * non-{@code null} objects, the {@link ComparableComparator} is
- * used.
- **/
+ * Construct an instance that sorts {@code null} higher than any
+ * non-{@code null} object it is compared with. When comparing two
+ * non-{@code null} objects, the {@link ComparableComparator} is
+ * used.
+ */
public NullComparator() {
this(ComparatorUtils.NATURAL_COMPARATOR, true);
}
/**
- * Construct an instance that sorts {@code null} higher or lower than
- * any non-{@code null} object it is compared with. When comparing
- * two non-{@code null} objects, the {@link ComparableComparator} is
- * used.
+ * Construct an instance that sorts {@code null} higher or lower than
+ * any non-{@code null} object it is compared with. When comparing
+ * two non-{@code null} objects, the {@link ComparableComparator} is
+ * used.
*
- * @param nullsAreHigh a {@code true} value indicates that
- * {@code null} should be compared as higher than a
- * non-{@code null} object. A {@code false} value indicates
- * that {@code null} should be compared as lower than a
- * non-{@code null} object.
- **/
+ * @param nullsAreHigh a {@code true} value indicates that
+ * {@code null} should be compared as higher than a
+ * non-{@code null} object. A {@code false} value indicates
+ * that {@code null} should be compared as lower than a
+ * non-{@code null} object.
+ */
public NullComparator(final boolean nullsAreHigh) {
this(ComparatorUtils.NATURAL_COMPARATOR, nullsAreHigh);
}
/**
- * Construct an instance that sorts {@code null} higher than any
- * non-{@code null} object it is compared with. When comparing two
- * non-{@code null} objects, the specified {@link Comparator} is
- * used.
+ * Construct an instance that sorts {@code null} higher than any
+ * non-{@code null} object it is compared with. When comparing two
+ * non-{@code null} objects, the specified {@link Comparator} is
+ * used.
*
- * @param nonNullComparator the comparator to use when comparing two
- * non-{@code null} objects. This argument cannot be
- * {@code null}
- *
- * @throws NullPointerException if {@code nonNullComparator} is
- * {@code null}
- **/
+ * @param nonNullComparator the comparator to use when comparing two
+ * non-{@code null} objects. This argument cannot be
+ * {@code null}
+ * @throws NullPointerException if {@code nonNullComparator} is
+ * {@code null}
+ */
public NullComparator(final Comparator super E> nonNullComparator) {
this(nonNullComparator, true);
}
/**
- * Construct an instance that sorts {@code null} higher or lower than
- * any non-{@code null} object it is compared with. When comparing
- * two non-{@code null} objects, the specified {@link Comparator} is
- * used.
- *
- * @param nonNullComparator the comparator to use when comparing two
- * non-{@code null} objects. This argument cannot be
- * {@code null}
+ * Construct an instance that sorts {@code null} higher or lower than
+ * any non-{@code null} object it is compared with. When comparing
+ * two non-{@code null} objects, the specified {@link Comparator} is
+ * used.
*
- * @param nullsAreHigh a {@code true} value indicates that
- * {@code null} should be compared as higher than a
- * non-{@code null} object. A {@code false} value indicates
- * that {@code null} should be compared as lower than a
- * non-{@code null} object.
- *
- * @throws NullPointerException if {@code nonNullComparator} is
- * {@code null}
- **/
+ * @param nonNullComparator the comparator to use when comparing two
+ * non-{@code null} objects. This argument cannot be
+ * {@code null}
+ * @param nullsAreHigh a {@code true} value indicates that
+ * {@code null} should be compared as higher than a
+ * non-{@code null} object. A {@code false} value indicates
+ * that {@code null} should be compared as lower than a
+ * non-{@code null} object.
+ * @throws NullPointerException if {@code nonNullComparator} is
+ * {@code null}
+ */
public NullComparator(final Comparator super E> nonNullComparator, final boolean nullsAreHigh) {
this.nonNullComparator = Objects.requireNonNull(nonNullComparator, "nonNullComparator");
this.nullsAreHigh = nullsAreHigh;
}
/**
- * Perform a comparison between two objects. If both objects are
- * {@code null}, a {@code 0} value is returned. If one object
- * is {@code null} and the other is not, the result is determined on
- * whether the Comparator was constructed to have nulls as higher or lower
- * than other objects. If neither object is {@code null}, an
- * underlying comparator specified in the constructor (or the default) is
- * used to compare the non-{@code null} objects.
+ * Perform a comparison between two objects. If both objects are
+ * {@code null}, a {@code 0} value is returned. If one object
+ * is {@code null} and the other is not, the result is determined on
+ * whether the Comparator was constructed to have nulls as higher or lower
+ * than other objects. If neither object is {@code null}, an
+ * underlying comparator specified in the constructor (or the default) is
+ * used to compare the non-{@code null} objects.
*
- * @param o1 the first object to compare
- * @param o2 the object to compare it to.
- * @return {@code -1} if {@code o1} is "lower" than (less than,
- * before, etc.) {@code o2}; {@code 1} if {@code o1} is
- * "higher" than (greater than, after, etc.) {@code o2}; or
- * {@code 0} if {@code o1} and {@code o2} are equal.
- **/
+ * @param o1 the first object to compare
+ * @param o2 the object to compare it to.
+ * @return {@code -1} if {@code o1} is "lower" than (less than,
+ * before, etc.) {@code o2}; {@code 1} if {@code o1} is
+ * "higher" than (greater than, after, etc.) {@code o2}; or
+ * {@code 0} if {@code o1} and {@code o2} are equal.
+ */
@Override
public int compare(final E o1, final E o2) {
if (o1 == o2) {
@@ -143,16 +140,15 @@ public int compare(final E o1, final E o2) {
}
/**
- * Determines whether the specified object represents a comparator that is
- * equal to this comparator.
- *
- * @param obj the object to compare this comparator with.
+ * Determines whether the specified object represents a comparator that is
+ * equal to this comparator.
*
- * @return {@code true} if the specified object is a NullComparator
- * with equivalent {@code null} comparison behavior
- * (i.e. {@code null} high or low) and with equivalent underlying
- * non-{@code null} object comparators.
- **/
+ * @param obj the object to compare this comparator with.
+ * @return {@code true} if the specified object is a NullComparator
+ * with equivalent {@code null} comparison behavior
+ * (i.e. {@code null} high or low) and with equivalent underlying
+ * non-{@code null} object comparators.
+ */
@Override
public boolean equals(final Object obj) {
if (obj == null) {
@@ -172,11 +168,11 @@ public boolean equals(final Object obj) {
}
/**
- * Implement a hash code for this comparator that is consistent with
- * {@link #equals(Object)}.
+ * Implement a hash code for this comparator that is consistent with
+ * {@link #equals(Object)}.
*
- * @return a hash code for this comparator.
- **/
+ * @return a hash code for this comparator.
+ */
@Override
public int hashCode() {
return (nullsAreHigh ? -1 : 1) * nonNullComparator.hashCode();
diff --git a/src/main/java/org/apache/commons/collections4/functors/AbstractPredicate.java b/src/main/java/org/apache/commons/collections4/functors/AbstractPredicate.java
index 5b7e409173..d091bd6321 100644
--- a/src/main/java/org/apache/commons/collections4/functors/AbstractPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/AbstractPredicate.java
@@ -19,7 +19,7 @@
import org.apache.commons.collections4.Predicate;
/**
- * Abstract base class for predicates.
+ * Abstract class for predicates.
*
* @param the type of the input to the predicate.
* @since 4.5.0-M3
diff --git a/src/main/java/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java b/src/main/java/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java
index c8b902aa04..062799ddfb 100644
--- a/src/main/java/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/AbstractQuantifierPredicate.java
@@ -21,7 +21,7 @@
import org.apache.commons.collections4.Predicate;
/**
- * Abstract base class for quantification predicates, for example All, Any, None.
+ * Abstract class for quantification predicates, for example All, Any, None.
*
* @param the type of the input to the predicate.
* @since 4.0
diff --git a/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java b/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java
index 40d8896ef9..5c21374510 100644
--- a/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/AndPredicate.java
@@ -46,6 +46,7 @@ public static Predicate andPredicate(final Predicate super T> predicate
return new AndPredicate<>(Objects.requireNonNull(predicate1, "predicate1"),
Objects.requireNonNull(predicate2, "predicate2"));
}
+
/** The array of predicates to call */
private final Predicate super T> iPredicate1;
diff --git a/src/main/java/org/apache/commons/collections4/functors/ForClosure.java b/src/main/java/org/apache/commons/collections4/functors/ForClosure.java
index 67eb9d0aa8..8fc4f58011 100644
--- a/src/main/java/org/apache/commons/collections4/functors/ForClosure.java
+++ b/src/main/java/org/apache/commons/collections4/functors/ForClosure.java
@@ -53,6 +53,7 @@ public static Closure forClosure(final int count, final Closure super E
}
return new ForClosure<>(count, closure);
}
+
/** The number of times to loop */
private final int iCount;
diff --git a/src/main/java/org/apache/commons/collections4/functors/IfClosure.java b/src/main/java/org/apache/commons/collections4/functors/IfClosure.java
index 964f16d900..54072b79bc 100644
--- a/src/main/java/org/apache/commons/collections4/functors/IfClosure.java
+++ b/src/main/java/org/apache/commons/collections4/functors/IfClosure.java
@@ -50,6 +50,7 @@ public class IfClosure implements Closure, Serializable {
public static Closure ifClosure(final Predicate super E> predicate, final Closure super E> trueClosure) {
return IfClosure.ifClosure(predicate, trueClosure, NOPClosure.nopClosure());
}
+
/**
* Factory method that performs validation.
*
@@ -67,6 +68,7 @@ public static Closure ifClosure(final Predicate super E> predicate,
Objects.requireNonNull(trueClosure, "trueClosure"),
Objects.requireNonNull(falseClosure, "falseClosure"));
}
+
/** The test */
private final Predicate super T> iPredicate;
diff --git a/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java b/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java
index 97e0c21716..7743c5337a 100644
--- a/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java
+++ b/src/main/java/org/apache/commons/collections4/functors/IfTransformer.java
@@ -53,6 +53,7 @@ public static Transformer ifTransformer(final Predicate super I>
Objects.requireNonNull(trueTransformer, "trueTransformer"),
Objects.requireNonNull(falseTransformer, "falseTransformer"));
}
+
/**
* Factory method that performs validation.
*
@@ -71,6 +72,7 @@ public static Transformer ifTransformer(
return new IfTransformer<>(Objects.requireNonNull(predicate, "predicate"),
Objects.requireNonNull(trueTransformer, "trueTransformer"), NOPTransformer.nopTransformer());
}
+
/** The test */
private final Predicate super T> iPredicate;
diff --git a/src/main/java/org/apache/commons/collections4/functors/InstantiateFactory.java b/src/main/java/org/apache/commons/collections4/functors/InstantiateFactory.java
index cb263f6f15..e8f2d22756 100644
--- a/src/main/java/org/apache/commons/collections4/functors/InstantiateFactory.java
+++ b/src/main/java/org/apache/commons/collections4/functors/InstantiateFactory.java
@@ -63,10 +63,13 @@ public static Factory instantiateFactory(final Class classToInstantiat
}
return new InstantiateFactory<>(classToInstantiate, paramTypes, args);
}
+
/** The class to create */
private final Class iClassToInstantiate;
+
/** The constructor parameter types */
private final Class>[] iParamTypes;
+
/** The constructor arguments */
private final Object[] iArgs;
diff --git a/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java b/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java
index e1c3f09869..18361e5c19 100644
--- a/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java
+++ b/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java
@@ -49,6 +49,7 @@ public class InstantiateTransformer implements Transformer extends T>
public static Transformer extends T>, T> instantiateTransformer() {
return NO_ARG_INSTANCE;
}
+
/**
* Transformer method that performs validation.
*
diff --git a/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java b/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java
index f24cea644e..263a306d09 100644
--- a/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java
+++ b/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java
@@ -51,6 +51,7 @@ public class InvokerTransformer implements Transformer {
public static Transformer invokerTransformer(final String methodName) {
return new InvokerTransformer<>(Objects.requireNonNull(methodName, "methodName"));
}
+
/**
* Gets an instance of this transformer calling a specific method with specific values.
*
@@ -76,6 +77,7 @@ public static Transformer invokerTransformer(final String methodNam
}
return new InvokerTransformer<>(methodName, paramTypes, args);
}
+
/** The method name to call */
private final String iMethodName;
diff --git a/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java b/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java
index 4576cc85bb..92572a5831 100644
--- a/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/functors/OrPredicate.java
@@ -46,6 +46,7 @@ public static Predicate orPredicate(final Predicate super T> predicate1
return new OrPredicate<>(Objects.requireNonNull(predicate1, "predicate1"),
Objects.requireNonNull(predicate2, "predicate2"));
}
+
/** The array of predicates to call */
private final Predicate super T> iPredicate1;
diff --git a/src/main/java/org/apache/commons/collections4/functors/PrototypeFactory.java b/src/main/java/org/apache/commons/collections4/functors/PrototypeFactory.java
index 5333dbec44..5c1fada974 100644
--- a/src/main/java/org/apache/commons/collections4/functors/PrototypeFactory.java
+++ b/src/main/java/org/apache/commons/collections4/functors/PrototypeFactory.java
@@ -51,6 +51,7 @@ static class PrototypeCloneFactory implements Factory {
/** The object to clone each time */
private final T iPrototype;
+
/** The method used to clone */
private transient Method iCloneMethod;
diff --git a/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java b/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java
index a63c67c225..2d20c1ad15 100644
--- a/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java
+++ b/src/main/java/org/apache/commons/collections4/functors/SwitchClosure.java
@@ -72,6 +72,7 @@ public static Closure switchClosure(final Map, Closure> p
}
return new SwitchClosure<>(false, preds, closures, defaultClosure);
}
+
/**
* Factory method that performs validation and copies the parameter arrays.
*
@@ -98,6 +99,7 @@ public static Closure switchClosure(final Predicate super E>[] predicat
}
return new SwitchClosure<>(predicates, closures, defaultClosure);
}
+
/** The tests to consider */
private final Predicate super T>[] iPredicates;
diff --git a/src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java b/src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java
index a73a7fe4f0..213d1d5b95 100644
--- a/src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java
+++ b/src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java
@@ -81,6 +81,7 @@ public static Transformer switchTransformer(
}
return new SwitchTransformer<>(false, preds, transformers, defaultTransformer);
}
+
/**
* Factory method that performs validation and copies the parameter arrays.
*
@@ -109,6 +110,7 @@ public static Transformer switchTransformer(final Predicate super
}
return new SwitchTransformer<>(predicates, transformers, defaultTransformer);
}
+
/** The tests to consider */
private final Predicate super T>[] iPredicates;
diff --git a/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java b/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java
index 84b235f3b0..cd9f984f58 100644
--- a/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java
+++ b/src/main/java/org/apache/commons/collections4/functors/WhileClosure.java
@@ -51,8 +51,10 @@ public static Closure whileClosure(final Predicate super E> predicate,
return new WhileClosure<>(Objects.requireNonNull(predicate, "predicate"),
Objects.requireNonNull(closure, "closure"), doLoop);
}
+
/** The test condition */
private final Predicate super T> iPredicate;
+
/** The closure to call */
private final Closure super T> iClosure;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/ArrayIterator.java b/src/main/java/org/apache/commons/collections4/iterators/ArrayIterator.java
index f972cdf27a..b19a8ec53c 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/ArrayIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/ArrayIterator.java
@@ -41,10 +41,13 @@ public class ArrayIterator implements ResettableIterator {
/** The array to iterate over */
final Object array;
+
/** The start index to loop from */
final int startIndex;
+
/** The end index to loop to */
final int endIndex;
+
/** The current iterator index */
int index;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/BoundedIterator.java b/src/main/java/org/apache/commons/collections4/iterators/BoundedIterator.java
index 73d3b2f316..300910b442 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/BoundedIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/BoundedIterator.java
@@ -82,6 +82,7 @@ public BoundedIterator(final Iterator extends E> iterator, final long offset,
/**
* Checks whether the iterator is still within its bounded range.
+ *
* @return {@code true} if the iterator is within its bounds, {@code false} otherwise
*/
private boolean checkBounds() {
diff --git a/src/main/java/org/apache/commons/collections4/iterators/EmptyMapIterator.java b/src/main/java/org/apache/commons/collections4/iterators/EmptyMapIterator.java
index 52265fec20..1aac23f18b 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/EmptyMapIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/EmptyMapIterator.java
@@ -30,6 +30,7 @@ public class EmptyMapIterator extends AbstractEmptyMapIterator imple
/**
* Singleton instance of the iterator.
+ *
* @since 3.1
*/
@SuppressWarnings("rawtypes")
@@ -37,6 +38,7 @@ public class EmptyMapIterator extends AbstractEmptyMapIterator imple
/**
* Gets a typed instance of the iterator.
+ *
* @param the key type
* @param the value type
* @return {@link MapIterator}<K, V>
diff --git a/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java b/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java
index 0ee07de620..b3e0fb4de7 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/EmptyOrderedMapIterator.java
@@ -30,6 +30,7 @@ public class EmptyOrderedMapIterator extends AbstractEmptyMapIterator extends AbstractEmptyMapIterator the key type
* @param the value type
* @return {@link OrderedMapIterator}<K, V>
diff --git a/src/main/java/org/apache/commons/collections4/iterators/EnumerationIterator.java b/src/main/java/org/apache/commons/collections4/iterators/EnumerationIterator.java
index 95333b4078..9a83e7ebfc 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/EnumerationIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/EnumerationIterator.java
@@ -31,12 +31,13 @@ public class EnumerationIterator implements Iterator {
/** The collection to remove elements from */
private final Collection super E> collection;
+
/** The enumeration being converted */
private Enumeration extends E> enumeration;
+
/** The last object retrieved */
private E last;
- // Constructors
/**
* Constructs a new {@code EnumerationIterator} that will not
* function until {@link #setEnumeration(Enumeration)} is called.
@@ -77,7 +78,6 @@ public Enumeration extends E> getEnumeration() {
return enumeration;
}
- // Iterator interface
/**
* Returns true if the underlying enumeration has more elements.
*
diff --git a/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java
index 7a2e88b72b..67fb422c49 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/FilterListIterator.java
@@ -109,6 +109,7 @@ public FilterListIterator(final Predicate super E> predicate) {
/**
* Not supported.
+ *
* @param o the element to insert
*/
@Override
@@ -194,6 +195,7 @@ public void remove() {
/**
* Not supported.
+ *
* @param ignored the element with which to replace the last element returned by
* {@code next} or {@code previous}
*/
diff --git a/src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java b/src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java
index 433f60d46b..031fb650c0 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/IteratorChain.java
@@ -69,7 +69,7 @@ public class IteratorChain implements Iterator {
private Iterator extends E> lastUsedIterator;
/**
- * ComparatorChain is "locked" after the first time compare(Object,Object)
+ * ComparatorChain is "locked" after the first time compare(Object, Object)
* is called
*/
private boolean isLocked;
@@ -175,7 +175,7 @@ public void addIterator(final Iterator extends E> iterator) {
// in case it is an IteratorChain, wrap every underlying iterators as unmodifiable
// multiple rechainings would otherwise lead to exponential growing number of function calls
// when the iteratorChain gets used.
- for (Iterator extends E> nestedIterator : ((IteratorChain extends E>) underlyingIterator).iteratorQueue) {
+ for (final Iterator extends E> nestedIterator : ((IteratorChain extends E>) underlyingIterator).iteratorQueue) {
iteratorQueue.add(UnmodifiableIterator.unmodifiableIterator(nestedIterator));
}
} else {
diff --git a/src/main/java/org/apache/commons/collections4/iterators/ListIteratorWrapper.java b/src/main/java/org/apache/commons/collections4/iterators/ListIteratorWrapper.java
index 3d227940a8..dbba4b722f 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/ListIteratorWrapper.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/ListIteratorWrapper.java
@@ -60,13 +60,16 @@ public class ListIteratorWrapper implements ResettableListIterator {
/** The underlying iterator being decorated. */
private final Iterator extends E> iterator;
+
/** The list being used to cache the iterator. */
private final List list = new ArrayList<>();
/** The current index of this iterator. */
private int currentIndex;
+
/** The current index of the wrapped iterator. */
private int wrappedIteratorIndex;
+
/** Recall whether the wrapped iterator's "cursor" is in such a state as to allow remove() to be called */
private boolean removeState;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/LoopingIterator.java b/src/main/java/org/apache/commons/collections4/iterators/LoopingIterator.java
index 31fb99dc6c..0bcdea5ee6 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/LoopingIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/LoopingIterator.java
@@ -42,6 +42,7 @@ public class LoopingIterator implements ResettableIterator {
/** The collection to base the iterator on */
private final Collection extends E> collection;
+
/** The current iterator */
private Iterator extends E> iterator;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/LoopingListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/LoopingListIterator.java
index 0c47deecc9..1f76ddf046 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/LoopingListIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/LoopingListIterator.java
@@ -44,6 +44,7 @@ public class LoopingListIterator implements ResettableListIterator {
/** The list to base the iterator on */
private final List list;
+
/** The current list iterator */
private ListIterator iterator;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/NodeListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/NodeListIterator.java
index 82f4682d9d..916eeab927 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/NodeListIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/NodeListIterator.java
@@ -37,6 +37,7 @@ public class NodeListIterator implements Iterator {
/** The original NodeList instance */
private final NodeList nodeList;
+
/** The current iterator index */
private int index;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/ObjectArrayIterator.java b/src/main/java/org/apache/commons/collections4/iterators/ObjectArrayIterator.java
index c45909d942..2c0d82631f 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/ObjectArrayIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/ObjectArrayIterator.java
@@ -38,10 +38,13 @@ public class ObjectArrayIterator implements ResettableIterator {
/** The array */
final E[] array;
+
/** The start index to loop from */
final int startIndex;
+
/** The end index to loop to */
final int endIndex;
+
/** The current iterator index */
int index;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/ObjectGraphIterator.java b/src/main/java/org/apache/commons/collections4/iterators/ObjectGraphIterator.java
index 2cc1f1a195..daae6e426a 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/ObjectGraphIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/ObjectGraphIterator.java
@@ -84,17 +84,22 @@ public class ObjectGraphIterator implements Iterator {
/** The stack of iterators */
private final Deque extends E>> stack = new ArrayDeque<>(8);
+
/** The root object in the tree */
private E root;
+
/** The transformer to use */
private final Transformer super E, ? extends E> transformer;
/** Whether there is another element in the iteration */
private boolean hasNext;
+
/** The current iterator */
private Iterator extends E> currentIterator;
+
/** The current value */
private E currentValue;
+
/** The last used iterator, needed for remove() */
private Iterator extends E> lastUsedIterator;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/PermutationIterator.java b/src/main/java/org/apache/commons/collections4/iterators/PermutationIterator.java
index 542cdae0d0..6aace66579 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/PermutationIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/PermutationIterator.java
@@ -71,6 +71,7 @@ public class PermutationIterator implements Iterator> {
/**
* Standard constructor for this class.
+ *
* @param collection the collection to generate permutations for
* @throws NullPointerException if coll is null
*/
@@ -91,6 +92,7 @@ public PermutationIterator(final Collection extends E> collection) {
/**
* Indicates if there are more permutation available.
+ *
* @return true if there are more permutations, otherwise false
*/
@Override
@@ -100,6 +102,7 @@ public boolean hasNext() {
/**
* Returns the next permutation of the input collection.
+ *
* @return a list of the permutator's elements representing a permutation
* @throws NoSuchElementException if there are no more permutations
*/
diff --git a/src/main/java/org/apache/commons/collections4/iterators/ReverseListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/ReverseListIterator.java
index 287bdf5b7f..921c66f09a 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/ReverseListIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/ReverseListIterator.java
@@ -42,8 +42,10 @@ public class ReverseListIterator implements ResettableListIterator {
/** The list being wrapped. */
private final List list;
+
/** The list iterator being wrapped. */
private ListIterator iterator;
+
/** Flag to indicate if updating is possible at the moment. */
private boolean validForUpdate = true;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/SingletonIterator.java b/src/main/java/org/apache/commons/collections4/iterators/SingletonIterator.java
index 87dd8d19d2..49b4fb6872 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/SingletonIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/SingletonIterator.java
@@ -32,10 +32,13 @@ public class SingletonIterator
/** Whether remove is allowed */
private final boolean removeAllowed;
+
/** Is the cursor before the first element */
private boolean beforeFirst = true;
+
/** Has the element been removed */
private boolean removed;
+
/** The object */
private E object;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/SingletonListIterator.java b/src/main/java/org/apache/commons/collections4/iterators/SingletonListIterator.java
index 6496e41a79..53529a98b2 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/SingletonListIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/SingletonListIterator.java
@@ -140,6 +140,7 @@ public int previousIndex() {
/**
* Remove the object from this iterator.
+ *
* @throws IllegalStateException if the {@code next} or {@code previous}
* method has not yet been called, or the {@code remove} method
* has already been called after the last call to {@code next}
diff --git a/src/main/java/org/apache/commons/collections4/iterators/TransformIterator.java b/src/main/java/org/apache/commons/collections4/iterators/TransformIterator.java
index 36dc0b9f1c..f7b4113fd7 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/TransformIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/TransformIterator.java
@@ -31,6 +31,7 @@ public class TransformIterator implements Iterator {
/** The iterator being used */
private Iterator extends I> iterator;
+
/** The transformer being used */
private Transformer super I, ? extends O> transformer;
diff --git a/src/main/java/org/apache/commons/collections4/iterators/UniqueFilterIterator.java b/src/main/java/org/apache/commons/collections4/iterators/UniqueFilterIterator.java
index 88eadd41ca..7370b1bd57 100644
--- a/src/main/java/org/apache/commons/collections4/iterators/UniqueFilterIterator.java
+++ b/src/main/java/org/apache/commons/collections4/iterators/UniqueFilterIterator.java
@@ -31,9 +31,9 @@
public class UniqueFilterIterator extends FilterIterator {
/**
- * Constructs a new {@code UniqueFilterIterator}.
+ * Constructs a new {@code UniqueFilterIterator}.
*
- * @param iterator the iterator to use
+ * @param iterator the iterator to use
*/
public UniqueFilterIterator(final Iterator extends E> iterator) {
super(iterator, UniquePredicate.uniquePredicate());
diff --git a/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java b/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java
index 24bdd55675..4a602681a4 100644
--- a/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java
+++ b/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java
@@ -30,6 +30,7 @@ public abstract class AbstractKeyValue implements KeyValue {
/** The key */
private K key;
+
/** The value */
private V value;
diff --git a/src/main/java/org/apache/commons/collections4/keyvalue/MultiKey.java b/src/main/java/org/apache/commons/collections4/keyvalue/MultiKey.java
index 4515372d23..dcc621eb3b 100644
--- a/src/main/java/org/apache/commons/collections4/keyvalue/MultiKey.java
+++ b/src/main/java/org/apache/commons/collections4/keyvalue/MultiKey.java
@@ -233,6 +233,7 @@ public MultiKey(final K[] keys, final boolean makeClone) {
/**
* Calculate the hash code of the instance using the provided keys.
+ *
* @param keys the keys to calculate the hash code for
*/
private void calculateHashCode(final Object[] keys) {
@@ -316,6 +317,7 @@ public int hashCode() {
* Recalculate the hash code after deserialization. The hash code of some
* keys might have change (hash codes based on the system hash code are
* only stable for the same process).
+ *
* @return the instance with recalculated hash code
*/
protected Object readResolve() {
diff --git a/src/main/java/org/apache/commons/collections4/keyvalue/package-info.java b/src/main/java/org/apache/commons/collections4/keyvalue/package-info.java
index f6f305feb6..4a1b204464 100644
--- a/src/main/java/org/apache/commons/collections4/keyvalue/package-info.java
+++ b/src/main/java/org/apache/commons/collections4/keyvalue/package-info.java
@@ -20,10 +20,11 @@
* These are usually used in maps, however they can be used as data holders in any collection.
*
* The following key/value designs are included:
+ *
*
- *
Map Entry - various map entry implementations
- *
KeyValue - a key and value pair, without map entry semantics
- *
MultiKey - a holder of multiple keys tied together
+ *
Map Entry - various map entry implementations
+ *
KeyValue - a key and value pair, without map entry semantics
+ *
MultiKey - a holder of multiple keys tied together
*
*/
package org.apache.commons.collections4.keyvalue;
diff --git a/src/main/java/org/apache/commons/collections4/list/AbstractLinkedList.java b/src/main/java/org/apache/commons/collections4/list/AbstractLinkedList.java
index ab18d7b032..fe9e30ea2f 100644
--- a/src/main/java/org/apache/commons/collections4/list/AbstractLinkedList.java
+++ b/src/main/java/org/apache/commons/collections4/list/AbstractLinkedList.java
@@ -438,8 +438,10 @@ protected static class Node {
/** A pointer to the node before this node */
protected Node previous;
+
/** A pointer to the node after this node */
protected Node next;
+
/** The object contained within this node */
protected E value;
diff --git a/src/main/java/org/apache/commons/collections4/list/AbstractLinkedListJava21.java b/src/main/java/org/apache/commons/collections4/list/AbstractLinkedListJava21.java
index e2a7c52e2a..7a79d4dc3f 100644
--- a/src/main/java/org/apache/commons/collections4/list/AbstractLinkedListJava21.java
+++ b/src/main/java/org/apache/commons/collections4/list/AbstractLinkedListJava21.java
@@ -229,12 +229,16 @@ public void set(final E obj) {
* @param the type of elements in this list.
*/
protected static class LinkedSubList extends AbstractList {
+
/** The main list */
AbstractLinkedListJava21 parent;
+
/** Offset from the main list */
int offset;
+
/** Sublist size */
int size;
+
/** Sublist modCount */
int expectedModCount;
@@ -437,8 +441,10 @@ protected static class Node {
/** A pointer to the node before this node */
protected Node previous;
+
/** A pointer to the node after this node */
protected Node next;
+
/** The object contained within this node */
protected E value;
diff --git a/src/main/java/org/apache/commons/collections4/list/AbstractListDecorator.java b/src/main/java/org/apache/commons/collections4/list/AbstractListDecorator.java
index 25ecf62669..ee85167de5 100644
--- a/src/main/java/org/apache/commons/collections4/list/AbstractListDecorator.java
+++ b/src/main/java/org/apache/commons/collections4/list/AbstractListDecorator.java
@@ -38,6 +38,7 @@ public abstract class AbstractListDecorator extends AbstractCollectionDecorat
/**
* Constructor only used in deserialization, do not use otherwise.
+ *
* @since 3.1
*/
protected AbstractListDecorator() {
diff --git a/src/main/java/org/apache/commons/collections4/list/CursorableLinkedList.java b/src/main/java/org/apache/commons/collections4/list/CursorableLinkedList.java
index df080a21e5..c8e231b4c4 100644
--- a/src/main/java/org/apache/commons/collections4/list/CursorableLinkedList.java
+++ b/src/main/java/org/apache/commons/collections4/list/CursorableLinkedList.java
@@ -70,10 +70,13 @@ public class CursorableLinkedList extends AbstractLinkedList implements Se
* @param the type of elements in this cursor.
*/
public static class Cursor extends AbstractLinkedList.LinkedListIterator {
+
/** Is the cursor valid (not closed) */
boolean valid = true;
+
/** Is the next index valid */
boolean nextIndexValid = true;
+
/** Flag to indicate if the current element was removed by another object. */
boolean currentRemovedByAnother;
diff --git a/src/main/java/org/apache/commons/collections4/list/TreeList.java b/src/main/java/org/apache/commons/collections4/list/TreeList.java
index 5bedb5cd1b..57c15b24ef 100644
--- a/src/main/java/org/apache/commons/collections4/list/TreeList.java
+++ b/src/main/java/org/apache/commons/collections4/list/TreeList.java
@@ -33,7 +33,7 @@
* A {@code List} implementation that is optimized for fast insertions and
* removals at any index in the list.
*
- * This list implementation utilises a tree structure internally to ensure that
+ * This list implementation utilizes a tree structure internally to ensure that
* all insertions and removals are O(log n). This provides much faster performance
* than both an {@code ArrayList} and a {@code LinkedList} where elements
* are inserted and removed repeatedly from anywhere in the list.
@@ -76,23 +76,32 @@ public class TreeList extends AbstractList {
* The nodes don't know the index of the object they are holding. They
* do know however their position relative to their parent node.
* This allows to calculate the index of a node while traversing the tree.
+ *
*
* The Faedelung calculation stores a flag for both the left and right child
* to indicate if they are a child (false) or a link as in linked list (true).
+ *
*/
static class AVLNode {
+
/** The left child node or the predecessor if {@link #leftIsPrevious}.*/
private AVLNode left;
+
/** Flag indicating that left reference is not a subtree but the predecessor. */
private boolean leftIsPrevious;
+
/** The right child node or the successor if {@link #rightIsNext}. */
private AVLNode right;
+
/** Flag indicating that right reference is not a subtree but the successor. */
private boolean rightIsNext;
+
/** How many levels of left/right are below this one. */
private int height;
+
/** The relative position, root holds absolute position. */
private int relativePosition;
+
/** The stored element. */
private E value;
@@ -132,6 +141,7 @@ private AVLNode(final int relativePosition, final E obj,
* to this method will construct the subtree for elements {@code start}
* through {@code end} of the collection, assuming the iterator
* {@code e} already points at element {@code start}.
+ *
*
* @param iterator an iterator over the collection, which should already point
* to the element at index {@code start} within the collection
@@ -754,25 +764,31 @@ public String toString() {
* A list iterator over the linked list.
*/
static class TreeListIterator implements ListIterator, OrderedIterator {
+
/** The parent list */
private final TreeList parent;
+
/**
* Cache of the next node that will be returned by {@link #next()}.
*/
private AVLNode next;
+
/**
* The index of the next node to be returned.
*/
private int nextIndex;
+
/**
* Cache of the last node that was returned by {@link #next()}
* or {@link #previous()}.
*/
private AVLNode current;
+
/**
* The index of the last node that was returned.
*/
private int currentIndex;
+
/**
* The modification count that the list is expected to have. If the list
* doesn't have this count, then a
@@ -788,6 +804,7 @@ static class TreeListIterator implements ListIterator, OrderedIterator
* @param fromIndex the index to start at
*/
protected TreeListIterator(final TreeList parent, final int fromIndex) {
+ checkInterval(fromIndex, 0, parent.size(), parent.size());
this.parent = parent;
this.expectedModCount = parent.modCount;
this.next = parent.root == null ? null : parent.root.get(fromIndex);
@@ -900,6 +917,21 @@ public void set(final E obj) {
}
}
+ /**
+ * Checks whether the index is valid.
+ *
+ * @param index the index to check.
+ * @param startIndex the first allowed index.
+ * @param endIndex the last allowed index.
+ * @param endIndex the size.
+ * @throws IndexOutOfBoundsException if the index is invalid
+ */
+ private static void checkInterval(final int index, final int startIndex, final int endIndex, final int size) {
+ if (index < startIndex || index > endIndex) {
+ throw new IndexOutOfBoundsException("Invalid index:" + index + ", size=" + size);
+ }
+ }
+
/** The root node in the AVL tree */
private AVLNode root;
@@ -949,6 +981,7 @@ public void add(final int index, final E obj) {
*
* This method runs in O(n + log m) time, where m is
* the size of this list and n is the size of {@code c}.
+ *
*
* @param c the collection to be added to this list
* @return {@code true} if this list changed as a result of the call
@@ -977,9 +1010,7 @@ public boolean addAll(final Collection extends E> c) {
* @throws IndexOutOfBoundsException if the index is invalid
*/
private void checkInterval(final int index, final int startIndex, final int endIndex) {
- if (index < startIndex || index > endIndex) {
- throw new IndexOutOfBoundsException("Invalid index:" + index + ", size=" + size());
- }
+ checkInterval(index, startIndex, endIndex, size());
}
/**
@@ -1055,14 +1086,13 @@ public ListIterator listIterator() {
/**
* Gets a ListIterator over the list.
*
- * @param fromIndex the index to start from
- * @return the new iterator
+ * @param fromIndex the index to start from.
+ * @return the new iterator.
*/
@Override
public ListIterator listIterator(final int fromIndex) {
// override to go 75% faster
// cannot use EmptyIterator as iterator.add() must work
- checkInterval(fromIndex, 0, size());
return new TreeListIterator<>(this, fromIndex);
}
diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java b/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java
index 683072cc82..aee103d8b7 100644
--- a/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/AbstractHashedMap.java
@@ -235,6 +235,7 @@ public String toString() {
return new StringBuilder().append(getKey()).append('=').append(getValue()).toString();
}
}
+
/**
* Base Iterator.
*
diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractLinkedMap.java b/src/main/java/org/apache/commons/collections4/map/AbstractLinkedMap.java
index 4473831a57..4f17657fba 100644
--- a/src/main/java/org/apache/commons/collections4/map/AbstractLinkedMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/AbstractLinkedMap.java
@@ -140,8 +140,10 @@ public K previous() {
* @param the value type.
*/
protected static class LinkEntry extends HashEntry {
+
/** The entry before this one in the order */
protected LinkEntry before;
+
/** The entry after this one in the order */
protected LinkEntry after;
diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractMapDecorator.java b/src/main/java/org/apache/commons/collections4/map/AbstractMapDecorator.java
index 5047b1ac76..ffcae5ee29 100644
--- a/src/main/java/org/apache/commons/collections4/map/AbstractMapDecorator.java
+++ b/src/main/java/org/apache/commons/collections4/map/AbstractMapDecorator.java
@@ -47,6 +47,7 @@ public abstract class AbstractMapDecorator extends AbstractIterableMap extends AbstractMapDecor
/**
* Constructor only used in deserialization, do not use otherwise.
+ *
* @since 3.1
*/
protected AbstractOrderedMapDecorator() {
diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
index 3b08521555..42f84c2942 100644
--- a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
@@ -94,6 +94,7 @@ public abstract class AbstractReferenceMap extends AbstractHashedMap
* Base iterator class.
*/
static class ReferenceBaseIterator {
+
/** The parent map */
final AbstractReferenceMap parent;
@@ -197,6 +198,7 @@ public void remove() {
* @since 3.1
*/
protected static class ReferenceEntry extends HashEntry {
+
/** The parent map */
private final AbstractReferenceMap parent;
@@ -309,6 +311,7 @@ protected void onPurge() {
/**
* Purges the specified reference
+ *
* @param ref the reference to purge
* @return true or false
*/
@@ -517,6 +520,7 @@ public enum ReferenceStrength {
/**
* Resolve enum from int.
+ *
* @param value the int value
* @return ReferenceType
* @throws IllegalArgumentException if the specified value is invalid.
@@ -586,6 +590,7 @@ public V next() {
* A soft reference holder.
*/
static class SoftRef extends SoftReference {
+
/** The hashCode of the key (even if the reference points to a value) */
private final int hash;
@@ -619,6 +624,7 @@ public int hashCode() {
* A weak reference holder.
*/
static class WeakRef extends WeakReference {
+
/** The hashCode of the key (even if the reference points to a value) */
private final int hash;
diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractSortedMapDecorator.java b/src/main/java/org/apache/commons/collections4/map/AbstractSortedMapDecorator.java
index 78a49ef6a1..75a6d7dca3 100644
--- a/src/main/java/org/apache/commons/collections4/map/AbstractSortedMapDecorator.java
+++ b/src/main/java/org/apache/commons/collections4/map/AbstractSortedMapDecorator.java
@@ -59,6 +59,7 @@ protected static class SortedMapIterator extends EntrySetToMapIteratorAdap
/**
* Create a new AbstractSortedMapDecorator.SortedMapIterator.
+ *
* @param entrySet the entrySet to iterate
*/
protected SortedMapIterator(final Set> entrySet) {
@@ -94,6 +95,7 @@ public synchronized void reset() {
/**
* Constructor only used in deserialization, do not use otherwise.
+ *
* @since 3.1
*/
protected AbstractSortedMapDecorator() {
diff --git a/src/main/java/org/apache/commons/collections4/map/CompositeMap.java b/src/main/java/org/apache/commons/collections4/map/CompositeMap.java
index 9c26db3f33..8161d6cb1f 100644
--- a/src/main/java/org/apache/commons/collections4/map/CompositeMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/CompositeMap.java
@@ -56,6 +56,7 @@ public class CompositeMap extends AbstractIterableMap implements Ser
* @param the type of the values in the map
*/
public interface MapMutator extends Serializable {
+
/**
* Called when the CompositeMap.put() method is invoked.
*
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 979c15c230..c7cdea3950 100644
--- a/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java
@@ -400,9 +400,9 @@ public int size() {
/**
* ConcurrentReferenceHashMap list entry. Note that this is never exported out as a user-visible Map.Entry.
*
- * Because the value field is volatile, not final, it is legal wrt the Java Memory Model for an unsynchronized reader to see null instead of initial value
- * when read via a data race. Although a reordering leading to this is not likely to ever actually occur, the Segment.readValueUnderLock method is used as a
- * backup in case a null (pre-initialized) value is ever seen in an unsynchronized access method.
+ * Because the value field is volatile, not final, it is legal with respect to the Java Memory Model for an unsynchronized reader to see null instead of
+ * initial value when read via a data race. Although a reordering leading to this is not likely to ever actually occur, the Segment.readValueUnderLock
+ * method is used as a backup in case a null (pre-initialized) value is ever seen in an unsynchronized access method.
*
*/
private static final class HashEntry {
@@ -622,9 +622,10 @@ public int size() {
}
/**
- * Behavior-changing configuration options for the map
+ * Enumerates eehavior-changing configuration options for the map.
*/
public enum Option {
+
/**
* Indicates that referential-equality (== instead of .equals()) should be used when locating keys. This offers similar behavior to
* {@link IdentityHashMap}
@@ -633,17 +634,20 @@ public enum Option {
}
/**
- * An option specifying which Java reference type should be used to refer to a key and/or value.
+ * Enumerates which Java reference type should be used to refer to a key and/or value.
*/
public enum ReferenceType {
+
/**
* Indicates a normal Java strong reference should be used
*/
STRONG,
+
/**
* Indicates a {@link WeakReference} should be used
*/
WEAK,
+
/**
* Indicates a {@link SoftReference} should be used
*/
diff --git a/src/main/java/org/apache/commons/collections4/map/EntrySetToMapIteratorAdapter.java b/src/main/java/org/apache/commons/collections4/map/EntrySetToMapIteratorAdapter.java
index 3f9d57ee3d..636e14d9e6 100644
--- a/src/main/java/org/apache/commons/collections4/map/EntrySetToMapIteratorAdapter.java
+++ b/src/main/java/org/apache/commons/collections4/map/EntrySetToMapIteratorAdapter.java
@@ -43,6 +43,7 @@ public class EntrySetToMapIteratorAdapter implements MapIterator, Re
/**
* Create a new EntrySetToMapIteratorAdapter.
+ *
* @param entrySet the entrySet to adapt
*/
public EntrySetToMapIteratorAdapter(final Set> entrySet) {
@@ -52,6 +53,7 @@ public EntrySetToMapIteratorAdapter(final Set> entrySet) {
/**
* Gets the currently active entry.
+ *
* @return Map.Entry<K, V>
*/
protected synchronized Map.Entry current() {
diff --git a/src/main/java/org/apache/commons/collections4/map/Flat3Map.java b/src/main/java/org/apache/commons/collections4/map/Flat3Map.java
index f9d7dbaec8..1d68fe033a 100644
--- a/src/main/java/org/apache/commons/collections4/map/Flat3Map.java
+++ b/src/main/java/org/apache/commons/collections4/map/Flat3Map.java
@@ -44,11 +44,11 @@
* It also has good garbage collection characteristics.
*
*
- *
Optimized for operation at size 3 or less.
- *
Still works well once size 3 exceeded.
- *
Gets at size 3 or less are about 0-10% faster than HashMap,
- *
Puts at size 3 or less are over 4 times faster than HashMap.
- *
Performance 5% slower than HashMap once size 3 exceeded once.
+ *
Optimized for operation at size 3 or less.
+ *
Still works well once size 3 exceeded.
+ *
Gets at size 3 or less are about 0-10% faster than HashMap,
+ *
Puts at size 3 or less are over 4 times faster than HashMap.
+ *
Performance 5% slower than HashMap once size 3 exceeded once.
*
*
* The design uses two distinct modes of operation - flat and delegate.
@@ -161,6 +161,7 @@ public int size() {
return parent.size();
}
}
+
/**
* EntrySetIterator and MapEntry
*/
diff --git a/src/main/java/org/apache/commons/collections4/map/LRUMap.java b/src/main/java/org/apache/commons/collections4/map/LRUMap.java
index 73ae5c539f..feecbe44c8 100644
--- a/src/main/java/org/apache/commons/collections4/map/LRUMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/LRUMap.java
@@ -68,11 +68,13 @@ public class LRUMap
/** Serialization version */
private static final long serialVersionUID = -612114643488955218L;
+
/** Default maximum size */
protected static final int DEFAULT_MAX_SIZE = 100;
/** Maximum size */
private transient int maxSize;
+
/** Scan behavior */
private final boolean scanUntilRemovable;
diff --git a/src/main/java/org/apache/commons/collections4/map/MultiKeyMap.java b/src/main/java/org/apache/commons/collections4/map/MultiKeyMap.java
index 7bb9e50f89..0882943fdb 100644
--- a/src/main/java/org/apache/commons/collections4/map/MultiKeyMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/MultiKeyMap.java
@@ -50,9 +50,9 @@
* enables extra behavior to be added easily.
*
*
- *
{@code MultiKeyMap.decorate(new LinkedMap())} creates an ordered map.
- *
{@code MultiKeyMap.decorate(new LRUMap())} creates an least recently used map.
- *
{@code MultiKeyMap.decorate(new LinkedMap())} creates an ordered map.
+ *
{@code MultiKeyMap.decorate(new LRUMap())} creates an least recently used map.
+ *
{@code MultiKeyMap.decorate(new ReferenceMap())} creates a garbage collector sensitive map.
*
*
* Note that {@code IdentityMap} and {@code ReferenceIdentityMap} are unsuitable
diff --git a/src/main/java/org/apache/commons/collections4/map/MultiValueMap.java b/src/main/java/org/apache/commons/collections4/map/MultiValueMap.java
index 995977da53..7d3cd3c8d2 100644
--- a/src/main/java/org/apache/commons/collections4/map/MultiValueMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/MultiValueMap.java
@@ -66,7 +66,7 @@
* @param the type of the keys in this map
* @param the type of the values in this map
* @since 3.2
- * @deprecated since 4.1, use {@link org.apache.commons.collections4.MultiValuedMap MultiValuedMap} instead
+ * @deprecated Since 4.1, use {@link org.apache.commons.collections4.MultiValuedMap MultiValuedMap} instead
*/
@Deprecated
public class MultiValueMap extends AbstractMapDecorator implements MultiMap, Serializable {
@@ -135,6 +135,7 @@ public int size() {
return totalSize();
}
}
+
/**
* Inner class that provides the values iterator.
*/
@@ -471,9 +472,9 @@ public boolean putAll(final K key, final Collection values) {
* correctly handled.
*
* If you call this method with a normal map, each entry is
- * added using {@code put(Object,Object)}.
+ * added using {@code put(Object, Object)}.
* If you call this method with a multi map, each entry is
- * added using {@code putAll(Object,Collection)}.
+ * added using {@code putAll(Object, Collection)}.
*
*
* @param map the map to copy (either a normal or multi map)
diff --git a/src/main/java/org/apache/commons/collections4/map/SingletonMap.java b/src/main/java/org/apache/commons/collections4/map/SingletonMap.java
index dff5a199b5..a9f3fc8fbd 100644
--- a/src/main/java/org/apache/commons/collections4/map/SingletonMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/SingletonMap.java
@@ -52,9 +52,9 @@
* The key and value can be obtained by:
*
*
- *
normal Map methods and views
- *
the {@code MapIterator}, see {@link #mapIterator()}
- *
the {@code KeyValue} interface (just cast - no object creation)
+ *
normal Map methods and views
+ *
the {@code MapIterator}, see {@link #mapIterator()}
+ *
the {@code KeyValue} interface (just cast - no object creation)
*
*
* @param the type of the keys in this map
@@ -183,6 +183,7 @@ public int size() {
return 1;
}
}
+
/** Serialization version */
private static final long serialVersionUID = -8931271118676803261L;
@@ -336,7 +337,6 @@ public K firstKey() {
return getKey();
}
- // Map
/**
* Gets the value mapped to the key specified.
*
@@ -351,7 +351,6 @@ public V get(final Object key) {
return null;
}
- // KeyValue
/**
* Gets the key.
*
@@ -413,7 +412,6 @@ protected boolean isEqualValue(final Object value) {
return Objects.equals(value, getValue());
}
- // BoundedMap
/**
* Is the map currently full, always true.
*
diff --git a/src/main/java/org/apache/commons/collections4/map/TransformedMap.java b/src/main/java/org/apache/commons/collections4/map/TransformedMap.java
index d358f29539..6dcd47d879 100644
--- a/src/main/java/org/apache/commons/collections4/map/TransformedMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/TransformedMap.java
@@ -84,6 +84,7 @@ public static TransformedMap transformedMap(final Map map,
}
return decorated;
}
+
/**
* Factory method to create a transforming map.
*
diff --git a/src/main/java/org/apache/commons/collections4/map/package-info.java b/src/main/java/org/apache/commons/collections4/map/package-info.java
index 84364141c3..c70baf0915 100644
--- a/src/main/java/org/apache/commons/collections4/map/package-info.java
+++ b/src/main/java/org/apache/commons/collections4/map/package-info.java
@@ -25,29 +25,31 @@
* simple iteration of map keys and values.
*
* The following implementations are provided:
+ *
*
- *
CaseInsensitiveMap - map that compares keys in a case insensitive way
- *
CompositeMap - map that combines multiple maps into a single view
- *
HashedMap - general purpose HashMap replacement supporting MapIterator
- *
Flat3Map - designed for good performance at size 3 or less
- *
LinkedMap - a hash map that maintains insertion order, supporting OrderedMapIterator
- *
LRUMap - a hash map that maintains a maximum size by removing the least recently used entries
- *
MultiKeyMap - map that provides special methods for using more than one key to access the value
- *
ReferenceMap - allows the garbage collector to collect keys and values using equals() for comparison
- *
ReferenceIdentityMap - allows the garbage collector to collect keys and values using == for comparison
- *
SingletonMap - a fully featured map to hold one key-value pair
- *
StaticBucketMap - internally synchronized and designed for thread-contentious environments
+ *
CaseInsensitiveMap - map that compares keys in a case insensitive way
+ *
CompositeMap - map that combines multiple maps into a single view
+ *
HashedMap - general purpose HashMap replacement supporting MapIterator
+ *
Flat3Map - designed for good performance at size 3 or less
+ *
LinkedMap - a hash map that maintains insertion order, supporting OrderedMapIterator
+ *
LRUMap - a hash map that maintains a maximum size by removing the least recently used entries
+ *
MultiKeyMap - map that provides special methods for using more than one key to access the value
+ *
ReferenceMap - allows the garbage collector to collect keys and values using equals() for comparison
+ *
ReferenceIdentityMap - allows the garbage collector to collect keys and values using == for comparison
+ *
SingletonMap - a fully featured map to hold one key-value pair
+ *
StaticBucketMap - internally synchronized and designed for thread-contentious environments
*
*
* The following decorators are provided:
+ *
*
- *
Unmodifiable - ensures the collection cannot be altered
- *
Predicated - ensures that only elements that are valid according to a predicate can be added
- *
Transformed - transforms each element added
- *
FixedSize - ensures that the size of the map cannot change
- *
Defaulted - provides default values for non-existing keys
- *
Lazy - creates objects in the map on demand
- *
ListOrdered - ensures that insertion order is retained
+ *
Unmodifiable - ensures the collection cannot be altered
+ *
Predicated - ensures that only elements that are valid according to a predicate can be added
+ *
Transformed - transforms each element added
+ *
FixedSize - ensures that the size of the map cannot change
+ *
Defaulted - provides default values for non-existing keys
+ *
Lazy - creates objects in the map on demand
+ *
ListOrdered - ensures that insertion order is retained
*
*/
package org.apache.commons.collections4.map;
diff --git a/src/main/java/org/apache/commons/collections4/multimap/AbstractListValuedMap.java b/src/main/java/org/apache/commons/collections4/multimap/AbstractListValuedMap.java
index f14371f9bc..de34ee31bb 100644
--- a/src/main/java/org/apache/commons/collections4/multimap/AbstractListValuedMap.java
+++ b/src/main/java/org/apache/commons/collections4/multimap/AbstractListValuedMap.java
@@ -242,6 +242,7 @@ protected AbstractListValuedMap(final Map> map) {
/**
* Creates a new value collection using the provided factory.
+ *
* @return a new list
*/
@Override
diff --git a/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java b/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java
index 5f3b940cf4..ff98ea2b75 100644
--- a/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java
+++ b/src/main/java/org/apache/commons/collections4/multimap/AbstractSetValuedMap.java
@@ -87,6 +87,7 @@ protected AbstractSetValuedMap(final Map> map) {
/**
* Creates a new value collection using the provided factory.
+ *
* @return a new set
*/
@Override
diff --git a/src/main/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMap.java b/src/main/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMap.java
index a9d2a11537..47586dc631 100644
--- a/src/main/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMap.java
+++ b/src/main/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMap.java
@@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.collections4.MultiMapUtils;
import org.apache.commons.collections4.MultiValuedMap;
/**
@@ -118,6 +119,11 @@ protected ArrayList createCollection() {
return new ArrayList<>(initialListCapacity);
}
+ @Override
+ public ArrayListValuedHashMap inverted() {
+ return MultiMapUtils.invert(this, new ArrayListValuedHashMap());
+ }
+
/**
* Deserializes an instance from an ObjectInputStream.
*
diff --git a/src/main/java/org/apache/commons/collections4/multimap/ArrayListValuedLinkedHashMap.java b/src/main/java/org/apache/commons/collections4/multimap/ArrayListValuedLinkedHashMap.java
index f1b797b532..2556ab3f74 100644
--- a/src/main/java/org/apache/commons/collections4/multimap/ArrayListValuedLinkedHashMap.java
+++ b/src/main/java/org/apache/commons/collections4/multimap/ArrayListValuedLinkedHashMap.java
@@ -25,6 +25,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
+import org.apache.commons.collections4.MultiMapUtils;
import org.apache.commons.collections4.MultiValuedMap;
/**
@@ -118,6 +119,11 @@ protected ArrayList createCollection() {
return new ArrayList<>(initialListCapacity);
}
+ @Override
+ public ArrayListValuedLinkedHashMap inverted() {
+ return MultiMapUtils.invert(this, new ArrayListValuedLinkedHashMap<>());
+ }
+
/**
* Deserializes an instance from an ObjectInputStream.
*
diff --git a/src/main/java/org/apache/commons/collections4/multimap/HashSetValuedHashMap.java b/src/main/java/org/apache/commons/collections4/multimap/HashSetValuedHashMap.java
index b122e2c410..184730cbfb 100644
--- a/src/main/java/org/apache/commons/collections4/multimap/HashSetValuedHashMap.java
+++ b/src/main/java/org/apache/commons/collections4/multimap/HashSetValuedHashMap.java
@@ -24,6 +24,7 @@
import java.util.HashSet;
import java.util.Map;
+import org.apache.commons.collections4.MultiMapUtils;
import org.apache.commons.collections4.MultiValuedMap;
/**
@@ -117,6 +118,11 @@ protected HashSet createCollection() {
return new HashSet<>(initialSetCapacity);
}
+ @Override
+ public HashSetValuedHashMap inverted() {
+ return MultiMapUtils.invert(this, new HashSetValuedHashMap());
+ }
+
/**
* Deserializes an instance from an ObjectInputStream.
*
diff --git a/src/main/java/org/apache/commons/collections4/multimap/LinkedHashSetValuedLinkedHashMap.java b/src/main/java/org/apache/commons/collections4/multimap/LinkedHashSetValuedLinkedHashMap.java
index c8be8751dc..c381893b6a 100644
--- a/src/main/java/org/apache/commons/collections4/multimap/LinkedHashSetValuedLinkedHashMap.java
+++ b/src/main/java/org/apache/commons/collections4/multimap/LinkedHashSetValuedLinkedHashMap.java
@@ -24,6 +24,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
+import org.apache.commons.collections4.MultiMapUtils;
import org.apache.commons.collections4.MultiValuedMap;
/**
@@ -117,6 +118,11 @@ protected LinkedHashSet createCollection() {
return new LinkedHashSet<>(initialSetCapacity);
}
+ @Override
+ public LinkedHashSetValuedLinkedHashMap inverted() {
+ return MultiMapUtils.invert(this, new LinkedHashSetValuedLinkedHashMap());
+ }
+
/**
* Deserializes an instance from an ObjectInputStream.
*
diff --git a/src/main/java/org/apache/commons/collections4/multimap/package-info.java b/src/main/java/org/apache/commons/collections4/multimap/package-info.java
index 85cb3686c9..4936635078 100644
--- a/src/main/java/org/apache/commons/collections4/multimap/package-info.java
+++ b/src/main/java/org/apache/commons/collections4/multimap/package-info.java
@@ -20,15 +20,17 @@
* A MultiValuedMap holds a collection of values against each key.
*
* The following implementations are provided in the package:
+ *
*
- *
ArrayListValuedHashMap - ListValuedMap implementation using a HashMap/ArrayList
- *
HashSetValuedHashMap - SetValuedMap implementation using a HashMap/HashSet
+ *
ArrayListValuedHashMap - ListValuedMap implementation using a HashMap/ArrayList
+ *
HashSetValuedHashMap - SetValuedMap implementation using a HashMap/HashSet
*
*
* The following decorators are provided in the package:
+ *
*
- *
Transformed - transforms elements added to the MultiValuedMap
- *
Unmodifiable - ensures the collection cannot be altered
+ *
Transformed - transforms elements added to the MultiValuedMap
+ *
Unmodifiable - ensures the collection cannot be altered
*
*/
package org.apache.commons.collections4.multimap;
diff --git a/src/main/java/org/apache/commons/collections4/multiset/AbstractMapMultiSet.java b/src/main/java/org/apache/commons/collections4/multiset/AbstractMapMultiSet.java
index 19e7f620c3..0e24a6e167 100644
--- a/src/main/java/org/apache/commons/collections4/multiset/AbstractMapMultiSet.java
+++ b/src/main/java/org/apache/commons/collections4/multiset/AbstractMapMultiSet.java
@@ -64,6 +64,7 @@ protected static class EntrySetIterator implements Iterator> {
/**
* Constructs a new instance.
+ *
* @param decorated the iterator to decorate
* @param parent the parent multiset
*/
@@ -95,6 +96,7 @@ public void remove() {
canRemove = false;
}
}
+
/**
* Inner class iterator for the MultiSet.
*/
@@ -174,6 +176,7 @@ protected static class MultiSetEntry extends AbstractEntry {
/**
* Constructs a new instance.
+ *
* @param parentEntry the entry to decorate
*/
protected MultiSetEntry(final Map.Entry parentEntry) {
@@ -195,11 +198,13 @@ public E getElement() {
* Mutable integer class for storing the data.
*/
protected static class MutableInteger {
+
/** The value of this mutable. */
protected int value;
/**
* Constructs a new instance.
+ *
* @param value the initial value
*/
MutableInteger(final int value) {
@@ -238,6 +243,7 @@ protected static class UniqueSetIterator extends AbstractIteratorDecorator
/**
* Constructs a new instance.
+ *
* @param iterator the iterator to decorate
* @param parent the parent multiset
*/
diff --git a/src/main/java/org/apache/commons/collections4/multiset/SynchronizedMultiSet.java b/src/main/java/org/apache/commons/collections4/multiset/SynchronizedMultiSet.java
index 426ad6438e..ccffd0946d 100644
--- a/src/main/java/org/apache/commons/collections4/multiset/SynchronizedMultiSet.java
+++ b/src/main/java/org/apache/commons/collections4/multiset/SynchronizedMultiSet.java
@@ -40,11 +40,13 @@ public class SynchronizedMultiSet extends SynchronizedCollection implement
* @param the type held in this Set.
*/
static class SynchronizedSet extends SynchronizedCollection implements Set {
+
/** Serialization version */
private static final long serialVersionUID = 20150629L;
/**
* Constructs a new instance.
+ *
* @param set the set to decorate
* @param lock the lock to use, shared with the multiset
*/
diff --git a/src/main/java/org/apache/commons/collections4/multiset/package-info.java b/src/main/java/org/apache/commons/collections4/multiset/package-info.java
index 58c1b4cd6c..5b8486f549 100644
--- a/src/main/java/org/apache/commons/collections4/multiset/package-info.java
+++ b/src/main/java/org/apache/commons/collections4/multiset/package-info.java
@@ -21,15 +21,17 @@
* A multiset stores an object and a count of the number of occurrences of the object.
*
* The following implementations are provided in the package:
+ *
*
- *
HashMultiSet - implementation that uses a HashMap to store the data
+ *
HashMultiSet - implementation that uses a HashMap to store the data
*
*
* The following decorators are provided in the package:
+ *
*
- *
Predicated - ensures that only elements that are valid according to a predicate can be added
- *
Synchronized - synchronizes method access for multithreaded environments
- *
Unmodifiable - ensures the multiset cannot be altered
+ *
Predicated - ensures that only elements that are valid according to a predicate can be added
+ *
Synchronized - synchronizes method access for multithreaded environments
+ *
Unmodifiable - ensures the multiset cannot be altered
*
*/
package org.apache.commons.collections4.multiset;
diff --git a/src/main/java/org/apache/commons/collections4/package-info.java b/src/main/java/org/apache/commons/collections4/package-info.java
index ef1e29105e..7e45d23606 100644
--- a/src/main/java/org/apache/commons/collections4/package-info.java
+++ b/src/main/java/org/apache/commons/collections4/package-info.java
@@ -21,7 +21,7 @@
* The following collection implementations are provided in the package:
*
*
- *
ArrayStack - a non synchronized Stack that follows the same API as {@code java.util Stack}
+ *
ArrayStack - a non synchronized Stack that follows the same API as {@code java.util Stack}
*
*/
package org.apache.commons.collections4;
diff --git a/src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java b/src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java
index fb39e749d1..3252b61f78 100644
--- a/src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java
+++ b/src/main/java/org/apache/commons/collections4/properties/OrderedProperties.java
@@ -84,6 +84,26 @@ public Set
+
+
+ For information about safe deserialization, please see Safe Deserialization.
+
+
+
diff --git a/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java b/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java
index db2eaa5cbc..4a31e6e848 100644
--- a/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java
+++ b/src/test/java/org/apache/commons/collections4/AbstractObjectTest.java
@@ -74,7 +74,6 @@ protected String getCanonicalFullCollectionName(final Object object) {
return retval.toString();
}
- // protected implementation
/**
* Gets the version of Collections that this object tries to
* maintain serialization compatibility with. Defaults to 4, due to
diff --git a/src/test/java/org/apache/commons/collections4/FactoryUtilsTest.java b/src/test/java/org/apache/commons/collections4/FactoryUtilsTest.java
index c35b5b785f..90f020bffd 100644
--- a/src/test/java/org/apache/commons/collections4/FactoryUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/FactoryUtilsTest.java
@@ -65,6 +65,7 @@ public int hashCode() { // please Findbugs
}
public static class Mock2 implements Serializable {
+
/**
* Generated serial version ID.
*/
diff --git a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
index 0dbeed2543..51b71a6a25 100644
--- a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java
@@ -628,24 +628,25 @@ void testInvertEmptyMap() {
@Test
void testInvertMap() {
- final Map in = new HashMap<>(5, 1);
+ testInvertMap(new HashMap<>(5, 1));
+ }
+
+ private void testInvertMap(final Map in) {
+ // setup
in.put("1", "A");
in.put("2", "B");
in.put("3", "C");
in.put("4", "D");
in.put("5", "E");
-
final Set inKeySet = new HashSet<>(in.keySet());
final Set inValSet = new HashSet<>(in.values());
-
+ // invert
final Map out = MapUtils.invertMap(in);
-
+ // assert
final Set outKeySet = new HashSet<>(out.keySet());
final Set outValSet = new HashSet<>(out.values());
-
assertEquals(inKeySet, outValSet);
assertEquals(inValSet, outKeySet);
-
assertEquals("1", out.get("A"));
assertEquals("2", out.get("B"));
assertEquals("3", out.get("C"));
@@ -653,6 +654,11 @@ void testInvertMap() {
assertEquals("5", out.get("E"));
}
+ @Test
+ void testInvertMapDefault() {
+ testInvertMap(new HashMap<>());
+ }
+
@Test
void testInvertMapNull() {
final Map nullMap = null;
diff --git a/src/test/java/org/apache/commons/collections4/MultiMapUtilsTest.java b/src/test/java/org/apache/commons/collections4/MultiMapUtilsTest.java
index 14f177f2b4..7ff98ba078 100644
--- a/src/test/java/org/apache/commons/collections4/MultiMapUtilsTest.java
+++ b/src/test/java/org/apache/commons/collections4/MultiMapUtilsTest.java
@@ -29,6 +29,8 @@
import java.util.Set;
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
+import org.apache.commons.collections4.multimap.HashSetValuedHashMap;
+import org.apache.commons.collections4.multimap.LinkedHashSetValuedLinkedHashMap;
import org.junit.jupiter.api.Test;
/**
@@ -116,6 +118,30 @@ void testGetValuesAsSet() {
assertEquals(new HashSet<>(Arrays.asList(values)), set);
}
+ @Test
+ void testInvert() {
+ final HashSetValuedHashMap usages = new HashSetValuedHashMap<>();
+
+ final LinkedHashSetValuedLinkedHashMap deps = new LinkedHashSetValuedLinkedHashMap<>();
+ deps.put("commons-configuration2", "commons-logging");
+ deps.put("commons-configuration2", "commons-lang3");
+ deps.put("commons-configuration2", "commons-text");
+ deps.put("commons-beanutils", "commons-collections");
+ deps.put("commons-beanutils", "commons-logging");
+ MultiMapUtils.invert(deps, usages);
+ final Set loggingUsagesCompile = usages.get("commons-logging");
+ assertEquals("[commons-configuration2, commons-beanutils]", loggingUsagesCompile.toString());
+ final Set codecUsagesCompile = usages.get("commons-codec");
+ assertEquals("[]", codecUsagesCompile.toString());
+
+ final LinkedHashSetValuedLinkedHashMap optionalDeps = new LinkedHashSetValuedLinkedHashMap<>();
+ optionalDeps.put("commons-configuration2", "commons-codec");
+ optionalDeps.put("commons-collections", "commons-codec");
+ MultiMapUtils.invert(optionalDeps, usages);
+ final Set codecUsagesAll = usages.get("commons-codec");
+ assertEquals("[commons-collections, commons-configuration2]", codecUsagesAll.toString());
+ }
+
@Test
void testIsEmptyWithEmptyMap() {
assertTrue(MultiMapUtils.isEmpty(new ArrayListValuedHashMap<>()));
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellExtractorTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellExtractorTest.java
index 2753bd4d68..0e1a95f19a 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellExtractorTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellExtractorTest.java
@@ -34,6 +34,7 @@ public abstract class AbstractCellExtractorTest extends AbstractIndexExtractorTe
* A testing CellConsumer that always returns true.
*/
private static final CellPredicate TRUE_CONSUMER = (i, j) -> true;
+
/**
* A testing CellConsumer that always returns false.
*/
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexExtractorTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexExtractorTest.java
index fefc54998c..163743c842 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexExtractorTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexExtractorTest.java
@@ -66,6 +66,7 @@ int[] toArray() {
private static final IntPredicate TRUE_PREDICATE = i -> true;
private static final IntPredicate FALSE_PREDICATE = i -> false;
+
/** Flag to indicate the indices are ordered, for example from {@link IndexExtractor#processIndices(IntPredicate)}. */
protected static final int ORDERED = 0x1;
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilterTest.java
index de5ba276cd..a4eb2a8553 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilterTest.java
@@ -260,6 +260,7 @@ void testCleanup() {
f = underTest.get(0);
assertEquals(3, f.sequence); // it is a new one.
}
+
/**
* Tests that the estimated union calculations are correct.
*/
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java b/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java
index 161e2d0ff0..90dce57897 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java
@@ -22,6 +22,7 @@
* A collection of methods and statics that represent standard hashers in testing.
*/
public class TestingHashers {
+
/**
* Hasher that increments from 1.
*/
diff --git a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java
index 49e168ecfe..1645d72c13 100644
--- a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java
+++ b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java
@@ -57,19 +57,24 @@
* implement the {@link #makeObject()}, {@link #makeConfirmedCollection()}
* and {@link #makeConfirmedFullCollection()} methods.
* You might want to override some of the additional public methods as well:
+ *
*
* Element Population Methods
+ *
*
* Override these if your collection restricts what kind of elements are
* allowed (for instance, if {@code null} is not permitted):
+ *
*
*
{@link #getFullElements()}
*
{@link #getOtherElements()}
*
*
* Supported Operation Methods
+ *
*
* Override these if your collection doesn't support certain operations:
+ *
* Override these if your collection makes specific behavior guarantees:
+ *
*
*
{@link #getIterationBehaviour()}
*
*
* Fixture Methods
+ *
*
* Fixtures are used to verify that the operation results in correct state
* for the collection. Basically, the operation is performed against your
@@ -99,12 +107,14 @@
* than a simple {@code equals} test. This verification is used to ensure
* proper modifications are made along with ensuring that the collection does
* not change when read-only modifications are made.
+ *
*
* The {@link #collection} field holds an instance of your collection
* implementation; the {@link #confirmed} field holds an instance of the
* confirmed collection implementation. The {@link #resetEmpty()} and
* {@link #resetFull()} methods set these fields to empty or full collections,
* so that tests can proceed from a known state.
+ *
*
* After a modification operation to both {@link #collection} and
* {@link #confirmed}, the {@link #verify()} method is invoked to compare
@@ -113,9 +123,11 @@
* views of a map, {@link org.apache.commons.collections4.map.AbstractMapTest AbstractTestMap}
* would override {@link #verify()} to make
* sure the map is changed after the collection view is changed.
+ *
*
* If you're extending this class directly, you will have to provide
* implementations for the following:
+ *
* Those methods should provide a confirmed collection implementation
* that's compatible with your collection implementation.
+ *
*
* If you're extending {@link org.apache.commons.collections4.list.AbstractListTest AbstractListTest},
* {@link org.apache.commons.collections4.set.AbstractSetTest AbstractTestSet},
* or {@link org.apache.commons.collections4.bag.AbstractBagTest AbstractBagTest},
* you probably don't have to worry about the
* above methods, because those three classes already override the methods
- * to provide standard JDK confirmed collections.
+ * to provide standard JDK confirmed collections.
+ *
*
* Other notes
+ *
*
* If your {@link Collection} fails one of these tests by design,
* you may still use this base set of cases. Simply override the
* test case (method) your {@link Collection} fails.
+ *
*/
public abstract class AbstractCollectionTest extends AbstractObjectTest {
@@ -245,42 +261,46 @@ private static void assertUnorderedArrayEquals(final Object[] a1, final Object[]
}
/**
- * A collection instance that will be used for testing.
+ * A collection instance that will be used for testing.
*/
private Collection collection;
/**
- * Confirmed collection. This is an instance of a collection that is
- * confirmed to conform exactly to the java.util.Collection contract.
- * Modification operations are tested by performing a mod on your
- * collection, performing the exact same mod on an equivalent confirmed
- * collection, and then calling verify() to make sure your collection
- * still matches the confirmed collection.
+ * Confirmed collection. This is an instance of a collection that is
+ * confirmed to conform exactly to the java.util.Collection contract.
+ * Modification operations are tested by performing a mod on your
+ * collection, performing the exact same mod on an equivalent confirmed
+ * collection, and then calling verify() to make sure your collection
+ * still matches the confirmed collection.
*/
private Collection confirmed;
/**
- * Specifies whether equal elements in the collection are, in fact,
- * distinguishable with information not readily available. That is, if a
- * particular value is to be removed from the collection, then there is
- * one and only one value that can be removed, even if there are other
- * elements which are equal to it.
- *
- *
In most collection cases, elements are not distinguishable (equal is
- * equal), thus this method defaults to return false. In some cases,
- * however, they are. For example, the collection returned from the map's
- * values() collection view are backed by the map, so while there may be
- * two values that are equal, their associated keys are not. Since the
- * keys are distinguishable, the values are.
- *
- *
This flag is used to skip some verifications for iterator.remove()
- * where it is impossible to perform an equivalent modification on the
- * confirmed collection because it is not possible to determine which
- * value in the confirmed collection to actually remove. Tests that
- * override the default (i.e. where equal elements are distinguishable),
- * should provide additional tests on iterator.remove() to make sure the
- * proper elements are removed when remove() is called on the iterator.
- **/
+ * Specifies whether equal elements in the collection are, in fact,
+ * distinguishable with information not readily available.
+ *
+ * If a particular value is to be removed from the collection, then there is
+ * one and only one value that can be removed, even if there are other
+ * elements which are equal to it.
+ *
+ *
+ * In most collection cases, elements are not distinguishable (equal is
+ * equal), thus this method defaults to return false. In some cases,
+ * however, they are. For example, the collection returned from the map's
+ * values() collection view are backed by the map, so while there may be
+ * two values that are equal, their associated keys are not. Since the
+ * keys are distinguishable, the values are.
+ *
+ *
+ * This flag is used to skip some verifications for iterator.remove()
+ * where it is impossible to perform an equivalent modification on the
+ * confirmed collection because it is not possible to determine which
+ * value in the confirmed collection to actually remove. Tests that
+ * override the default (i.e. where equal elements are distinguishable),
+ * should provide additional tests on iterator.remove() to make sure the
+ * proper elements are removed when remove() is called on the iterator.
+ *
+ */
public boolean areEqualElementsDistinguishable() {
return false;
}
@@ -303,14 +323,18 @@ public Collection getConfirmed() {
}
/**
- * Returns an array of objects that are contained in a collection
- * produced by {@link #makeFullCollection()}. Every element in the
- * returned array must be an element in a full collection.
- * The default implementation returns a heterogeneous array of
- * objects with some duplicates. null is added if allowed.
- * Override if you require specific testing elements. Note that if you
- * override {@link #makeFullCollection()}, you must override
- * this method to reflect the contents of a full collection.
+ * Returns an array of objects that are contained in a collection
+ * produced by {@link #makeFullCollection()}.
+ *
+ * Every element in the returned array must be an element in a full collection.
+ *
+ *
+ * The default implementation returns a heterogeneous array of
+ * objects with some duplicates. null is added if allowed.
+ * Override if you require specific testing elements. Note that if you
+ * override {@link #makeFullCollection()}, you must override
+ * this method to reflect the contents of a full collection.
+ *
*/
@SuppressWarnings("unchecked")
public E[] getFullElements() {
@@ -323,12 +347,12 @@ public E[] getFullElements() {
}
/**
- * Returns a list of elements suitable for return by
- * {@link #getFullElements()}. The array returned by this method
- * does not include null, but does include a variety of objects
- * of different types. Override getFullElements to return
- * the results of this method if your collection does not support
- * the null element.
+ * Returns a list of elements suitable for return by
+ * {@link #getFullElements()}. The array returned by this method
+ * does not include null, but does include a variety of objects
+ * of different types. Override getFullElements to return
+ * the results of this method if your collection does not support
+ * the null element.
*/
@SuppressWarnings("unchecked")
public E[] getFullNonNullElements() {
@@ -355,10 +379,10 @@ public E[] getFullNonNullElements() {
}
/**
- * Returns a list of string elements suitable for return by
- * {@link #getFullElements()}. Override getFullElements to return
- * the results of this method if your collection does not support
- * heterogeneous elements or the null element.
+ * Returns a list of string elements suitable for return by
+ * {@link #getFullElements()}. Override getFullElements to return
+ * the results of this method if your collection does not support
+ * heterogeneous elements or the null element.
*/
public Object[] getFullNonNullStringElements() {
return new Object[] {
@@ -380,22 +404,22 @@ protected int getIterationBehaviour() {
}
/**
- * Returns an array of elements that are not contained in a
- * full collection. Every element in the returned array must
- * not exist in a collection returned by {@link #makeFullCollection()}.
- * The default implementation returns a heterogeneous array of elements
- * without null. Note that some of the tests add these elements
- * to an empty or full collection, so if your collection restricts
- * certain kinds of elements, you should override this method.
+ * Returns an array of elements that are not contained in a
+ * full collection. Every element in the returned array must
+ * not exist in a collection returned by {@link #makeFullCollection()}.
+ * The default implementation returns a heterogeneous array of elements
+ * without null. Note that some of the tests add these elements
+ * to an empty or full collection, so if your collection restricts
+ * certain kinds of elements, you should override this method.
*/
public E[] getOtherElements() {
return getOtherNonNullElements();
}
/**
- * Returns the default list of objects returned by
- * {@link #getOtherElements()}. Includes many objects
- * of different types.
+ * Returns the default list of objects returned by
+ * {@link #getOtherElements()}. Includes many objects
+ * of different types.
*/
@SuppressWarnings("unchecked")
public E[] getOtherNonNullElements() {
@@ -413,10 +437,10 @@ public E[] getOtherNonNullElements() {
}
/**
- * Returns a list of string elements suitable for return by
- * {@link #getOtherElements()}. Override getOtherElements to return
- * the results of this method if your collection does not support
- * heterogeneous elements or the null element.
+ * Returns a list of string elements suitable for return by
+ * {@link #getOtherElements()}. Override getOtherElements to return
+ * the results of this method if your collection does not support
+ * heterogeneous elements or the null element.
*/
public Object[] getOtherNonNullStringElements() {
return new Object[] {
@@ -426,12 +450,14 @@ public Object[] getOtherNonNullStringElements() {
}
/**
- * Returns true if the collections produced by
- * {@link #makeObject()} and {@link #makeFullCollection()}
- * support the {@code add} and {@code addAll}
- * operations.
- * Default implementation returns true. Override if your collection
- * class does not support add or addAll.
+ * Returns true if the collections produced by
+ * {@link #makeObject()} and {@link #makeFullCollection()}
+ * support the {@code add} and {@code addAll}
+ * operations.
+ *
+ * Default implementation returns true. Override if your collection
+ * class does not support add or addAll.
+ *
*/
public boolean isAddSupported() {
return true;
@@ -463,44 +489,44 @@ public boolean isNullSupported() {
}
/**
- * Returns true if the collections produced by
- * {@link #makeObject()} and {@link #makeFullCollection()}
- * support the {@code remove}, {@code removeAll},
- * {@code retainAll}, {@code clear} and
- * {@code iterator().remove()} methods.
- * Default implementation returns true. Override if your collection
- * class does not support removal operations.
+ * Returns true if the collections produced by
+ * {@link #makeObject()} and {@link #makeFullCollection()}
+ * support the {@code remove}, {@code removeAll},
+ * {@code retainAll}, {@code clear} and
+ * {@code iterator().remove()} methods.
+ * Default implementation returns true. Override if your collection
+ * class does not support removal operations.
*/
public boolean isRemoveSupported() {
return true;
}
/**
- * Returns a confirmed empty collection.
- * For instance, an {@link java.util.ArrayList} for lists or a
- * {@link java.util.HashSet} for sets.
+ * Returns a confirmed empty collection.
+ * For instance, an {@link java.util.ArrayList} for lists or a
+ * {@link java.util.HashSet} for sets.
*
- * @return a confirmed empty collection
+ * @return a confirmed empty collection
*/
public abstract Collection makeConfirmedCollection();
/**
- * Returns a confirmed full collection.
- * For instance, an {@link java.util.ArrayList} for lists or a
- * {@link java.util.HashSet} for sets. The returned collection
- * should contain the elements returned by {@link #getFullElements()}.
+ * Returns a confirmed full collection.
+ * For instance, an {@link java.util.ArrayList} for lists or a
+ * {@link java.util.HashSet} for sets. The returned collection
+ * should contain the elements returned by {@link #getFullElements()}.
*
- * @return a confirmed full collection
+ * @return a confirmed full collection
*/
public abstract Collection makeConfirmedFullCollection();
/**
- * Returns a full collection to be used for testing. The collection
- * returned by this method should contain every element returned by
- * {@link #getFullElements()}. The default implementation, in fact,
- * simply invokes {@code addAll} on an empty collection with
- * the results of {@link #getFullElements()}. Override this default
- * if your collection doesn't support addAll.
+ * Returns a full collection to be used for testing. The collection
+ * returned by this method should contain every element returned by
+ * {@link #getFullElements()}. The default implementation, in fact,
+ * simply invokes {@code addAll} on an empty collection with
+ * the results of {@link #getFullElements()}. Override this default
+ * if your collection doesn't support addAll.
*/
public Collection makeFullCollection() {
final Collection c = makeObject();
@@ -515,9 +541,9 @@ public Collection makeFullCollection() {
public abstract Collection makeObject();
/**
- * Resets the {@link #collection} and {@link #confirmed} fields to empty
- * collections. Invoke this method before performing a modification
- * test.
+ * Resets the {@link #collection} and {@link #confirmed} fields to empty
+ * collections. Invoke this method before performing a modification
+ * test.
*/
public void resetEmpty() {
this.setCollection(makeObject());
@@ -525,9 +551,9 @@ public void resetEmpty() {
}
/**
- * Resets the {@link #collection} and {@link #confirmed} fields to full
- * collections. Invoke this method before performing a modification
- * test.
+ * Resets the {@link #collection} and {@link #confirmed} fields to full
+ * collections. Invoke this method before performing a modification
+ * test.
*/
public void resetFull() {
this.setCollection(makeFullCollection());
@@ -536,6 +562,7 @@ public void resetFull() {
/**
* Sets the collection.
+ *
* @param collection the Collection to set
*/
public void setCollection(final Collection collection) {
@@ -544,13 +571,13 @@ public void setCollection(final Collection collection) {
/**
* Sets the confirmed.
+ *
* @param confirmed the Collection to set
*/
public void setConfirmed(final Collection confirmed) {
this.confirmed = confirmed;
}
- // Tests
/**
* Tests {@link Collection#add(Object)}.
*/
diff --git a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java
index 4a02113a47..b7116edd76 100644
--- a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java
+++ b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java
@@ -79,6 +79,7 @@ public Collection makeConfirmedCollection() {
public Collection makeConfirmedFullCollection() {
return new HashSet<>(Arrays.asList(getFullElements()));
}
+
/**
* Full collection consists of 4 collections, each with one element
*/
@@ -93,6 +94,7 @@ public Collection makeFullCollection() {
}
return compositeCollection;
}
+
/**
* Empty collection is empty composite
*/
diff --git a/src/test/java/org/apache/commons/collections4/functors/AbstractMockPredicateTest.java b/src/test/java/org/apache/commons/collections4/functors/AbstractMockPredicateTest.java
index ad6e28065c..b4bfeca14c 100644
--- a/src/test/java/org/apache/commons/collections4/functors/AbstractMockPredicateTest.java
+++ b/src/test/java/org/apache/commons/collections4/functors/AbstractMockPredicateTest.java
@@ -32,6 +32,7 @@
* provides methods to create and verify mock predicates to which to delegate.
*/
public abstract class AbstractMockPredicateTest {
+
/**
* Mock predicates created by a single test case which need to be verified after the test completes.
*/
diff --git a/src/test/java/org/apache/commons/collections4/iterators/ExtendedIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/ExtendedIteratorTest.java
index 612bb60629..21ae019073 100644
--- a/src/test/java/org/apache/commons/collections4/iterators/ExtendedIteratorTest.java
+++ b/src/test/java/org/apache/commons/collections4/iterators/ExtendedIteratorTest.java
@@ -32,6 +32,7 @@
import org.junit.jupiter.api.Test;
class ExtendedIteratorTest {
+
/**
* Collection of {@link Integer}s
*/
diff --git a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java
index 839b82d42e..f1dad5c1b6 100644
--- a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java
+++ b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java
@@ -167,10 +167,10 @@ public boolean supportsSet() {
}
/**
- * Traverses to the beginning of the given iterator.
+ * Traverses to the beginning of the given iterator.
*
- * @param iter the iterator to traverse
- * @param i the starting index
+ * @param iter the iterator to traverse
+ * @param i the starting index
*/
private void backwardTest(final ListIterator iter, int i) {
final List list = getCollection();
@@ -203,14 +203,14 @@ public BulkTest bulkTestListIterator() {
}
/**
- * Returns a {@link BulkTest} for testing {@link List#subList(int,int)}.
- * The returned bulk test will run through every {@code TestList}
- * method, including another {@code bulkTestSubList}.
- * Sublists are tested until the size of the sublist is less than 10.
- * Each sublist is 6 elements smaller than its parent list.
- * (By default this means that two rounds of sublists will be tested).
- * The verify() method is overloaded to test that the original list is
- * modified when the sublist is.
+ * Returns a {@link BulkTest} for testing {@link List#subList(int,int)}.
+ * The returned bulk test will run through every {@code TestList}
+ * method, including another {@code bulkTestSubList}.
+ * Sublists are tested until the size of the sublist is less than 10.
+ * Each sublist is 6 elements smaller than its parent list.
+ * (By default this means that two rounds of sublists will be tested).
+ * The verify() method is overloaded to test that the original list is
+ * modified when the sublist is.
*/
public BulkTest bulkTestSubList() {
if (getFullElements().length - 6 < 10) {
@@ -271,10 +271,10 @@ protected void failFastMethod(final List list, final Method m) {
}
/**
- * Traverses to the end of the given iterator.
+ * Traverses to the end of the given iterator.
*
- * @param iter the iterator to traverse
- * @param i the starting index
+ * @param iter the iterator to traverse
+ * @param i the starting index
*/
private void forwardTest(final ListIterator iter, int i) {
final List list = getCollection();
@@ -328,11 +328,11 @@ public boolean isEqualsCheckable() {
}
/**
- * Returns true if the collections produced by
- * {@link #makeObject()} and {@link #makeFullCollection()}
- * support the set operation.
- * Default implementation returns true. Override if your collection
- * class does not support set.
+ * Returns true if the collections produced by
+ * {@link #makeObject()} and {@link #makeFullCollection()}
+ * support the set operation.
+ * Default implementation returns true. Override if your collection
+ * class does not support set.
*/
public boolean isSetSupported() {
return true;
@@ -458,7 +458,7 @@ void testFullListSerialization() throws IOException, ClassNotFoundException {
}
/**
- * Tests {@link List#add(int,Object)}.
+ * Tests {@link List#add(int,Object)}.
*/
@Test
void testListAddByIndex() {
@@ -478,8 +478,8 @@ void testListAddByIndex() {
}
/**
- * Tests bounds checking for {@link List#add(int, Object)} on an
- * empty list.
+ * Tests bounds checking for {@link List#add(int, Object)} on an
+ * empty list.
*/
@Test
void testListAddByIndexBoundsChecking() {
@@ -507,8 +507,8 @@ void testListAddByIndexBoundsChecking() {
}
/**
- * Tests bounds checking for {@link List#add(int, Object)} on a
- * full list.
+ * Tests bounds checking for {@link List#add(int, Object)} on a
+ * full list.
*/
@Test
void testListAddByIndexBoundsChecking2() {
@@ -536,7 +536,7 @@ void testListAddByIndexBoundsChecking2() {
}
/**
- * Tests {@link List#equals(Object)}.
+ * Tests {@link List#equals(Object)}.
*/
@Test
void testListEquals() {
@@ -607,7 +607,7 @@ public int size() {
}
/**
- * Tests {@link List#get(int)}.
+ * Tests {@link List#get(int)}.
*/
@Test
void testListGetByIndex() {
@@ -621,8 +621,8 @@ void testListGetByIndex() {
}
/**
- * Tests bounds checking for {@link List#get(int)} on an
- * empty list.
+ * Tests bounds checking for {@link List#get(int)} on an
+ * empty list.
*/
@Test
void testListGetByIndexBoundsChecking() {
@@ -645,8 +645,8 @@ void testListGetByIndexBoundsChecking() {
}
/**
- * Tests bounds checking for {@link List#get(int)} on a
- * full list.
+ * Tests bounds checking for {@link List#get(int)} on a
+ * full list.
*/
@Test
void testListGetByIndexBoundsChecking2() {
@@ -666,7 +666,7 @@ void testListGetByIndexBoundsChecking2() {
}
/**
- * Tests {@link List#hashCode()}.
+ * Tests {@link List#hashCode()}.
*/
@Test
void testListHashCode() {
@@ -684,7 +684,7 @@ void testListHashCode() {
}
/**
- * Tests {@link List#indexOf}.
+ * Tests {@link List#indexOf}.
*/
@Test
void testListIndexOf() {
@@ -707,8 +707,8 @@ void testListIndexOf() {
}
/**
- * Tests the {@link ListIterator#add(Object)} method of the list
- * iterator.
+ * Tests the {@link ListIterator#add(Object)} method of the list
+ * iterator.
*/
@Test
void testListIteratorAdd() {
@@ -743,8 +743,8 @@ void testListIteratorAdd() {
}
/**
- * Tests the {@link ListIterator#set(Object)} method of the list
- * iterator.
+ * Tests the {@link ListIterator#set(Object)} method of the list
+ * iterator.
*/
@Test
void testListIteratorSet() {
@@ -767,7 +767,7 @@ void testListIteratorSet() {
}
/**
- * Tests {@link List#lastIndexOf}.
+ * Tests {@link List#lastIndexOf}.
*/
@Test
void testListLastIndexOf() {
@@ -790,7 +790,7 @@ void testListLastIndexOf() {
}
/**
- * Tests the read-only bits of {@link List#listIterator()}.
+ * Tests the read-only bits of {@link List#listIterator()}.
*/
@Test
void testListListIterator() {
@@ -800,7 +800,7 @@ void testListListIterator() {
}
/**
- * Tests the read-only bits of {@link List#listIterator(int)}.
+ * Tests the read-only bits of {@link List#listIterator(int)}.
*/
@Test
void testListListIteratorByIndex() {
@@ -945,7 +945,7 @@ void testListListIteratorPreviousRemovePrevious() {
}
/**
- * Tests {@link List#remove(int)}.
+ * Tests {@link List#remove(int)}.
*/
@Test
void testListRemoveByIndex() {
@@ -964,8 +964,8 @@ void testListRemoveByIndex() {
}
/**
- * Tests bounds checking for {@link List#remove(int)} on an
- * empty list.
+ * Tests bounds checking for {@link List#remove(int)} on an
+ * empty list.
*/
@Test
void testListRemoveByIndexBoundsChecking() {
@@ -992,8 +992,8 @@ void testListRemoveByIndexBoundsChecking() {
}
/**
- * Tests bounds checking for {@link List#remove(int)} on a
- * full list.
+ * Tests bounds checking for {@link List#remove(int)} on a
+ * full list.
*/
@Test
void testListRemoveByIndexBoundsChecking2() {
@@ -1017,7 +1017,7 @@ void testListRemoveByIndexBoundsChecking2() {
}
/**
- * Test {@link List#set(int,Object)}.
+ * Test {@link List#set(int,Object)}.
*/
@Test
void testListSetByIndex() {
@@ -1039,8 +1039,8 @@ void testListSetByIndex() {
}
/**
- * Tests bounds checking for {@link List#set(int,Object)} on an
- * empty list.
+ * Tests bounds checking for {@link List#set(int,Object)} on an
+ * empty list.
*/
@Test
void testListSetByIndexBoundsChecking() {
@@ -1068,8 +1068,8 @@ void testListSetByIndexBoundsChecking() {
}
/**
- * Tests bounds checking for {@link List#set(int,Object)} on a
- * full list.
+ * Tests bounds checking for {@link List#set(int,Object)} on a
+ * full list.
*/
@Test
void testListSetByIndexBoundsChecking2() {
@@ -1169,8 +1169,8 @@ void testListSubListFailFastOnRemove() {
}
/**
- * If {@link #isSetSupported()} returns false, tests that set operation
- * raises UnsupportedOperationException.
+ * If {@link #isSetSupported()} returns false, tests that set operation
+ * raises UnsupportedOperationException.
*/
@Test
void testUnsupportedSet() {
@@ -1187,8 +1187,8 @@ void testUnsupportedSet() {
}
/**
- * Verifies that the test list implementation matches the confirmed list
- * implementation.
+ * Verifies that the test list implementation matches the confirmed list
+ * implementation.
*/
@Override
@SuppressWarnings("unchecked")
diff --git a/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java b/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
index 9cd1b4bd01..2a22a89c6d 100644
--- a/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
+++ b/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java
@@ -42,6 +42,7 @@
public class SetUniqueListTest extends AbstractListTest {
final class SetUniqueList307 extends SetUniqueList {
+
/**
* Generated serial version ID.
*/
diff --git a/src/test/java/org/apache/commons/collections4/list/TreeListTest.java b/src/test/java/org/apache/commons/collections4/list/TreeListTest.java
index ec5b683e66..bff75d2bc7 100644
--- a/src/test/java/org/apache/commons/collections4/list/TreeListTest.java
+++ b/src/test/java/org/apache/commons/collections4/list/TreeListTest.java
@@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList;
import java.util.List;
@@ -202,16 +203,6 @@ void testIndexOf() {
assertEquals(0, l.indexOf("3"));
}
-// void testCheck() {
-// List l = makeEmptyList();
-// l.add("A1");
-// l.add("A2");
-// l.add("A3");
-// l.add("A4");
-// l.add("A5");
-// l.add("A6");
-// }
-
@Test
@SuppressWarnings("unchecked")
void testInsertBefore() {
@@ -222,6 +213,16 @@ void testInsertBefore() {
assertEquals("erna", l.get(1));
}
+// void testCheck() {
+// List l = makeEmptyList();
+// l.add("A1");
+// l.add("A2");
+// l.add("A3");
+// l.add("A4");
+// l.add("A5");
+// l.add("A6");
+// }
+
@Test
@SuppressWarnings("boxing") // OK in test code
void testIterationOrder() {
@@ -326,4 +327,15 @@ void testRemove() {
assertEquals("harald", l.get(i++));
}
+ @Test
+ void testTreeListIteratorConstruction() throws Throwable {
+ final TreeList treeList = new TreeList<>();
+ treeList.add("a");
+ treeList.add("b");
+ assertThrows(IndexOutOfBoundsException.class, () -> treeList.listIterator(3).previous());
+ assertThrows(IndexOutOfBoundsException.class, () -> new TreeList.TreeListIterator(treeList, 3));
+ // Test doesn't get to previous()
+ assertThrows(IndexOutOfBoundsException.class, () -> new TreeList.TreeListIterator(treeList, 3).previous());
+ }
+
}
diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
index 1fa6a52203..1c7ee770aa 100644
--- a/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/AbstractMapTest.java
@@ -164,6 +164,7 @@ public Map.Entry getEntry(final Iterator> itConfirmed, fin
}
// Have to implement manually; entrySet doesn't support addAll
+
/**
* {@inheritDoc}
*/
diff --git a/src/test/java/org/apache/commons/collections4/map/EmptyMapMutator.java b/src/test/java/org/apache/commons/collections4/map/EmptyMapMutator.java
index a9871f6672..75520d1e9e 100644
--- a/src/test/java/org/apache/commons/collections4/map/EmptyMapMutator.java
+++ b/src/test/java/org/apache/commons/collections4/map/EmptyMapMutator.java
@@ -25,6 +25,7 @@
* class also has to be serialized.
*/
final class EmptyMapMutator implements CompositeMap.MapMutator {
+
/** Serialization version */
private static final long serialVersionUID = -2729718980002476794L;
diff --git a/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java b/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java
index b15998dbe1..db65f2e2a7 100644
--- a/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java
@@ -612,6 +612,7 @@ public void run() {
map.entrySet().removeIf(entry -> entry.getValue() == this);
}
} catch (final InterruptedException e) {
+ interrupt();
fail("Unexpected InterruptedException");
}
if (i > 0) {
@@ -696,6 +697,7 @@ public void run() {
}
}
} catch (final InterruptedException e) {
+ interrupt();
fail("Unexpected InterruptedException");
}
if (i > 0) {
@@ -780,6 +782,7 @@ public void run() {
}
}
} catch (final InterruptedException e) {
+ interrupt();
fail("Unexpected InterruptedException");
}
if (i > 0) {
@@ -859,6 +862,7 @@ public void run() {
map.values().removeIf(thread1 -> thread1 == this);
}
} catch (final InterruptedException e) {
+ interrupt();
fail("Unexpected InterruptedException");
}
if (i > 0) {
diff --git a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java
index ff6a7b152e..f6ec78ce00 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/AbstractMultiValuedMapTest.java
@@ -435,7 +435,6 @@ public BulkTest bulkTestAsMap() {
return new MultiValuedMapAsMapTest();
}
- // Bulk Tests
/**
* Bulk test {@link MultiValuedMap#entries()}. This method runs through all
* of the tests in {@link AbstractCollectionTest}. After modification
diff --git a/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java
index 47e9a63e60..f65ee297c0 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java
@@ -93,6 +93,19 @@ void testEqualsHashCodeContract() {
assertNotSame(map1.hashCode(), map2.hashCode());
}
+ @Test
+ void testInverted() {
+ final ArrayListValuedHashMap shopping = new ArrayListValuedHashMap<>(4);
+ shopping.put("Alice", "Bread");
+ shopping.put("Alice", "Milk");
+ shopping.put("Alice", "Milk");
+ shopping.put("Bob", "Pizza");
+ shopping.put("Bob", "Bread");
+ shopping.put("Bob", "Bread");
+ assertEquals("{Pizza=[Bob], Bread=[Bob, Bob, Alice], Milk=[Alice, Alice]}",
+ shopping.inverted().toString());
+ }
+
@Test
@SuppressWarnings("unchecked")
void testListValuedMapAdd() {
diff --git a/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedLinkedHashMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedLinkedHashMapTest.java
index 74353b50ab..550a192409 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedLinkedHashMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedLinkedHashMapTest.java
@@ -99,6 +99,19 @@ void testEqualsHashCodeContract() {
assertNotSame(map1.hashCode(), map2.hashCode());
}
+ @Test
+ void testInverted() {
+ final ArrayListValuedLinkedHashMap shopping = new ArrayListValuedLinkedHashMap<>(4);
+ shopping.put("Alice", "Bread");
+ shopping.put("Alice", "Milk");
+ shopping.put("Alice", "Milk");
+ shopping.put("Bob", "Pizza");
+ shopping.put("Bob", "Bread");
+ shopping.put("Bob", "Bread");
+ assertEquals("{Bread=[Alice, Bob, Bob], Milk=[Alice, Alice], Pizza=[Bob]}",
+ shopping.inverted().toString());
+ }
+
@Test
@SuppressWarnings("unchecked")
void testListValuedMapAdd() {
diff --git a/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java
index 7b50d6cd13..419ae3814f 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java
@@ -110,6 +110,19 @@ void testHashSetValueHashMap_1() {
assertEquals("{}", map3.toString());
}
+ @Test
+ void testInverted() {
+ final HashSetValuedHashMap dependencies = new HashSetValuedHashMap<>();
+ dependencies.put("commons-configuration2", "commons-logging");
+ dependencies.put("commons-configuration2", "commons-lang3");
+ dependencies.put("commons-configuration2", "commons-text");
+ dependencies.put("commons-beanutils", "commons-collections");
+ dependencies.put("commons-beanutils", "commons-logging");
+ final Set loggingUsages = dependencies.inverted().get("commons-logging");
+ assertEquals("[commons-beanutils, commons-configuration2]",
+ loggingUsages.toString());
+ }
+
@Test
@SuppressWarnings("unchecked")
void testSetValuedMapAdd() {
diff --git a/src/test/java/org/apache/commons/collections4/multimap/LinkedHashSetValuedLinkedHashMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/LinkedHashSetValuedLinkedHashMapTest.java
index 2b37cb76d2..561432363b 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/LinkedHashSetValuedLinkedHashMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/LinkedHashSetValuedLinkedHashMapTest.java
@@ -96,6 +96,19 @@ void testHashSetValueHashMap_1() {
assertEquals("{}", map3.toString());
}
+ @Test
+ void testInverted() {
+ final LinkedHashSetValuedLinkedHashMap citiesLived = new LinkedHashSetValuedLinkedHashMap<>(4);
+ citiesLived.put("Alice", "N.Y.");
+ citiesLived.put("Alice", "L.A.");
+ citiesLived.put("Alice", "Chicago");
+ citiesLived.put("Bob", "N.Y.");
+ citiesLived.put("Cara", "L.A.");
+ citiesLived.put("Cara", "Chicago");
+ assertEquals("{N.Y.=[Alice, Bob], L.A.=[Alice, Cara], Chicago=[Alice, Cara]}",
+ citiesLived.inverted().toString());
+ }
+
@Test
void testLinkedHashSetValuedLinkedHashMap_2() {
final Map map = new HashMap<>();
diff --git a/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java
index 37ef87d8f0..d83b47108a 100644
--- a/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/multimap/TransformedMultiValuedMapTest.java
@@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collection;
@@ -99,6 +100,11 @@ void testFactory_decorateTransform() {
assertTrue(transMap.get((K) "D").contains(Integer.valueOf(4)));
}
+ @Test
+ void testInvertedIsUnsupportedByDefault() {
+ assertThrows(UnsupportedOperationException.class, () -> makeObject().inverted());
+ }
+
@Test
@SuppressWarnings("unchecked")
void testKeyTransformedMap() {
diff --git a/src/test/java/org/apache/commons/collections4/properties/OrderedPropertiesTest.java b/src/test/java/org/apache/commons/collections4/properties/OrderedPropertiesTest.java
index b463e60e6b..9d44952a4c 100644
--- a/src/test/java/org/apache/commons/collections4/properties/OrderedPropertiesTest.java
+++ b/src/test/java/org/apache/commons/collections4/properties/OrderedPropertiesTest.java
@@ -18,6 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -27,6 +28,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
@@ -57,6 +59,9 @@ private void assertAscendingOrder(final OrderedProperties orderedProperties) {
for (int i = first; i <= last; i++) {
assertEquals("key" + i, propertyNames.nextElement());
}
+ final Set propertyNameSet = orderedProperties.stringPropertyNames();
+ final AtomicInteger i = new AtomicInteger(first);
+ propertyNameSet.forEach(e -> assertEquals("key" + i.getAndIncrement(), e));
}
private OrderedProperties assertDescendingOrder(final OrderedProperties orderedProperties) {
@@ -80,6 +85,9 @@ private OrderedProperties assertDescendingOrder(final OrderedProperties orderedP
for (int i = first; i <= last; i--) {
assertEquals("key" + i, propertyNames.nextElement());
}
+ final Set propertyNameSet = orderedProperties.stringPropertyNames();
+ final AtomicInteger i = new AtomicInteger(first);
+ propertyNameSet.forEach(e -> assertEquals("key" + i.getAndDecrement(), e));
return orderedProperties;
}
@@ -287,6 +295,12 @@ void testRemoveKeyValue() throws FileNotFoundException, IOException {
assertFalse(Collections.list(props.propertyNames()).contains(k));
}
+ @Test
+ void testStringPropertyName() {
+ final OrderedProperties orderedProperties = new OrderedProperties();
+ assertTrue(orderedProperties.stringPropertyNames().isEmpty());
+ }
+
@Test
void testToString() {
final OrderedProperties orderedProperties = new OrderedProperties();
diff --git a/src/test/java/org/apache/commons/collections4/properties/SortedPropertiesTest.java b/src/test/java/org/apache/commons/collections4/properties/SortedPropertiesTest.java
index 9682f208a2..63c14ec49e 100644
--- a/src/test/java/org/apache/commons/collections4/properties/SortedPropertiesTest.java
+++ b/src/test/java/org/apache/commons/collections4/properties/SortedPropertiesTest.java
@@ -17,17 +17,116 @@
package org.apache.commons.collections4.properties;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
class SortedPropertiesTest {
+ private SortedProperties assertAscendingOrder(final SortedProperties sortedProperties) {
+ final String[] keys = { "1", "10", "11", "2", "3", "4", "5", "6", "7", "8", "9" };
+ final Enumeration enumObjects = sortedProperties.keys();
+ for (final String key : keys) {
+ assertEquals("key" + key, enumObjects.nextElement());
+ }
+ final Iterator iterSet = sortedProperties.keySet().iterator();
+ for (final String key : keys) {
+ assertEquals("key" + key, iterSet.next());
+ }
+ final Iterator> iterEntrySet = sortedProperties.entrySet().iterator();
+ for (final String key : keys) {
+ final Entry next = iterEntrySet.next();
+ assertEquals("key" + key, next.getKey());
+ assertEquals("value" + key, next.getValue());
+ }
+ final Enumeration> propertyNames = sortedProperties.propertyNames();
+ for (final String key : keys) {
+ assertEquals("key" + key, propertyNames.nextElement());
+ }
+ final Set propertyNameSet = sortedProperties.stringPropertyNames();
+ final AtomicInteger i = new AtomicInteger(0);
+ propertyNameSet.forEach(e -> assertEquals("key" + keys[i.getAndIncrement()], e));
+ return sortedProperties;
+ }
+
+ private SortedProperties loadOrderedKeysReverse() throws FileNotFoundException, IOException {
+ final SortedProperties sortedProperties = new SortedProperties();
+ try (FileReader reader = new FileReader("src/test/resources/org/apache/commons/collections4/properties/test-reverse.properties")) {
+ sortedProperties.load(reader);
+ }
+ return assertAscendingOrder(sortedProperties);
+ }
+
+ @Test
+ void testCompute() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ int first = 1;
+ int last = 11;
+ for (int i = first; i <= last; i++) {
+ final AtomicInteger aInt = new AtomicInteger(i);
+ sortedProperties.compute("key" + i, (k, v) -> "value" + aInt.get());
+ }
+ assertAscendingOrder(sortedProperties);
+ sortedProperties.clear();
+ first = 11;
+ last = 1;
+ for (int i = first; i >= last; i--) {
+ final AtomicInteger aInt = new AtomicInteger(i);
+ sortedProperties.compute("key" + i, (k, v) -> "value" + aInt.get());
+ }
+ assertAscendingOrder(sortedProperties);
+ }
+
+ @Test
+ void testComputeIfAbsent() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ int first = 1;
+ int last = 11;
+ for (int i = first; i <= last; i++) {
+ final AtomicInteger aInt = new AtomicInteger(i);
+ sortedProperties.computeIfAbsent("key" + i, k -> "value" + aInt.get());
+ }
+ assertAscendingOrder(sortedProperties);
+ sortedProperties.clear();
+ first = 11;
+ last = 1;
+ for (int i = first; i >= last; i--) {
+ final AtomicInteger aInt = new AtomicInteger(i);
+ sortedProperties.computeIfAbsent("key" + i, k -> "value" + aInt.get());
+ }
+ assertAscendingOrder(sortedProperties);
+ }
+
@Test
void testEntrySet() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ final char first = 'Z';
+ final char last = 'A';
+ for (char ch = first; ch >= last; ch--) {
+ sortedProperties.put(String.valueOf(ch), "Value" + ch);
+ }
+ final Iterator> entries = sortedProperties.entrySet().iterator();
+ for (char ch = first; ch <= last; ch++) {
+ final Map.Entry entry = entries.next();
+ assertEquals(String.valueOf(ch), entry.getKey());
+ assertEquals("Value" + ch, entry.getValue());
+ }
+ }
+
+ @Test
+ void testEntrySet2() {
final SortedProperties sortedProperties = new SortedProperties();
for (char ch = 'Z'; ch >= 'A'; ch--) {
sortedProperties.put(String.valueOf(ch), "Value" + ch);
@@ -40,8 +139,38 @@ void testEntrySet() {
}
}
+ @Test
+ void testForEach() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ final char first = 'Z';
+ final char last = 'A';
+ for (char ch = first; ch >= last; ch--) {
+ sortedProperties.put(String.valueOf(ch), "Value" + ch);
+ }
+ final AtomicInteger aCh = new AtomicInteger(last);
+ sortedProperties.forEach((k, v) -> {
+ final char ch = (char) aCh.getAndIncrement();
+ assertEquals(String.valueOf(ch), k);
+ assertEquals("Value" + ch, v);
+ });
+ }
+
@Test
void testKeys() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ final char first = 'Z';
+ final char last = 'A';
+ for (char ch = first; ch >= last; ch--) {
+ sortedProperties.put(String.valueOf(ch), "Value" + ch);
+ }
+ final Enumeration keys = sortedProperties.keys();
+ for (char ch = first; ch <= last; ch++) {
+ assertEquals(String.valueOf(ch), keys.nextElement());
+ }
+ }
+
+ @Test
+ void testKeys2() {
final SortedProperties sortedProperties = new SortedProperties();
for (char ch = 'Z'; ch >= 'A'; ch--) {
sortedProperties.put(String.valueOf(ch), "Value" + ch);
@@ -52,4 +181,133 @@ void testKeys() {
}
}
+ @Test
+ void testLoadOrderedKeys() throws IOException {
+ final SortedProperties sortedProperties = new SortedProperties();
+ try (FileReader reader = new FileReader("src/test/resources/org/apache/commons/collections4/properties/test.properties")) {
+ sortedProperties.load(reader);
+ }
+ assertAscendingOrder(sortedProperties);
+ }
+
+ @Test
+ void testLoadOrderedKeysReverse() throws IOException {
+ loadOrderedKeysReverse();
+ }
+
+ @Test
+ void testMerge() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ int first = 1;
+ int last = 11;
+ for (int i = first; i <= last; i++) {
+ sortedProperties.merge("key" + i, "value" + i, (k, v) -> v);
+ }
+ assertAscendingOrder(sortedProperties);
+ sortedProperties.clear();
+ first = 11;
+ last = 1;
+ for (int i = first; i >= last; i--) {
+ sortedProperties.merge("key" + i, "value" + i, (k, v) -> v);
+ }
+ assertAscendingOrder(sortedProperties);
+ }
+
+ @Test
+ void testPut() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ int first = 1;
+ int last = 11;
+ for (int i = first; i <= last; i++) {
+ sortedProperties.put("key" + i, "value" + i);
+ }
+ assertAscendingOrder(sortedProperties);
+ sortedProperties.clear();
+ first = 11;
+ last = 1;
+ for (int i = first; i >= last; i--) {
+ sortedProperties.put("key" + i, "value" + i);
+ }
+ assertAscendingOrder(sortedProperties);
+ }
+
+ @Test
+ void testPutAll() {
+ final SortedProperties sourceProperties = new SortedProperties();
+ int first = 1;
+ int last = 11;
+ for (int i = first; i <= last; i++) {
+ sourceProperties.put("key" + i, "value" + i);
+ }
+ final SortedProperties sortedProperties = new SortedProperties();
+ sortedProperties.putAll(sourceProperties);
+ assertAscendingOrder(sortedProperties);
+ sortedProperties.clear();
+ first = 11;
+ last = 1;
+ for (int i = first; i >= last; i--) {
+ sortedProperties.put("key" + i, "value" + i);
+ }
+ assertAscendingOrder(sortedProperties);
+ }
+
+ @Test
+ void testPutIfAbsent() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ int first = 1;
+ int last = 11;
+ for (int i = first; i <= last; i++) {
+ sortedProperties.putIfAbsent("key" + i, "value" + i);
+ }
+ assertAscendingOrder(sortedProperties);
+ sortedProperties.clear();
+ first = 11;
+ last = 1;
+ for (int i = first; i >= last; i--) {
+ sortedProperties.putIfAbsent("key" + i, "value" + i);
+ }
+ assertAscendingOrder(sortedProperties);
+ }
+
+ @Test
+ void testRemoveKey() throws FileNotFoundException, IOException {
+ final SortedProperties props = loadOrderedKeysReverse();
+ final String k = "key1";
+ props.remove(k);
+ assertFalse(props.contains(k));
+ assertFalse(props.containsKey(k));
+ assertFalse(Collections.list(props.keys()).contains(k));
+ assertFalse(Collections.list(props.propertyNames()).contains(k));
+ }
+
+ @Test
+ void testRemoveKeyValue() throws FileNotFoundException, IOException {
+ final SortedProperties props = loadOrderedKeysReverse();
+ final String k = "key1";
+ props.remove(k, "value1");
+ assertFalse(props.contains(k));
+ assertFalse(props.containsKey(k));
+ assertFalse(Collections.list(props.keys()).contains(k));
+ assertFalse(Collections.list(props.propertyNames()).contains(k));
+ }
+
+ @Test
+ void testStringPropertyName() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ assertTrue(sortedProperties.stringPropertyNames().isEmpty());
+ }
+
+ @Test
+ void testToString() {
+ final SortedProperties sortedProperties = new SortedProperties();
+ final char first = 'Z';
+ final char last = 'A';
+ for (char ch = first; ch >= last; ch--) {
+ sortedProperties.put(String.valueOf(ch), "Value" + ch);
+ }
+ assertEquals(
+ "{A=ValueA, B=ValueB, C=ValueC, D=ValueD, E=ValueE, F=ValueF, G=ValueG, H=ValueH, I=ValueI, J=ValueJ, K=ValueK, L=ValueL, M=ValueM, N=ValueN, O=ValueO, P=ValueP, Q=ValueQ, R=ValueR, S=ValueS, T=ValueT, U=ValueU, V=ValueV, W=ValueW, X=ValueX, Y=ValueY, Z=ValueZ}",
+ sortedProperties.toString());
+ }
+
}
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 9da685ef53..e1c7547605 100644
--- a/src/test/java/org/apache/commons/collections4/trie/PatriciaTrieTest.java
+++ b/src/test/java/org/apache/commons/collections4/trie/PatriciaTrieTest.java
@@ -33,6 +33,14 @@
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedMap;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
import org.apache.commons.collections4.Trie;
import org.apache.commons.collections4.map.AbstractSortedMapTest;
@@ -40,7 +48,7 @@
import org.junit.jupiter.api.Test;
/**
- * JUnit tests for the PatriciaTrie.
+ * Tests {@link PatriciaTrie}.
*
* @param the value type.
*/
@@ -437,6 +445,229 @@ void testPrefixMapSizes2() {
assertTrue(trie.prefixMap(prefixString).containsKey(longerString));
}
+ @Test
+ void testSubmap() {
+ final PatriciaTrie trie = new PatriciaTrie<>();
+ trie.put("ga", "ga");
+ trie.put("gb", "gb");
+ trie.put("gc", "gc");
+ trie.put("gd", "gd");
+ trie.put("ge", "ge");
+
+ // subMap should be entire trie
+ SortedMap subMap = trie.subMap("a", "z");
+ assertEquals(5, subMap.size());
+ assertEquals("ga", subMap.get("ga"));
+ assertEquals("gb", subMap.get("gb"));
+ assertEquals("gc", subMap.get("gc"));
+ assertEquals("gd", subMap.get("gd"));
+ assertEquals("ge", subMap.get("ge"));
+
+ // subMap should be empty
+ subMap = trie.subMap("a", "a");
+ assertEquals(0, subMap.size());
+
+ // subMap() is not inclusive of the second key
+ // subMap should be 4 entries only - "ge" excluded
+ subMap = trie.subMap("ga", "ge");
+ assertEquals(4, subMap.size());
+ assertEquals("ga", subMap.get("ga"));
+ assertEquals("gb", subMap.get("gb"));
+ assertEquals("gc", subMap.get("gc"));
+ assertEquals("gd", subMap.get("gd"));
+ assertNull(subMap.get("ge"));
+
+ // subMap should be 5 entries
+ subMap = trie.subMap("ga", "gf");
+ assertEquals(5, subMap.size());
+ assertEquals("ga", subMap.get("ga"));
+ assertEquals("gb", subMap.get("gb"));
+ assertEquals("gc", subMap.get("gc"));
+ assertEquals("gd", subMap.get("gd"));
+ assertEquals("ge", subMap.get("ge"));
+
+ // subMap should be 4 entries - "ga" excluded
+ subMap = trie.subMap("gb", "z");
+ assertEquals(4, subMap.size());
+ assertNull(subMap.get("ga"));
+ assertEquals("gb", subMap.get("gb"));
+ assertEquals("gc", subMap.get("gc"));
+ assertEquals("gd", subMap.get("gd"));
+ assertEquals("ge", subMap.get("ge"));
+
+
+ // subMap should be 1 entry - "gc" only
+ subMap = trie.subMap("gc", "gd");
+ assertEquals(1, subMap.size());
+ assertNull(subMap.get("ga"));
+ assertNull(subMap.get("gb"));
+ assertEquals("gc", subMap.get("gc"));
+ assertNull(subMap.get("gd"));
+ assertNull(subMap.get("ge"));
+ }
+
+ @Test
+ void testTailMap() {
+ final PatriciaTrie trie = new PatriciaTrie<>();
+ trie.put("ga", "ga");
+ trie.put("gb", "gb");
+ trie.put("gc", "gc");
+ trie.put("gd", "gd");
+ trie.put("ge", "ge");
+
+ // tailMap should be entire trie
+ SortedMap tailMap = trie.tailMap("a");
+ assertEquals(5, tailMap.size());
+ assertEquals("ga", tailMap.get("ga"));
+ assertEquals("gb", tailMap.get("gb"));
+ assertEquals("gc", tailMap.get("gc"));
+ assertEquals("gd", tailMap.get("gd"));
+ assertEquals("ge", tailMap.get("ge"));
+
+ // tailMap should be empty
+ tailMap = trie.tailMap("z");
+ assertEquals(0, tailMap.size());
+
+ // tailMap is inclusive of the search key
+ // tailMap should be the entire trie
+ tailMap = trie.tailMap("ga");
+ assertEquals(5, tailMap.size());
+ assertEquals("ga", tailMap.get("ga"));
+ assertEquals("gb", tailMap.get("gb"));
+ assertEquals("gc", tailMap.get("gc"));
+ assertEquals("gd", tailMap.get("gd"));
+ assertEquals("ge", tailMap.get("ge"));
+
+ // tailMap should be single entry "ge"
+ tailMap = trie.tailMap("ge");
+ assertEquals(1, tailMap.size());
+ assertNull(tailMap.get("ga"));
+ assertNull(tailMap.get("gb"));
+ assertNull(tailMap.get("gc"));
+ assertNull(tailMap.get("gd"));
+ assertEquals("ge", tailMap.get("ge"));
+ }
+
+ @Test
+ void testHeadMap() {
+ final PatriciaTrie trie = new PatriciaTrie<>();
+ trie.put("ga", "ga");
+ trie.put("gb", "gb");
+ trie.put("gc", "gc");
+ trie.put("gd", "gd");
+ trie.put("ge", "ge");
+
+ // headMap should be entire trie
+ SortedMap headMap = trie.headMap("z");
+ assertEquals(5, headMap.size());
+ assertEquals("ga", headMap.get("ga"));
+ assertEquals("gb", headMap.get("gb"));
+ assertEquals("gc", headMap.get("gc"));
+ assertEquals("gd", headMap.get("gd"));
+ assertEquals("ge", headMap.get("ge"));
+
+ // headMap should be empty
+ headMap = trie.headMap("a");
+ assertEquals(0, headMap.size());
+
+ // headMap() is not inclusive of the key
+ // headMap should be 4 entries only - "ge" excluded
+ headMap = trie.headMap("ge");
+ assertEquals(4, headMap.size());
+ assertEquals("ga", headMap.get("ga"));
+ assertEquals("gb", headMap.get("gb"));
+ assertEquals("gc", headMap.get("gc"));
+ assertEquals("gd", headMap.get("gd"));
+ assertNull(headMap.get("ge"));
+
+ // headMap should be 5 entries
+ headMap = trie.headMap("gf");
+ assertEquals(5, headMap.size());
+ assertEquals("ga", headMap.get("ga"));
+ assertEquals("gb", headMap.get("gb"));
+ assertEquals("gc", headMap.get("gc"));
+ assertEquals("gd", headMap.get("gd"));
+ assertEquals("ge", headMap.get("ge"));
+
+ // headMap should be 1 entry - "ga" only
+ headMap = trie.headMap("gb");
+ assertEquals(1, headMap.size());
+ assertEquals("ga", headMap.get("ga"));
+ assertNull(headMap.get("gb"));
+ assertNull(headMap.get("gc"));
+ assertNull(headMap.get("gd"));
+ assertNull(headMap.get("ge"));
+ }
+
+
+ @Test
+ void testConcurrentTrieIterationAndSubMapIteration() throws InterruptedException, ExecutionException, TimeoutException {
+ final PatriciaTrie trie = new PatriciaTrie<>();
+ // populate with enough entries to make concurrent collisions likely
+ // call subMap with both keys missing to ensure phantom node addition done twice
+ final int subKeyFirst = 1;
+ final int subKeySecond = 4;
+ final String subKeyFirstStr = String.format("key%04d", subKeyFirst);
+ final String subKeySecondStr = String.format("key%04d", subKeySecond);
+ for (int i = 0; i <= 501; i++) {
+ if (i != subKeyFirst && i != subKeySecond) {
+ trie.put(String.format("key%04d", i), i);
+ }
+ }
+
+ final int iterations = 100;
+ final CyclicBarrier barrier = new CyclicBarrier(2);
+
+ final ExecutorService executor = Executors.newFixedThreadPool(2);
+ try {
+ // Thread 1: repeatedly iterate the entire trie
+ final Future> iteratorTask = executor.submit(() -> {
+ barrier.await(1, TimeUnit.SECONDS);
+ for (int i = 0; i < iterations && !Thread.currentThread().isInterrupted(); i++) {
+ int count = 0;
+ for (final Map.Entry entry : trie.entrySet()) {
+ // verify the iterated keys and values are not from the phantom node
+ assertNotNull(entry.getKey());
+ assertNotNull(entry.getValue());
+ count++;
+ }
+ assertEquals(500, count, "Iterator skipped or duplicated entries");
+ }
+ return null;
+ });
+
+ // Thread 2: repeatedly create and iterate subMap views
+ // (this triggers ceilingEntry with keys NOT in the trie)
+ final Future> subMapTask = executor.submit(() -> {
+ barrier.await(1, TimeUnit.SECONDS);
+ for (int i = 0; i < iterations && !Thread.currentThread().isInterrupted(); i++) {
+ // Use boundary keys that do NOT exist in the trie
+ // to force the ceiling/floor walk algorithm
+ final SortedMap sub = trie.subMap(subKeyFirstStr, subKeySecondStr);
+ int count = 0;
+ for (final Map.Entry entry : sub.entrySet()) {
+ // verify the iterated keys and values are not from the phantom node
+ assertNotNull(entry.getKey());
+ assertNotNull(entry.getValue());
+ count++;
+ }
+ assertEquals(2, count, "subMap returned wrong number of entries");
+ }
+ return null;
+ });
+
+ // get() unwraps ExecutionException
+ // if either task threw an exception or an assertion Error, (or any Throwable),
+ // then the original exception propagates with its full stacktrace
+ // and TimeoutException surfaces hangs
+ subMapTask.get(10, TimeUnit.SECONDS);
+ iteratorTask.get(10, TimeUnit.SECONDS);
+ } finally {
+ executor.shutdownNow();
+ executor.awaitTermination(5, TimeUnit.SECONDS);
+ }
+ }
+
// void testCreate() throws Exception {
// resetEmpty();
// writeExternalFormToDisk(