Exemple #1
0
 public Object get(String pFieldName) {
   if (!(mFormat.containsField(pFieldName))) {
     throw new RuntimeException("No such field: " + pFieldName);
   }
   int fieldInd = mFormat.getFieldIndex(pFieldName);
   return get(fieldInd);
 }
Exemple #2
0
 public void set(String pFieldName, Object pVal) {
   if (!(mFormat.containsField(pFieldName))) {
     throw new RuntimeException("No such field: " + pFieldName);
   }
   int fieldInd = mFormat.getFieldIndex(pFieldName);
   set(fieldInd, pVal);
 }
 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;
 }
Exemple #4
0
 public Row select(String[] pFieldNames) {
   RowFormat newFormat = mFormat.select(pFieldNames);
   Row newRow = (Row) newFormat.getRowFactory().makeRow();
   for (int i = 0; i < pFieldNames.length; i++) {
     String fieldName = pFieldNames[i];
     newRow.set(fieldName, get(fieldName));
   }
   return newRow;
 }
Exemple #5
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);
     }
   }
 }
Exemple #6
0
  public Row join(Row pRow, String pField) {
    // dbgMsg("Join!");
    RowFormat newFormat = mFormat.join(pRow.mFormat, pField);
    Row newRow = (Row) newFormat.getRowFactory().makeRow();
    // String[] ourFieldNames = mFormat.getFieldNames();
    // String[] theirFieldNames =pRow.mFormat.getFieldNames();
    // dbgMsg("ourFieldNames="+StringUtils.arrayToString(ourFieldNames, ", "));
    // dbgMsg("theirFieldNames="+StringUtils.arrayToString(theirFieldNames, ", "));

    HashSet ourFields = new HashSet(Arrays.asList(mFormat.getFieldNames()));
    HashSet theirFields = new HashSet(Arrays.asList(pRow.mFormat.getFieldNames()));
    ourFields.remove(pField);
    theirFields.remove(pField);
    HashSet commonFields = new HashSet(ourFields);
    commonFields.retainAll(theirFields);
    ourFields.removeAll(commonFields);
    theirFields.removeAll(commonFields);

    // dbgMsg("join field "+pField);
    // dbgMsg("our fields: "+StringUtils.collectionToString(ourFields, " "));
    // dbgMsg("their fields: "+StringUtils.collectionToString(theirFields, " "));
    // dbgMsg("common fields: "+StringUtils.collectionToString(commonFields, " "));

    // copy join field
    newRow.set(pField, get(pField)); // (copied arbitrarily from...us, as should be same!)

    // copy our fields
    Iterator ourFieldsIter = ourFields.iterator();
    while (ourFieldsIter.hasNext()) {
      String field = (String) ourFieldsIter.next();
      newRow.set(field, (get(field)));
    }

    // copy their fields
    Iterator theirFieldsIter = theirFields.iterator();
    while (theirFieldsIter.hasNext()) {
      String field = (String) theirFieldsIter.next();
      newRow.set(field, (pRow.get(field)));
    }

    // copy common fields (renaming fields becomes necessary)
    Iterator commonFieldsIter = commonFields.iterator();
    while (commonFieldsIter.hasNext()) {
      String field = (String) commonFieldsIter.next();
      newRow.set(field + "1", (get(field)));
      newRow.set(field + "2", (pRow.get(field)));
    }

    return newRow;
  }
Exemple #7
0
 public void setOrInsertField(String pFieldName, Object pData, int pInd) {
   if (mFormat.containsField(pFieldName)) {
     set(pFieldName, pData);
   } else {
     insertField(pInd, pFieldName, pData);
   }
 }
Exemple #8
0
 public void setOrAppendField(String pFieldName, Object pData) {
   if (mFormat.containsField(pFieldName)) {
     set(pFieldName, pData);
   } else {
     appendField(pFieldName, pData);
   }
 }
Exemple #9
0
 public boolean equals(Object pObj) {
   if (!(pObj instanceof Row)) {
     return false;
   }
   Row other = (Row) pObj;
   return mFormat.equals(other.mFormat) && super.equals(other);
 }
Exemple #10
0
 public List formatFields() {
   ArrayList result = new ArrayList(size());
   for (int i = 0; i < size(); i++) {
     result.add(mFormat.formatField(i, get(i)));
   }
   return result;
 }
Exemple #11
0
 public String formatField(int pInd) {
   return mFormat.formatField(pInd, get(pInd));
 }
Exemple #12
0
 /** @see #appendField(String, Object) ,as this is conceptually a similar operation. */
 public void insertField(int pIndex, String pFieldName, Object pData) {
   mFormat = mFormat.insertField(pIndex, pFieldName);
   add(pIndex, pData);
 }
Exemple #13
0
 /**
  * Append a field to the Row. The field needs also be added to the format. Note that this is a bit
  * inefficient, as a new RowFormat needs to be created, as RowFormat objects are immutable(if that
  * were not the case, we would just run into another kinds of problems!). As a work-around for
  * this inefficiency, a method should be devised to add the field and set the new format at the
  * same time, so that format objects might be shared.
  */
 public void appendField(String pFieldName, Object pData) {
   mFormat = mFormat.addFieldToEnd(pFieldName);
   add(pData);
 }
Exemple #14
0
 public boolean containsField(String pFieldId) {
   return mFormat.containsField(pFieldId);
 }
Exemple #15
0
 public void removeField(String pFieldName) {
   int index = mFormat.getFieldIndex(pFieldName);
   mFormat = mFormat.removeField(index);
   remove(index);
 }
 /** No enforced row format */
 public ArrayListRowFactory(RowFormat pFormat) {
   mNumFields = pFormat.getNumFields();
   mFormat = pFormat;
 }