Exemple #1
0
 /**
  * Note that altough this is a public constructor, Rows should always be created by a RowFactory.
  *
  * @param pAddNulls will the list be filled with nulls?
  */
 public Row(RowFormat pFormat, boolean pAddNulls) {
   super(pFormat.getNumFields());
   mFormat = pFormat;
   if (pAddNulls) {
     int numFields = pFormat.getNumFields();
     for (int i = 0; i < numFields; i++) {
       add(null);
     }
   }
 }
 public List makeRow(String pDataString) {
   ArrayList row;
   if (mFormat != null) {
     // we have a format
     row = new ArrayList(mFormat.getNumFields());
     dbgMsg("makeRow(" + pDataString + "," + mFormat + ")");
     int[] groups = mFormat.getNumFieldsArray();
     dbgMsg(
         "Groups of the format: "
             + StringUtils.collectionToString(ConversionUtils.asList(groups), " "));
     dbgMsg("Row(" + pDataString + "," + mFormat + ")");
     String[] tokens = StringUtils.split(pDataString, columnSeparatorRegex, groups);
     dbgMsg("Tokens: " + StringUtils.arrayToString(tokens, "\n"));
     for (int i = 0; i < tokens.length; i++) {
       row.add(mFormat.makeFieldRep(i, tokens[i]));
     }
   } else {
     // we do not have a format
     String[] tokens = pDataString.split(columnSeparatorRegex);
     // note: -1 indicates that the number of fields is not fixed!
     if (mNumFields != -1 && tokens.length != mNumFields) {
       throw new RuntimeException(
           "Cannot make row: numFieds = " + mNumFields + " != numTokens = " + tokens.length);
     } else {
       row = new ArrayList(Arrays.asList(tokens));
     }
   }
   return row;
 }
 /** No enforced row format */
 public ArrayListRowFactory(RowFormat pFormat) {
   mNumFields = pFormat.getNumFields();
   mFormat = pFormat;
 }