@Test public void toVersionOfLastRemoteCommandEqualsToVersionOfLastLocalCommand() { final List<? extends ListCommand> repairRemoteCommands = cut.repairRemoteCommandVersion( asList(someRemoteCommand, someOtherRemoteCommand), localCommands); assertThat(repairRemoteCommands).hasSize(2); assertThat(repairRemoteCommands.get(1).getListVersionChange().getToVersion()).isEqualTo( replaceInList.getListVersionChange().getToVersion()); }
public List<? extends ListCommand> repairRemoteCommandVersion( final List<? extends ListCommand> indexRepairedRemoteCommands, final List<ListCommand> versionRepairedLocalCommands) { final int commandCount = indexRepairedRemoteCommands.size(); final ListCommand lastLocalCommand = versionRepairedLocalCommands.get(versionRepairedLocalCommands.size() - 1); if (commandCount == 0) { return asList(new RemoveFromList(lastLocalCommand.getListId(), new ListVersionChange(randomUUID(), lastLocalCommand.getListVersionChange().getToVersion()), 0, 0)); } final List<ListCommand> repaired = new ArrayList<ListCommand>(commandCount); for (int i = 0; i < commandCount - 1; i++) { repaired.add(indexRepairedRemoteCommands.get(i)); } repaired.add(repairCommand(indexRepairedRemoteCommands.get(commandCount - 1), randomUUID(), lastLocalCommand .getListVersionChange().getToVersion())); return repaired; }
ListCommandVersionRepairer { public List<? extends ListCommand> repairRemoteCommandVersion( final List<? extends ListCommand> indexRepairedRemoteCommands, final List<ListCommand> versionRepairedLocalCommands) { final int commandCount = indexRepairedRemoteCommands.size(); final ListCommand lastLocalCommand = versionRepairedLocalCommands.get(versionRepairedLocalCommands.size() - 1); if (commandCount == 0) { return asList(new RemoveFromList(lastLocalCommand.getListId(), new ListVersionChange(randomUUID(), lastLocalCommand.getListVersionChange().getToVersion()), 0, 0)); } final List<ListCommand> repaired = new ArrayList<ListCommand>(commandCount); for (int i = 0; i < commandCount - 1; i++) { repaired.add(indexRepairedRemoteCommands.get(i)); } repaired.add(repairCommand(indexRepairedRemoteCommands.get(commandCount - 1), randomUUID(), lastLocalCommand .getListVersionChange().getToVersion())); return repaired; } }
ListCommandVersionRepairer { public List<? extends ListCommand> repairRemoteCommandVersion( final List<? extends ListCommand> indexRepairedRemoteCommands, final List<ListCommand> versionRepairedLocalCommands) { final int commandCount = indexRepairedRemoteCommands.size(); final ListCommand lastLocalCommand = versionRepairedLocalCommands.get(versionRepairedLocalCommands.size() - 1); if (commandCount == 0) { return asList(new RemoveFromList(lastLocalCommand.getListId(), new ListVersionChange(randomUUID(), lastLocalCommand.getListVersionChange().getToVersion()), 0, 0)); } final List<ListCommand> repaired = new ArrayList<ListCommand>(commandCount); for (int i = 0; i < commandCount - 1; i++) { repaired.add(indexRepairedRemoteCommands.get(i)); } repaired.add(repairCommand(indexRepairedRemoteCommands.get(commandCount - 1), randomUUID(), lastLocalCommand .getListVersionChange().getToVersion())); return repaired; }  }
ListCommandVersionRepairer { public List<? extends ListCommand> repairRemoteCommandVersion( final List<? extends ListCommand> indexRepairedRemoteCommands, final List<ListCommand> versionRepairedLocalCommands) { final int commandCount = indexRepairedRemoteCommands.size(); final ListCommand lastLocalCommand = versionRepairedLocalCommands.get(versionRepairedLocalCommands.size() - 1); if (commandCount == 0) { return asList(new RemoveFromList(lastLocalCommand.getListId(), new ListVersionChange(randomUUID(), lastLocalCommand.getListVersionChange().getToVersion()), 0, 0)); } final List<ListCommand> repaired = new ArrayList<ListCommand>(commandCount); for (int i = 0; i < commandCount - 1; i++) { repaired.add(indexRepairedRemoteCommands.get(i)); } repaired.add(repairCommand(indexRepairedRemoteCommands.get(commandCount - 1), randomUUID(), lastLocalCommand .getListVersionChange().getToVersion())); return repaired; }  void repairLocalCommandsVersion(final Queue<ListCommand> localCommands,
            final ListCommand originalRemoteCommand); List<? extends ListCommand> repairRemoteCommandVersion(
            final List<? extends ListCommand> indexRepairedRemoteCommands,
            final List<ListCommand> versionRepairedLocalCommands); }
ListCommandVersionRepairer { public List<? extends ListCommand> repairRemoteCommandVersion( final List<? extends ListCommand> indexRepairedRemoteCommands, final List<ListCommand> versionRepairedLocalCommands) { final int commandCount = indexRepairedRemoteCommands.size(); final ListCommand lastLocalCommand = versionRepairedLocalCommands.get(versionRepairedLocalCommands.size() - 1); if (commandCount == 0) { return asList(new RemoveFromList(lastLocalCommand.getListId(), new ListVersionChange(randomUUID(), lastLocalCommand.getListVersionChange().getToVersion()), 0, 0)); } final List<ListCommand> repaired = new ArrayList<ListCommand>(commandCount); for (int i = 0; i < commandCount - 1; i++) { repaired.add(indexRepairedRemoteCommands.get(i)); } repaired.add(repairCommand(indexRepairedRemoteCommands.get(commandCount - 1), randomUUID(), lastLocalCommand .getListVersionChange().getToVersion())); return repaired; }  void repairLocalCommandsVersion(final Queue<ListCommand> localCommands,
            final ListCommand originalRemoteCommand); List<? extends ListCommand> repairRemoteCommandVersion(
            final List<? extends ListCommand> indexRepairedRemoteCommands,
            final List<ListCommand> versionRepairedLocalCommands);  }