Friday, July 10, 2015

few Java Util methods used in batch programs

During processing of csv files or mainframe dumps and feeding to oracle/mysql via spring batch etc.


public static  convertStringSetToString(Set inputStrSet, char delimiter) {
    StringBuilder sb = new StringBuilder();
    if (inputStrSet != null) {
      Iterator iters = inputStrSet.iterator();

      while (iters.hasNext()) {
        String stringValue = iters.next();
        sb.append(stringValue);
        sb.append(delimiter);
      }
    }
    return sb.toString();
  }

  public  String convertStringListToString(List inputStrList, char delimiter) {
    StringBuilder sb = new StringBuilder();
    if (inputStrList != null) {
      Iterator iters = inputStrList.iterator();

      while (iters.hasNext()) {
        String stringValue = iters.next();
        sb.append(stringValue);
        sb.append(delimiter);
      }
    }
    return sb.toString();
  }


    public  String arrayToString(T[] array) {
      if (array != null) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
          Object object = (Object) array[i];
          builder.append(String.valueOf(object));
          if (i < array.length - 1) {
            builder.append(", ");
          }
        }
        return builder.toString();
      } ///if null return ""?
  }

No comments: