Author: desruisseaux
Date: Fri Mar 8 21:26:56 2013
New Revision: 1454581
URL: http://svn.apache.org/r1454581
Log:
Minor change of policy: do not automatically remove whitespaces in Numbers
static method;
leave the responsibility to the caller. For such low-level function, it may be
preferable
to avoid taking too much initiative.
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java?rev=1454581&r1=1454580&r2=1454581&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/DefaultFormat.java
[UTF-8] Fri Mar 8 21:26:56 2013
@@ -22,6 +22,7 @@ import java.text.ParsePosition;
import java.text.ParseException;
import net.jcip.annotations.ThreadSafe;
import org.apache.sis.util.Numbers;
+import org.apache.sis.util.CharSequences;
import org.apache.sis.internal.util.LocalizedParseException;
@@ -104,7 +105,8 @@ final class DefaultFormat extends Format
* Parses the given string as a number of the type given at construction
time.
*/
@Override
- public Object parseObject(final String source) throws ParseException {
+ public Object parseObject(String source) throws ParseException {
+ source = CharSequences.trimWhitespaces(source);
try {
return valueOf(source);
} catch (NumberFormatException cause) {
@@ -119,8 +121,9 @@ final class DefaultFormat extends Format
*/
@Override
public Object parseObject(String source, final ParsePosition pos) {
- final int index = pos.getIndex();
- source = source.substring(index);
+ final int length = source.length();
+ final int index = CharSequences.skipLeadingWhitespaces(source,
pos.getIndex(), length);
+ source = source.substring(index,
CharSequences.skipTrailingWhitespaces(source, index, length));
try {
return valueOf(source);
} catch (NumberFormatException cause) {
Modified:
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Numbers.java?rev=1454581&r1=1454580&r2=1454581&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
[UTF-8] (original)
+++
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Numbers.java
[UTF-8] Fri Mar 8 21:26:56 2013
@@ -502,8 +502,9 @@ public final class Numbers extends Stati
* @see #narrowestNumber(double)
* @see #narrowestNumber(long)
*/
- public static Number narrowestNumber(String value) throws
NumberFormatException {
- value = CharSequences.trimWhitespaces(value);
+ public static Number narrowestNumber(final String value) throws
NumberFormatException {
+ // Do not trim whitespaces. It is up to the caller to do that if he
wants.
+ // For such low level function, we are better to avoid hidden
initiative.
final int length = value.length();
for (int i=0; i<length; i++) {
final char c = value.charAt(i);
@@ -621,7 +622,7 @@ public final class Numbers extends Stati
* string value is not parseable as a number of the specified type.
*/
@SuppressWarnings("unchecked")
- public static <T> T valueOf(String value, final Class<T> type)
+ public static <T> T valueOf(final String value, final Class<T> type)
throws IllegalArgumentException, NumberFormatException
{
if (value == null || type == String.class) {
@@ -637,7 +638,8 @@ public final class Numbers extends Stati
*/
return (T) Character.valueOf(value.isEmpty() ? 0 :
value.charAt(0));
}
- value = CharSequences.trimWhitespaces(value);
+ // Do not trim whitespaces. It is up to the caller to do that if he
wants.
+ // For such low level function, we are better to avoid hidden
initiative.
if (type == Double .class) return (T) Double .valueOf(value);
if (type == Float .class) return (T) Float .valueOf(value);
if (type == Long .class) return (T) Long .valueOf(value);