public final class StringToDouble extends Object
It is a utility class uses by the AsciiGridRaster
class for
converting the input String
into numbers. This class is highly
optimized for performances reasons.
This class is not thread safe!!!
Usage
final StringToDouble converter = new StringToDouble(); // If I need to load 10 samples, I need to count 9 spaces while (...) { // ///////////////////////////////////////////////////////////////// // // Read the char // // ///////////////////////////////////////////////////////////////// ch = read(); // ///////////////////////////////////////////////////////////////// // // Push the char into the converter // // ///////////////////////////////////////////////////////////////// if (converter.pushChar(ch)) { // ///////////////////////////////////////////////////////////////// // // Get the new value // // ///////////////////////////////////////////////////////////////// value = converter.getValue(); // ///////////////////////////////////////////////////////////////// // // Consume the new value // // ///////////////////////////////////////////////////////////////// ... ... ... } else { // ///////////////////////////////////////////////////////////////// // // Let's check the EOF. // // ///////////////////////////////////////////////////////////////// if (converter.isEof()) { ... ... ... } } }
It is worth to point out that when using this class it would be great to add
to the JVM the hint to augment the lifetime of SoftReference
objects
since the underlying pool is based on them.
Modifier and Type | Method and Description |
---|---|
static StringToDouble |
acquire()
Retrieves a poole
StringToDouble object. |
double |
compute()
Returns a value, if any was advertised by the
pushChar(int) method. |
boolean |
pushChar(int newChar)
Pushes a new character to this converter.
|
static void |
release(StringToDouble c)
Reacquire a pooled
StringToDouble . |
public boolean pushChar(int newChar)
The converter parses the char and check if we have a new value. The value is not computed unless requested for performance reasons. Often it is needed to throw away values that are not needed because of subsampling or the like, hence it is a waste of resource explicitly computing them.
It is worth to point out that after getting a false value it is crucial
to check the isEof()
to see if we reached to eof
condition.
newChar
- to parse.StringToDouble#isEof()}
public double compute()
pushChar(int)
method.public static StringToDouble acquire()
StringToDouble
object.public static void release(StringToDouble c)
StringToDouble
.c
- Copyright © 2006–2014 GeoSolutions. All rights reserved.