[Mulgara-svn] r1329 - trunk/src/jar/resolver/java/org/mulgara/resolver
pag at mulgara.org
pag at mulgara.org
Thu Oct 16 19:01:37 UTC 2008
Author: pag
Date: 2008-10-16 12:01:36 -0700 (Thu, 16 Oct 2008)
New Revision: 1329
Modified:
trunk/src/jar/resolver/java/org/mulgara/resolver/OrderByRowComparator.java
Log:
Handling negative numbers. Based on a patch submitted by David Smith
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/OrderByRowComparator.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/OrderByRowComparator.java 2008-10-16 19:00:24 UTC (rev 1328)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/OrderByRowComparator.java 2008-10-16 19:01:36 UTC (rev 1329)
@@ -347,40 +347,24 @@
if (rdfNode instanceof Literal) {
String text = ((Literal) rdfNode).getLexicalForm();
- // Check if the string is a number.
- int len = text.length();
- boolean isNumber = true;
- boolean hasDecimalPoint = false;
+ if (logger.isDebugEnabled()) logger.debug("Checking if " + text + " is a number");
- if (logger.isDebugEnabled()) {
+ if (text.length() > 0) {
+ char ch = text.charAt(0);
- logger.debug("Checking if " + text + " is a number");
- }
-
- // Check if the string is empty
- isNumber = len > 0;
-
- for (int i = 0; i < len; ++i) {
- char ch = text.charAt(i);
- if (ch == '.') {
- if (hasDecimalPoint) {
- // A number can't have two decimal points.
- isNumber = false;
- break;
+ // if it smells like a numeric (and not a DateTime)
+ if (((ch >= '0' && ch <= '9') || ch == '.' || ch == '+' || ch == '-') && text.indexOf('T') < 0) {
+ // The floating parser accepts numbers ending in d or f, but we don't
+ ch = text.charAt(text.length() - 1);
+ if (ch != 'f' && ch != 'F' && ch != 'd' && ch != 'D') {
+ try {
+ // try to return as a number, using autoboxing
+ return Float.parseFloat(text);
+ } catch (NumberFormatException ex) { /* not a number - fall through */ }
}
-
- hasDecimalPoint = true;
- } else if ( (ch < '0') || (ch > '9')) {
- // A char which is not a digit.
- isNumber = false;
- break;
}
}
- if (isNumber) {
- return new Float(text);
- }
-
return text;
} else if (rdfNode instanceof URIReference) {
return ((URIReference) rdfNode).getURI().toString();
More information about the Mulgara-svn
mailing list