Justin Deoliveira ha scritto:
> Hi all,
>
> I have a few issues with this patch which is supposed to address
> performance with filters.
>
> 1) It causes floating point strings to be truncated to an integer. The
> following simple test case illustrates:
>
> Literal l = ff.literal("0.1");
> Object o = l.evaluate(null);
> assertEquals( "0.1", o.toString() );
I reworked that code again to avoid converters but limiting the
number of exceptions that are thrown and catched to at most two:
1) one exception is thrown and catched if the string is not a
number
2) at most another is thrown if the number is integral, but too
big for a Long to hold
I also added unit tests to make sure 0.1 is not cut to an
integer, but handled as a double instead.
For reference, here is the replacement code (again, not a patch
since it's not the original code, which was slow, nor the
current one, which was incorrect):
// check if it's a number
try {
BigDecimal bd = new BigDecimal(s);
// check if it has a decimal part
if(bd.scale() > 0) {
double d = bd.doubleValue();
// if too big for double, it will become infinite
if(!Double.isInfinite(d))
parsedValue = d;
else
parsedValue = bd;
} else {
// it's integral, see if we can convert it to a long or int
try {
long l = bd.longValueExact();
// if this test passes, it's actually an int
if((int) l == l)
parsedValue = new Integer((int) l);
else
parsedValue = new Long(l);
} catch(Exception e) {
// was too big for a long
parsedValue = bd.toBigIntegerExact();
}
}
} catch(Exception e) {
// ok, it's not a number, let's keep it as it is
parsedValue = literal;
}
I've done a gt2 build and run the cite wfs 1.1+xlink tests,
and it works fine. So I'm commiting it ;)
If you can spot any bug in it, please let me know.
Cheers
Andrea
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel