-
Notifications
You must be signed in to change notification settings - Fork 175
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
[MDEP-832] - Remove commons-collections-4 #255
Conversation
return new LinkedHashSet<>( | ||
CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); | ||
// @formatter:on | ||
Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); |
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.
I struggled on that one a few weeks ago.
Given the two sets are the same, I think the result will always be an empty set.
So I would just simply remove that call and the two added classes.
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.
No they are not the same. The first list (modelDependencies2) contains two entries (junit) while the hashset contains only a single entry of that and the result must be the single junit-jar difference. Check the unit test: TestAnalyzeDuplicateMojo
testcase testDuplicate
and testDuplicate2
which references src/test/resources/unit/duplicate-dependencies/plugin-config.xml
and the src/test/resources/unit/duplicate-dependencies/plugin-config2.xml
which contains exactly those cases.
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.
Ah, got it. But then, wouldn't it be simpler and more understandable :
/**
* Remove exactly one instance of each element from the given list.
*/
static <O> List<O> symmetricDifference( Collection<O> elements )
{
List<O> list = new ArrayList<>( elements );
Set<O> set = new HashSet<>( elements );
list.removeIf( set::remove );
return list;
}
It passes the slightly adapted tests in the UtilTest
(the two last ones).
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.
It could even be inlined with a simple comment...
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.
The shortest form could be:
private Set<String> findDuplicateDependencies( List<Dependency> modelDependencies )
{
List<String> modelDependencies2 = modelDependencies.stream()
.map( Dependency::getManagementKey ).collect( Collectors.toList() );
// remove one instance of each element from the list
modelDependencies2.removeIf( new HashSet<>( modelDependencies2 )::remove );
// keep a single instance of each duplicate
return new LinkedHashSet<>( modelDependencies2 );
}
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.
I agree with Guillaume. Please simplify (or remove) the util class with the code he provided.
After that, consider my changes request obsolete. :)
import static java.util.stream.Collectors.summingInt; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
class Util |
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.
This needs a more specific name. Arguably this can be a private method in the class that uses it.
@@ -260,11 +260,6 @@ under the License. | |||
<artifactId>commons-collections4</artifactId> |
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.
didn't you mean to remove this one?
There were a number of pom changes in flight at the same time so it looks like some of the PRs got a little mixed up when resolving merge conflicts, but I think it is removed at HEAD. |
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MDEP-XXX] - Fixes bug in ApproximateQuantiles
,where you replace
MDEP-XXX
with the appropriate JIRA issue. Best practiceis to use the JIRA issue title in the pull request title and in the first line of the
commit message.
mvn clean verify
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
mvn -Prun-its clean verify
).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licensed under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.