it.geosolutions.imageio.utilities
Class StringToDouble

Object
  extended by StringToDouble

public final class StringToDouble
extends Object

This class is responsible for converting a sequence of chars into a a double number.

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.

Author:
Daniele Romagnoli, GeoSolutions., Simone Giannecchini, GeoSolutions.

Method Summary
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.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

pushChar

public boolean pushChar(int newChar)
Pushes a new character to this converter.

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.

Parameters:
newChar - to parse.
Returns:
true if there is a value to get, false otherwise.
See Also:
StringToDouble#isEof()}

compute

public double compute()
Returns a value, if any was advertised by the pushChar(int) method.

Returns:

acquire

public static StringToDouble acquire()
Retrieves a poole StringToDouble object.


release

public static void release(StringToDouble c)
Reacquire a pooled StringToDouble.

Parameters:
c -


Copyright © 2006-2010 GeoSolutions. All Rights Reserved.