code: public ListCommand repairCommand(final ReplaceInList toRepair, final RemoveFromList repairAgainst) {
          final int indicesBefore = toRepair.getPosition() - repairAgainst.getStartPosition();
          if (indicesBefore <= 0) {
              return toRepair;
          }
          final int indicesToDecrese = indicesBefore < repairAgainst.getRemoveCount() ? indicesBefore : repairAgainst
                  .getRemoveCount();
  
          if (repairAgainst.getStartPosition() + repairAgainst.getRemoveCount() <= toRepair.getPosition()) {
              return new ReplaceInList(toRepair.getListId(), toRepair.getListVersionChange(), toRepair.getValue(),
                      toRepair.getPosition() - indicesToDecrese);
          }
          return new AddToList(toRepair.getListId(), toRepair.getListVersionChange(), toRepair.getValue(),
                  toRepair.getPosition() - indicesToDecrese);
      }
docs: Repairs a {@link ReplaceInList} in relation to an {@link RemoveFromList} command.
  
  <p>
  Repairing a {@link ReplaceInList} command can result in an {@link AddToList} command in the case that the element
  that should be replaced was removed. Therefore this methods return a {@link ListCommand} which is either a
  {@link ReplaceInList} or {@link AddToList}.
  </p>
  
  @param toRepair
  The command to repair.
  @param repairAgainst
  The command to repair against.
  @return The repaired command.