private void mergeFields(Row row, Row requiredRow) {
   for (Field field : requiredRow.getFields().toFieldList()) {
     if (!row.containsField(field.getName())) {
       row.getLocalDefinedFields().put(new Field(field));
     }
   }
   LocationUtil.mergeLocationPointers(row.getLocationPointer(), requiredRow.getLocationPointer());
 }
 public int compare(Row row1, Row row2) {
   if (row1.getUniqueKey() == null && row2.getUniqueKey() != null) {
     return -1;
   }
   if (row1.getUniqueKey() != null && row2.getUniqueKey() == null) {
     return 1;
   }
   return initialOrder.indexOf(row1) - initialOrder.indexOf(row2);
 }
 private String computeErrorMessage(
     Row requiredRow, List<Row> incompatibleRows, String initialErrorMessage) {
   StringBuilder stringBuilder =
       new StringBuilder()
           .append(initialErrorMessage)
           .append("\n")
           .append("\n")
           .append("ligne required :\n");
   requiredRow.getLocationPointer().accept(new LoggerLocationVisitor(stringBuilder));
   stringBuilder.append("\n").append("ligne(s) en conflit :\n");
   for (Row incompatibleRow : incompatibleRows) {
     incompatibleRow.getLocationPointer().accept(new LoggerLocationVisitor(stringBuilder));
   }
   return stringBuilder.toString();
 }
  private void mergeRequiredRowWithUniqueKey(Table destinationTable, Row requiredRow) {
    List<Row> updatables = new ArrayList<Row>();
    List<Row> incompatiblesRows = new ArrayList<Row>();

    for (Row existingRow : destinationTable.getRows()) {
      if (checker.matchUniqueKey(requiredRow.getUniqueKey(), existingRow)) {
        if (checker.checkIncompatibilityIgnoringUniqueKey(requiredRow, existingRow)) {
          incompatiblesRows.add(existingRow);
        } else {
          updatables.add(existingRow);
        }
      }
    }

    if (!incompatiblesRows.isEmpty()) {
      throw new TokioLoaderException(
          computeErrorMessage(requiredRow, incompatiblesRows, CONFLICT_ERROR_MESSAGE));
    } else if (updatables.size() > 1) {
      throw new TokioLoaderException(
          computeErrorMessage(requiredRow, updatables, TOO_MANY_ROWS_ERROR_MESSAGE));
    } else if (updatables.size() == 1) {
      mergeFields(updatables.get(0), requiredRow);
    } else {
      destinationTable.addRow(requiredRow);
    }
  }
 private void mergeRequiredRow(Table destinationTable, Row requiredRow) {
   boolean thereIsAMerge = false;
   for (Row existingRow : destinationTable.getRows()) {
     if (checker.matchAllFields(requiredRow, existingRow)) {
       LocationUtil.mergeLocationPointers(
           existingRow.getLocationPointer(), requiredRow.getLocationPointer());
       thereIsAMerge = true;
     }
   }
   if (!thereIsAMerge) {
     if (requiredRow.getUniqueKey() == null) {
       destinationTable.addRow(requiredRow);
     } else {
       mergeRequiredRowWithUniqueKey(destinationTable, requiredRow);
     }
   }
 }