コード例 #1
0
ファイル: SimplePrintUtil.java プロジェクト: netcrest/pado
  private static void computeMaxLengths(List list, StructType structType, Struct struct) {
    ObjectType[] fieldTypes = structType.getFieldTypes();
    String[] fieldNames = structType.getFieldNames();
    Object[] fieldValues = struct.getFieldValues();

    int listIndex = 0;
    for (int i = 0; i < fieldTypes.length; i++) {
      ObjectType fieldType = fieldTypes[i];
      String fieldName = fieldNames[i];
      Object fieldValue = fieldValues[i];

      Integer len;
      if (listIndex >= list.size()) {
        len = fieldName.length();
        list.add(len);
      } else {
        len = (Integer) list.get(listIndex);
      }
      if (fieldValue == null) {
        if (len.intValue() < 4) {
          len = 4;
        }
      } else {
        int valueLen = fieldValue.toString().length();
        if (len.intValue() < valueLen) {
          len = valueLen;
        }
      }
      list.set(listIndex, len);
      listIndex++;
    }
  }
コード例 #2
0
ファイル: SimplePrintUtil.java プロジェクト: netcrest/pado
  private static void printStruct(int row, Struct struct, int level) {
    String spaces = getSpaces(level);
    String spaces2 = getSpaces(level + 1);

    StructType structType = struct.getStructType();
    ObjectType[] fieldTypes = structType.getFieldTypes();
    String[] fieldNames = structType.getFieldNames();
    Object[] fieldValues = struct.getFieldValues();

    int listIndex = 0;
    PadoShell.println(spaces + row + ".");
    for (int i = 0; i < fieldTypes.length; i++) {
      ObjectType fieldType = fieldTypes[i];
      String fieldName = fieldNames[i];
      Object fieldValue = fieldValues[i];
      printObject(fieldName, fieldValue, level + 1);
    }
  }
コード例 #3
0
ファイル: SimplePrintUtil.java プロジェクト: netcrest/pado
  private static void printHeaders(List list, StructType structType, Struct struct, int rowMaxLen) {
    StringBuffer printStr = new StringBuffer();
    printStr.append(StringUtil.getRightPaddedString("Row", rowMaxLen, ' '));
    printStr.append("  ");

    ObjectType[] fieldTypes = structType.getFieldTypes();
    String[] fieldNames = structType.getFieldNames();
    Object[] fieldValues = struct.getFieldValues();

    int listIndex = 0;
    for (int i = 0; i < fieldTypes.length; i++) {
      ObjectType fieldType = fieldTypes[i];
      String fieldName = fieldNames[i];
      Object fieldValue = fieldValues[i];
      fieldValue = getPrintableValue(fieldValue);
      int maxLen = (Integer) list.get(listIndex);
      String header = fieldName;
      printStr.append(StringUtil.getRightPaddedString(header, maxLen, ' '));
      printStr.append("  ");
      listIndex++;
    }
    PadoShell.println(printStr.toString());

    printStr = new StringBuffer();
    printStr.append(StringUtil.getRightPaddedString("", rowMaxLen, '-'));
    printStr.append("  ");
    listIndex = 0;
    for (int i = 0; i < fieldTypes.length; i++) {
      ObjectType fieldType = fieldTypes[i];
      String fieldName = fieldNames[i];
      Object fieldValue = fieldValues[i];
      fieldValue = getPrintableValue(fieldValue);
      int maxLen = (Integer) list.get(listIndex);
      String header = fieldName;
      printStr.append(
          StringUtil.getRightPaddedString(
              StringUtil.getRightPaddedString("", header.length(), '-'), maxLen, ' '));
      printStr.append("  ");
      listIndex++;
    }
    PadoShell.println(printStr.toString());
  }