getFieldClass method

Type getFieldClass(
  1. int i
)

Determine the most appropriate Java Class for representing the data in the field.

All packages are java.lang unless otherwise specified.
C (Character) -> String
N (Numeric)   -> Integer or Long or Double (depends on field's decimal count and fieldLength)
F (Floating)  -> Double
L (Logical)   -> Boolean
D (Date)      -> java.util.Date (Without time)
@ (Timestamp) -> java.sql.Timestamp (With time)
Unknown       -> String

@param i The index of the field, from 0 to getNumFields() - 1 . @return A Class which closely represents the dbase field type.

Implementation

Type getFieldClass(int i) {
  Type typeClass;

  var fieldType = fields[i].fieldType;
  var code = String.fromCharCode(fieldType);
  switch (code) {
    case 'C':
      typeClass = String;
      break;

    case 'N':
      if (fields[i].decimalCount == 0) {
        if (fields[i].fieldLength < 10) {
          typeClass = int;
        } else {
          typeClass = int;
        }
      } else {
        typeClass = double;
      }
      break;

    case 'F':
      typeClass = double;
      break;

    case 'L':
      typeClass = bool;
      break;

    case 'D':
      typeClass = DateTime;
      break;

    case '@':
      typeClass = DateTime;
      break;

    default:
      typeClass = String;
      break;
  }

  return typeClass;
}