DataFile 1.4

com.infomata.data
Class DataRow

java.lang.Object
  extended bycom.infomata.data.DataRow

public class DataRow
extends java.lang.Object

Object representing collection of data items contained within one line of the data file

Version:
$Revision: 1.2 $
Author:
Sam Kim

Constructor Summary
DataRow()
          Creates a new DataRow instance.
DataRow(java.text.NumberFormat format)
          Creates a new DataRow instance.
 
Method Summary
 void add(double datum)
          Adds a double datum to the next location.
 void add(int datum)
          Adds an int datum to the next location.
 void add(long datum)
          Adds a long datum to the next location.
 void add(java.lang.Object obj)
          Adds an object with toString() method defined to the next item.
 void add(java.lang.String datum)
          Adds a String datum to the next location
 void addEmpty()
          Adds an empty item (spacer)
 void clear()
          Remove the content of DataRow.
 java.util.Date getDate(int location, java.lang.String pattern)
          Retrieves the date using the specified pattern to parse the date.
 java.util.Date getDate(java.lang.String label, java.lang.String pattern)
          Retrieves the date corresponding to the specified column label.
 double getDouble(int location)
          Retrieves the double value of the datum contained in the specified location.
 double getDouble(int location, java.text.DecimalFormat format, double defaultVal)
          Retrieves the double value at specified location parsed using format.
 double getDouble(int location, double defaultVal)
          Retrieves the double value of the datum contained in the specified location.
 double getDouble(java.lang.String label)
          Retrieve the double value contained in data cell corresponding to the specified column label
 double getDouble(java.lang.String label, double defaultVal)
          Retrieve the double value contained in data cell corresponding to the specified column label.
 int getInt(int location)
          Retrieves the int value of the datum contained in the specified location.
 int getInt(int location, java.text.DecimalFormat format, int defaultVal)
          Retrieves the int value at specified location parsed using format.
 int getInt(int location, int defaultVal)
          Retrieves the int value of the datum contained in the specified location.
 int getInt(java.lang.String label)
          Retrieves the int value of the datum contained under specified column label.
 int getInt(java.lang.String label, int defaultVal)
          Retrieves the int value under the specified column label.
 java.sql.Date getSqlDate(int location, java.lang.String pattern)
          Retrieve the date value at the specified location in specified pattern as an instance of java.sql.Date instead of java.util.Date.
 java.lang.String getString(int location)
          Retrieves the String value contained in the specified location.
 java.lang.String getString(int location, java.lang.String defaultVal)
          Retrieves the String value contained in the specified location or defaultVal if it does not.
 java.lang.String getString(java.lang.String label)
          Retrieves the String value located under specified column label.
 java.lang.String getString(java.lang.String label, java.lang.String defaultVal)
          Retrieves the String value contained under the specified column label.
 java.util.Iterator iterator()
          Retrieves an iterator for items
 int size()
          Retrieves the number of location in row.
 java.lang.String toString()
          For debugging purpose.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DataRow

public DataRow()
Creates a new DataRow instance. Uses JVM's locale for formatting numbers.


DataRow

public DataRow(java.text.NumberFormat format)
Creates a new DataRow instance. Uses specified NumberFormat object to read or write numbers.

Parameters:
format - a NumberFormat object
Method Detail

add

public void add(java.lang.String datum)
Adds a String datum to the next location

Parameters:
datum - String datum item

add

public void add(int datum)
Adds an int datum to the next location.

Parameters:
datum - int datum item

add

public void add(long datum)
Adds a long datum to the next location.

Parameters:
datum - a long value

add

public void add(double datum)
Adds a double datum to the next location.

Parameters:
datum - a double value

add

public void add(java.lang.Object obj)
Adds an object with toString() method defined to the next item.

Parameters:
obj - an Object with toString() defined.

addEmpty

public void addEmpty()
Adds an empty item (spacer)


iterator

public java.util.Iterator iterator()
Retrieves an iterator for items

Returns:
an Iterator

getDate

public java.util.Date getDate(int location,
                              java.lang.String pattern)
Retrieves the date using the specified pattern to parse the date. See java.text.SimpleDateFormat documentation valid date format patterns.

Parameters:
location - locationg of the item
pattern - date format pattern (i.e. "yyyy.MM.dd" for 2002.10.20")
Returns:
Date contained in specified location. If parsing fails using the specified pattern, returns NULL.

getSqlDate

public java.sql.Date getSqlDate(int location,
                                java.lang.String pattern)
Retrieve the date value at the specified location in specified pattern as an instance of java.sql.Date instead of java.util.Date.

Parameters:
location - location of date value
pattern - format of the date value in the data file
Returns:
java.sql.Date instance representing the date at location.

getDate

public java.util.Date getDate(java.lang.String label,
                              java.lang.String pattern)
Retrieves the date corresponding to the specified column label.

Parameters:
label - column label
pattern - see SimpleDateFormat for further description on pattern syntax.
Returns:
Date value under specified column label.

getDouble

public double getDouble(int location)
                 throws java.lang.NumberFormatException
Retrieves the double value of the datum contained in the specified location.

Parameters:
location - location of the item
Returns:
a double value
Throws:
java.lang.NumberFormatException - if the item cannot be parsed using normal number parser.

getDouble

public double getDouble(java.lang.String label)
                 throws java.lang.NumberFormatException
Retrieve the double value contained in data cell corresponding to the specified column label

Parameters:
label - column label
Returns:
a double value
Throws:
java.lang.NumberFormatException - if the value cannot be parsed correctly.

getDouble

public double getDouble(int location,
                        double defaultVal)
Retrieves the double value of the datum contained in the specified location. If the specified location does not contain a double value or empty, default value is returned.

Parameters:
location - location of the item.
defaultVal - default value to use when value does not exist or fails to parse correctly.
Returns:
a double value

getDouble

public double getDouble(int location,
                        java.text.DecimalFormat format,
                        double defaultVal)
Retrieves the double value at specified location parsed using format. If the value does not exist or fails to parse into double, defaultVal is returned.

Parameters:
location - location of double value
format - double value parser to be used in extracting item.
defaultVal - default value to use in case of missing data or parse error.
Returns:
a double value at specified location or defaultVal

getDouble

public double getDouble(java.lang.String label,
                        double defaultVal)
Retrieve the double value contained in data cell corresponding to the specified column label.

Parameters:
label - column label
defaultVal - default value to use when value does not exist or does not parse correctly.
Returns:
double value corresponding to the specified column label. If the specified column label does not exist or the value cannot parsed into a double, defaultValu.

getInt

public int getInt(int location)
           throws java.lang.NumberFormatException
Retrieves the int value of the datum contained in the specified location.

Parameters:
location - location of the item.
Returns:
an int at the specified location.
Throws:
java.lang.NumberFormatException - if the value at specified location cannot parsed into an int

getInt

public int getInt(java.lang.String label)
           throws java.lang.NumberFormatException
Retrieves the int value of the datum contained under specified column label.

Parameters:
label - column label
Returns:
a int value
Throws:
java.lang.NumberFormatException - if specified column label does not exist or the value cannot parsed into an int

getInt

public int getInt(int location,
                  int defaultVal)
Retrieves the int value of the datum contained in the specified location. If the specified location does not contain a int value or empty, default value is returned.

Parameters:
location - location of the item.
defaultVal - default value to use when value does not exist.
Returns:
a int value

getInt

public int getInt(int location,
                  java.text.DecimalFormat format,
                  int defaultVal)
Retrieves the int value at specified location parsed using format. If the value does not exist or fails to parse into int, defaultVal is returned.

Parameters:
location - location of int value
format - int value parser to be used in extracting item.
defaultVal - default value to use in case of missing data or parse error.
Returns:
an int value at specified location or the defaultVal

getInt

public int getInt(java.lang.String label,
                  int defaultVal)
Retrieves the int value under the specified column label.

Parameters:
label - column label (header)
defaultVal - default value to use when value does not exist.
Returns:
int value corresponding to the specified column label. If the specified column label does not exist or cannot be convert into an int default value is returned.

getString

public java.lang.String getString(int location)
Retrieves the String value contained in the specified location.

Parameters:
location - an int value
Returns:
a String value or emty String if specified location does not exist. (never returns null)

getString

public java.lang.String getString(java.lang.String label)
Retrieves the String value located under specified column label.

Parameters:
label - column label
Returns:
a String value corresponding to specified column label. If the column does not exist, empty String is returned.

getString

public java.lang.String getString(int location,
                                  java.lang.String defaultVal)
Retrieves the String value contained in the specified location or defaultVal if it does not.

Parameters:
location - location of the item (starts at zero)
defaultVal - default value to use when the does not contain a value.
Returns:
a String value at specified location. If the value does not exist, defaultVal is returned.

getString

public java.lang.String getString(java.lang.String label,
                                  java.lang.String defaultVal)
Retrieves the String value contained under the specified column label.

Parameters:
label - column label
defaultVal - default value to return when value does not exist or label fails to match any of the column names in header row.
Returns:
a String value corresponding to specified column label. If no such column exists or the value is empty, devaultVal is returned.

size

public int size()
Retrieves the number of location in row.

Returns:
number of items contined in DataRow

toString

public java.lang.String toString()
For debugging purpose. Converts the row of data into String

Returns:
String representation of data row.

clear

public void clear()
Remove the content of DataRow.


DataFile 1.4

Copyright © 2004 Infomata. All Rights Reserved.