Skip to content

SPR-9164 - Added BigDecimal capabilities to SpEl numeric operators #80

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

Closed
wants to merge 1 commit into from
Closed

Conversation

giovannidalloglio
Copy link
Contributor

Clean version of old pull request #54

This should cover part of SPR-9164

[added BigDecimal support to SpEl numerics calculations.]

PS: I have signed and agree to the terms of the SpringSource Individual Contributor License Agreement.

@cbeams
Copy link
Contributor

cbeams commented May 15, 2012

In addition to the contributor guidelines, you might find it helpful, Giovanni, to simply browse through the commit log to see how other commits look. You can easily do this with git log, and particularly with git log --author=cbeams

@giovannidalloglio
Copy link
Contributor Author

I amended my work, rebasing on current Spring's master.

I hope that this'll be the right time.

@cbeams: you commented my choice:

performance: the if block for Double should come first, then the else if for BigDecimal. The former is more likely to be used than the latter, meaning that this arrangement will result in fewer cycles being used up.

This is a choice: to not risk the calculation error due to the double approximation (is this the same error that this issue want to fix?). Using the BigDecimal as first choice, we get away from this risk.

Do you agree?

@obecker
Copy link
Contributor

obecker commented Jul 1, 2012

@cbeams @giovannidalloglio regarding test for Double first or test for BigDecimal first:

If one operand is Double and the other is BigDecimal, then the operation should treat both as BigDecimal. So the test for BigDecimal first is correct.

@ghost ghost assigned cbeams Jul 2, 2012

evaluate("3 le 5", true, Boolean.class);
evaluate("5 le 3", false, Boolean.class);
evaluate("3 le 5", true, Boolean.class);
evaluate("5 le 3", false, Boolean.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

These new two lines are just a duplicate of the two lines preceding them??

@aclement
Copy link
Contributor

Apart from the duplicate tests this looks ok to me. Two further comments:

  1. The StandardTypeComparator could also be changed to include the BigDecimal case, for consistency, although i'm not sure how much that class gets exercised in practice.

  2. One point on style is that I think the spring way is to have your if statements like this:

if (foo) {
}
else if (op1 instanceof Float || op2 instanceof Float) {

rather than

if (foo) {
} else if (op1 instanceof Float || op2 instanceof Float) {

and this PR uses the latter.

Issue: SPR-9164

Prior to this change, SpEL supported numeric operations for int, float, ...
'new java.math.BigDecimal('0.1') > 0' evaluates to false
(BigDecimal is truncated to int)

This commit introduces support for BigDecimal operations
'new java.math.BigDecimal('0.1') > 0' evaluates to true
(the comparison is made with bigDecimals)

In the meantime (from the pull request to now), SpEL advanced [operator++, between].
Now is everything covered, updated and fixed.

In addition, some polish (like Phil Webb commit e83bdda)
philwebb pushed a commit that referenced this pull request Nov 21, 2013
* SPR-9164:
  Add BigDecimal support for SpEl numeric operations
@philwebb
Copy link
Member

Great pull request! This has now been merged into master with a few minor tweaks.

Thanks!

@philwebb philwebb closed this Nov 21, 2013
rwinch pushed a commit to rwinch/spring-framework that referenced this pull request Jun 20, 2016
This commit makes messageEncoders a required argument for building a
client request - those are needed to actually encode the body object as
a reactive stream to be written to the HTTP request body.

Removed raw types usage in DefaultHttpRequestBuilder.

DefaultHttpRequestBuilder now uses a UriTemplateHandler to expand URI
templates + variables into a concrete URI.

Fixes spring-projects#80, fixes spring-projects#85, fixes spring-projects#86
rwinch pushed a commit to rwinch/spring-framework that referenced this pull request Jul 13, 2016
This commit makes messageEncoders a required argument for building a
client request - those are needed to actually encode the body object as
a reactive stream to be written to the HTTP request body.

Removed raw types usage in DefaultHttpRequestBuilder.

DefaultHttpRequestBuilder now uses a UriTemplateHandler to expand URI
templates + variables into a concrete URI.

Fixes spring-projects#80, fixes spring-projects#85, fixes spring-projects#86
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.

5 participants