Skip to content

style: use stream#3501

Open
shenshaoming wants to merge 2 commits into
iluwatar:masterfrom
shenshaoming:master
Open

style: use stream#3501
shenshaoming wants to merge 2 commits into
iluwatar:masterfrom
shenshaoming:master

Conversation

@shenshaoming
Copy link
Copy Markdown

Pull Request Template

What does this PR do?

refactor: Optimize collection operations using Java Stream API

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

PR Summary

Refactored collection-processing methods to use Java Streams for cleaner, more concise code. Replaced manual loops with stream-based implementations: getModelsAfter2000 filters, sorts by year, and maps to models; getGroupingOfCarsByCategory uses Collectors.groupingBy; getSedanCarsOwnedSortedByDate flattens owners' cars, filters for SEDAN, and sorts by year. Updated imports accordingly.

Changes

File Summary
collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/ImperativeProgramming.java Converted imperative operations to Java Streams in ImperativeProgramming: getModelsAfter2000 now filters, sorts by year, maps to model using streams; getGroupingOfCarsByCategory replaced manual map building with Collectors.groupingBy; getSedanCarsOwnedSortedByDate flattens owner lists, filters for SEDAN, and sorts by year. Imports updated (added Collectors; removed unused ArrayList/HashMap) to align with stream usage.

autogenerated by presubmit.ai

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
Files Processed (1)
  • collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/ImperativeProgramming.java (4 hunks)
Actionable Comments (0)
Skipped Comments (3)
  • collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/ImperativeProgramming.java [59-64]

    readability: "Use streams for model extraction after 2000"

  • collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/ImperativeProgramming.java [73-73]

    enhancement: "Use Collectors.groupingBy for grouping by category"

  • collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/ImperativeProgramming.java [84-90]

    enhancement: "Compute sedan cars owned by date using a stream"

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
  • 58610c8: style: More standardized after modification.
Files Processed (1)
  • collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/ImperativeProgramming.java (4 hunks)
Actionable Comments (1)
  • collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/ImperativeProgramming.java [59-64]

    possible bug: "Use correct integer-based comparator for year when sorting models after 2000"

Skipped Comments (1)
  • collection-pipeline/src/main/java/com/iluwatar/collectionpipeline/ImperativeProgramming.java [81-91]

    compatibility: "Potential incompatibility with Stream.toList() across Java versions"

Comment on lines +59 to 64
return cars.stream()
.filter(car -> car.year() > 2000)
.sorted(Comparator.comparing(Car::year))
.map(Car::model)
.toList();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting by year using Comparator.comparing with an integer year may not compile if Car.year() returns a primitive int. Use Comparator.comparingInt(Car::year) to avoid primitive boxing and ensure correct compilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant