« Response: Rickard's AOP thoughts | Main | Inform.Ant: Wizard first design steps »

Many ways to skin a cat

Ok, how does one determine the size of a text field from the maxInclusive="12345" field of a XML Schema xsd:element? Does one do this (packed into one statement or many as tastes dictate)...

String maxInclusive = element.getAttribute("maxInclusive");
double d = Double.parseDouble(maxInclusive);
d = Math.log(d + .9); // for the case of 100, we need 3 not 2
d /= Math.log(10);
d = Math.ceil(d);
return (int)d;

That's what I intially did. Too much time spent in math classes in high scool and college I guess. That blinded me to the more elegant solution... return element.getAttribute("maxInclusive").length(). And I even spent time looking online to verify that log10(x) is ln(x)/ln(10) after the guy with a degree in statistics couldn't remember for certian!


This page contains a single entry from the blog posted on October 17, 2002 11:13 AM.

The previous post in this blog was Response: Rickard's AOP thoughts.

The next post in this blog is Inform.Ant: Wizard first design steps.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33