[GitHub] [maven-dependency-plugin] gnodet commented on a diff in pull request #255: [MDEP-832] - Remove commons-collections-4
gnodet commented on code in PR #255: URL: https://github.com/apache/maven-dependency-plugin/pull/255#discussion_r1002059135 ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: The shortest form could be: ``` private Set findDuplicateDependencies( List modelDependencies ) { List 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 ); } ``` ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: The shortest form could be: ``` private Set findDuplicateDependencies( List modelDependencies ) { List 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 ); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [maven-dependency-plugin] gnodet commented on a diff in pull request #255: [MDEP-832] - Remove commons-collections-4
gnodet commented on code in PR #255: URL: https://github.com/apache/maven-dependency-plugin/pull/255#discussion_r1002052466 ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: It could even be inlined with a simple comment... -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [maven-dependency-plugin] gnodet commented on a diff in pull request #255: [MDEP-832] - Remove commons-collections-4
gnodet commented on code in PR #255: URL: https://github.com/apache/maven-dependency-plugin/pull/255#discussion_r1001931149 ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: 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 List symmetricDifference( Collection elements ) { List list = new ArrayList<>( elements ); Set set = new HashSet<>( elements ); list.removeIf( set::remove ); return list; } ``` It passes the slightly adapted tests in the `UtilTest` (the two last ones). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [maven-dependency-plugin] gnodet commented on a diff in pull request #255: [MDEP-832] - Remove commons-collections-4
gnodet commented on code in PR #255: URL: https://github.com/apache/maven-dependency-plugin/pull/255#discussion_r1001931149 ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: Ah, got it. But then, wouldn't it be simpler and more understandable : ``` /** * Remove exactly one instance of each element from the give list. */ static List symmetricDifference( Collection elements ) { List list = new ArrayList<>( elements ); Set set = new HashSet<>( elements ); list.removeIf( set::remove ); return list; } ``` It passes the slightly adapted tests in the `UtilTest` (the two last ones). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [maven-dependency-plugin] gnodet commented on a diff in pull request #255: [MDEP-832] - Remove commons-collections-4
gnodet commented on code in PR #255: URL: https://github.com/apache/maven-dependency-plugin/pull/255#discussion_r1001931149 ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: Ah, got it. But then, wouldn't it be simpler and more understandable : ``` /** * Remove exactly one instance of each element from the give list. */ static List symmetricDifference( Collection elements ) { List list = new ArrayList<>( elements ); Set set = new HashSet<>( elements ); list.removeIf( set::remove ); return list; } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [maven-dependency-plugin] gnodet commented on a diff in pull request #255: [MDEP-832] - Remove commons-collections-4
gnodet commented on code in PR #255: URL: https://github.com/apache/maven-dependency-plugin/pull/255#discussion_r1001874458 ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [maven-dependency-plugin] gnodet commented on a diff in pull request #255: [MDEP-832] - Remove commons-collections-4
gnodet commented on code in PR #255: URL: https://github.com/apache/maven-dependency-plugin/pull/255#discussion_r1001874458 ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [maven-dependency-plugin] gnodet commented on a diff in pull request #255: [MDEP-832] - Remove commons-collections-4
gnodet commented on code in PR #255: URL: https://github.com/apache/maven-dependency-plugin/pull/255#discussion_r1001874458 ## src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDuplicateMojo.java: ## @@ -151,15 +150,9 @@ private void createMessage( Set duplicateDependencies, StringBuilder sb, private Set findDuplicateDependencies( List modelDependencies ) { -List modelDependencies2 = new ArrayList<>(); -for ( Dependency dep : modelDependencies ) -{ -modelDependencies2.add( dep.getManagementKey() ); -} - -// @formatter:off +List modelDependencies2 = +modelDependencies.stream().map( Dependency::getManagementKey ).collect( Collectors.toList() ); return new LinkedHashSet<>( -CollectionUtils.disjunction( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); -// @formatter:on +Util.symmetricDifference( modelDependencies2, new LinkedHashSet<>( modelDependencies2 ) ) ); Review Comment: I struggled on that one. 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org