Example #1
0
  /**
   * 只有String和Boolean类型进行转换,其他类型均返回false
   *
   * @param columnIdx
   * @return boolean
   * @roseuid 3E5D883200BA
   */
  public boolean getBoolean(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return false;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);

    if (rmd.getType() == MetaDataTypes.STRING_TP) {
      Record record = (Record) records.get(currentNo);
      String value = (String) record.get(columnIdx);
      if (value == null || value.equals("0")) return false;
      return true;
    }
    if (rmd.getType() == MetaDataTypes.BOOLEAN_TP) {
      Record record = (Record) records.get(currentNo);
      Boolean value = (Boolean) record.get(columnIdx);
      return value.booleanValue();
    } else {
      return false;
    }
  }
Example #2
0
  /**
   * @param columnIdx
   * @return double
   * @roseuid 3E5D88C701AE
   */
  public double getDouble(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return 0;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    if (value == null) return 0;

    switch (rmd.getType()) {
      case MetaDataTypes.BIGDECIMAL_TP:
        return ((BigDecimal) value).doubleValue();
      case MetaDataTypes.BIGINTEGER_TP:
        return ((BigInteger) value).doubleValue();
      case MetaDataTypes.BOOLEAN_TP:
        Boolean b = (Boolean) value;
        if (b.booleanValue()) return 1;
        else return 0;
      case MetaDataTypes.DOUBLE_TP:
        return ((Double) value).doubleValue();
      case MetaDataTypes.FLOAT_TP:
        return ((Float) value).doubleValue();
      case MetaDataTypes.INTEGER_TP:
        return ((Integer) value).doubleValue();
      case MetaDataTypes.LONG_TP:
        return ((Long) value).doubleValue();
      case MetaDataTypes.SHORT_TP:
        return ((Short) value).doubleValue();
      case MetaDataTypes.STRING_TP:
        try {
          return Double.parseDouble((String) value);
        } catch (Exception e) {
          return 0;
        }
      default:
        return 0;
    } // switch
  }