### Round and Round we go; Netbeans WTF

I found the following code in a recent snapshot of netbeans. If anyone has a clue as to what the developer was thinking, let me know. The code is in org.openide.awt.HtmlLabelUI:

private static int textWidth(String text, Graphics g, Font f, boolean html) {

if (text != null) {

if (html) {

return Math.round(

Math.round(

Math.ceil(

HtmlRenderer.renderHTML(

text, g, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, f, Color.BLACK,

HtmlRenderer.STYLE_CLIP, false

)

)

)

);

} else {

return Math.round(

Math.round(

Math.ceil(

HtmlRenderer.renderPlainString(

text, g, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, f, Color.BLACK,

HtmlRenderer.STYLE_CLIP, false

)

)

)

);

}

} else {

return 0;

}

}

Labels: WTF

## 6 Comments:

Franky speaking I do not understand it from the very beginning: I have found the method in google:

public static double

renderPlainStringRender a string to a graphics instance, using the same API as renderHTML...

Returns the width in pixels successfully painted.Why the successful pixels amount is a double?

Maybe the programmer is just a huge fan of Math.round() ^^

I can imagine how this one developed, he just used

Math.ceil()first, but then:possible loss of precisionfound : double

required: int

ok, so he was looking for a method to convert it to int, he had the javadoc for the class Math still open (he just looked up

Math.ceil()) and found the methodstatic long round(double a)"That's gonna work - long is also an integer right?"

Math.round(Math.ceil())of course...

possible loss of precisionfound : long

required: int

it didn't. But there is another

round()method:static int round(float a)And being the clever programmer he obviously is ^^, he knew Java would convert his

longtofloat. So, using round a second time, the result would now beint!"Hooray!"

I just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.

Branding Services in Chennai

Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

Personal Installment Loans

Title Car loan

Cash Advance Loan

Really something Grate in this article Thanks for sharing this. We are providing Online Training Classes. After reading this slightly I am changed my way of introduction about my training to people.

Best Linux training in Noida

Linux Training Institute in Noida

Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me.

Best bca college in noida

Top bca colleges in noida

Post a Comment

<< Home