Skip to content

Fix progress calculation using proper Integer unboxing method#44713

Closed
KmYgJn wants to merge 10 commits intospring-projects:mainfrom
KmYgJn:optimize-progress-calculation
Closed

Fix progress calculation using proper Integer unboxing method#44713
KmYgJn wants to merge 10 commits intospring-projects:mainfrom
KmYgJn:optimize-progress-calculation

Conversation

@KmYgJn
Copy link
Contributor

@KmYgJn KmYgJn commented Mar 14, 2025

Description

This PR fixes the Integer conversion in the getProgress() method by replacing Integer::valueOf with Integer::intValue. The original code incorrectly used valueOf which is meant for converting other types to Integer objects, while intValue() is the correct method for unboxing Integer objects to primitive int values.

Changes

  • Modified getProgress() method in the progress calculation logic
  • Replaced Integer::valueOf with Integer::intValue for proper unboxing
  • Improved semantic clarity of the code without affecting functionality

Reasoning

progressByStatus.values() returns a collection of Integer objects. When processing these values with mapToInt(), we need to extract the primitive int value from each Integer object. The valueOf() method is meant for creating Integer objects from other types (like String), while intValue() is designed for extracting the primitive value from an Integer object.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 14, 2025

int getProgress() {
return withinPercentageBounds((this.progressByStatus.values().stream().mapToInt(Integer::valueOf).sum())
return withinPercentageBounds((this.progressByStatus.values().stream().mapToInt(Integer::intValue).sum())
Copy link
Contributor

Choose a reason for hiding this comment

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

In that case .reduce(0, Integer::sum) can be used instead of mapToInt(..).sum()

Copy link
Contributor

Choose a reason for hiding this comment

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

I think .mapToInt(...).sum() makes it easier to understand.

@mhalbritter
Copy link
Contributor

Hello @KmYgJn, please sign your commit, so that the DCO check passes. See this blog post for more details. Thanks!

@mhalbritter mhalbritter added the status: waiting-for-feedback We need additional information before we can continue label Mar 14, 2025
mhalbritter and others added 10 commits March 14, 2025 23:46
See spring-projectsgh-44033

Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
This reverts commit d98dd7b.

Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
This reverts commit 105dfb8.

Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
This reverts commit dad936d.

Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
Signed-off-by: youngjin_dev <qazkyj0310@gmail.com>
@KmYgJn KmYgJn force-pushed the optimize-progress-calculation branch from 79dd1e0 to 179c5da Compare March 14, 2025 14:51
@KmYgJn KmYgJn closed this Mar 14, 2025
@KmYgJn KmYgJn reopened this Mar 14, 2025
@KmYgJn
Copy link
Contributor Author

KmYgJn commented Mar 14, 2025

Close the PR to get a clean PR again

@KmYgJn KmYgJn closed this Mar 14, 2025
@bclozel bclozel added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Mar 14, 2025
@KmYgJn KmYgJn deleted the optimize-progress-calculation branch March 14, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: invalid An issue that we don't feel is valid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants