-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add findDuplicates Method to ListUtils with Comprehensive Test Cases #537
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the result is effectively a set and the input does not have to be restricted to a list, it would be better to do this IMO:
public static <E> Set<E> duplicates(final Collection<E> list) {
final HashSet<E> dups = new HashSet<>();
final HashSet<E> set = new HashSet<>();
for (E e : list) {
(set.contains(e) ? dups : set).add(e);
}
return dups;
}
and put it in CollectionUtils
probably.
Thanks for the feedback. The
Keeping this method in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments. The input can still be
src/test/java/org/apache/commons/collections4/ListUtilsTest.java
Outdated
Show resolved
Hide resolved
Hello @hemanth0525 Please see git master for:
You are credited in Are there tests or functionality we could provide specific to ListUtils? I believe that this PR's new ListUtils method is now the same in functionality as Note that this PR is still failing. Run 'mvn' by itself before you push to catch all build errors. TY! |
hello @garydgregory, TY ! I guess all the change requests are done. i have run mvn locally and build success ! |
hello @garydgregory |
* @since 4.5.0-M3 | ||
*/ | ||
public static <E> List<E> findDuplicates(final List<E> list) { | ||
Objects.requireNonNull(list, "The input list must not be null."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you replace the body of this (git master) method with:
return IterableUtils.duplicateList(list);
You'll find that all tests pass.
So I don't think we need this method in this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u mean from CollectionUtils ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if yes, I have done it. So yeah utilizing the other function to help list functionalities.
* @since 4.5.0-M3 | ||
*/ | ||
public static <E> List<E> findDuplicates(final List<E> list) { | ||
return CollectionUtils.duplicateList(list); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you rebase on git master, you'll find this method in 'IterableUtils'.
Bumps [org.easymock:easymock](https://github.com/easymock/easymock) from 5.3.0 to 5.4.0. - [Release notes](https://github.com/easymock/easymock/releases) - [Changelog](https://github.com/easymock/easymock/blob/master/ReleaseNotes.md) - [Commits](easymock/easymock@easymock-5.3.0...easymock-5.4.0) --- updated-dependencies: - dependency-name: org.easymock:easymock dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]>
Bags instead of custom Maps
- Add TreeBag.TreeBag(Iterable)
Objects.requireNonNull()
…25/commons-collections into feature/findDuplicates
…into feature/findDuplicates
Oh Yeah !! |
Hello @hemanth0525 |
@garydgregory Okay so what u want me to do in this case ? |
I would either close the PR or update it if there are missing use cases in IterableUtilsTest (if yes, then also remove the new method from this PR). |
you can update |
I don't understand what you mean. |
sorry ! Suggested Improvement
Shall i make this update ? |
In git master, we now make sure
|
@garydgregory I just did that and thought of commiting........... |
- Mixed element types - Nested collections - Custom objects - Large-scale data - Immutable collections
…ctions into feature/findDuplicates
Hello @garydgregory, I have added several diverse test cases to |
update on this PR ? |
Hello @hemanth0525 Does the PR now provide additional code coverage? You can tell when you run "mvn clean install site" and you look at the JaCoCo report. Gary |
- Mixed element types - Nested collections - Custom objects - Large-scale data - Immutable collections
…25/commons-collections into feature/findDuplicates
i dont see any additional code coverage |
this PR started to provide functionalities to find duplicates to list which u have implemented in IterableUtils for all collections. so ig lets close this PR now |
Summary
This pull request introduces the
findDuplicates
method to theListUtils
class, a feature designed to enhance the functionality of list operations by providing a straightforward way to detect duplicate elements.Why This Change?
In many software development scenarios, detecting duplicates within a list is a common task. This functionality is essential for tasks such as data validation, cleaning, and processing. Instead of requiring developers to implement custom solutions or rely on third-party libraries, this method integrates seamlessly into the
ListUtils
class, offering a reliable and efficient way to handle duplicate detection.How This Change is Useful
Efficiency:
findDuplicates
method is implemented with optimal performance in mind, ensuring that duplicate detection is handled efficiently even for large lists.Simplification:
Versatility:
Example Usage