• Post Reply Bookmark Topic Watch Topic
  • New Topic

Looking for an optimization  RSS feed

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using Java 1.5 and running the PMD code checker on my code. I have this code ...



I'm getting a warning on the line, "BigDecimal allocation = BigDecimal.ZERO;" (Found 'DD' anomaly for variable 'allocation', lines 417-426) because I reassign the variable on the line, "allocation = allocation.add(payment.getPaymentAmt());". However, with BigDecimals, I don't know how to add on to what I already have other than how I'm doing it. Does anyone have an optimization that can satisfy my code checker?

Thanks, - Dave
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is perfectly good. Anything you do to it to satisfy the code checker can't be described as an "optimization". What's the opposite of "optimization"? That's what it would be.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Paul. There's nothing wrong with this code. BigDecimals are immutable, so you can not add to one without reassignment. I think your warning system is going overboard here. A quick search shows that it's listed as a PMD "controversial" rule, so I think you're safe to ignore it.

Using a while loop instead of a new Java "for each" loop ... well that may be more warn-worthy.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd give the same advice I gave last time you asked a question about a DD anomaly. They're not always wrong, or bad. Turn it off with a comment, or disable that check altogether.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!