@Test public void mergeAlreadyExistingServerDoesNotModifyList() throws ValidationException { List<Server> existingServers = new ArrayList<Server>(); existingServers.add(dummyServer()); List<Server> newServers = new ArrayList<Server>(); newServers.add(dummyServer()); List<Server> merged = configurationParser.mergeServerLists(existingServers, newServers); assertThat(merged).hasSize(1); Server mergedServer = merged.get(0); assertThat(mergedServer.getQueries()).hasSize(1); }
@CheckReturnValue @VisibleForTesting ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) { ImmutableList.Builder<Server> results = ImmutableList.builder(); List<Server> toProcess = new ArrayList<>(secondList); for (Server firstServer : firstList) { if (toProcess.contains(firstServer)) { Server found = toProcess.get(secondList.indexOf(firstServer)); results.add(merge(firstServer, found)); toProcess.remove(found); } else { results.add(firstServer); } } results.addAll(toProcess); return results.build(); }
ConfigurationParser { @CheckReturnValue @VisibleForTesting ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) { ImmutableList.Builder<Server> results = ImmutableList.builder(); List<Server> toProcess = new ArrayList<>(secondList); for (Server firstServer : firstList) { if (toProcess.contains(firstServer)) { Server found = toProcess.get(secondList.indexOf(firstServer)); results.add(merge(firstServer, found)); toProcess.remove(found); } else { results.add(firstServer); } } results.addAll(toProcess); return results.build(); } }
ConfigurationParser { @CheckReturnValue @VisibleForTesting ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) { ImmutableList.Builder<Server> results = ImmutableList.builder(); List<Server> toProcess = new ArrayList<>(secondList); for (Server firstServer : firstList) { if (toProcess.contains(firstServer)) { Server found = toProcess.get(secondList.indexOf(firstServer)); results.add(merge(firstServer, found)); toProcess.remove(found); } else { results.add(firstServer); } } results.addAll(toProcess); return results.build(); } @Inject  ConfigurationParser(ProcessConfigUtils processConfigUtils); }
ConfigurationParser { @CheckReturnValue @VisibleForTesting ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) { ImmutableList.Builder<Server> results = ImmutableList.builder(); List<Server> toProcess = new ArrayList<>(secondList); for (Server firstServer : firstList) { if (toProcess.contains(firstServer)) { Server found = toProcess.get(secondList.indexOf(firstServer)); results.add(merge(firstServer, found)); toProcess.remove(found); } else { results.add(firstServer); } } results.addAll(toProcess); return results.build(); } @Inject  ConfigurationParser(ProcessConfigUtils processConfigUtils); ImmutableList parseServers(Iterable<File> processConfigFiles, boolean continueOnJsonError); }
ConfigurationParser { @CheckReturnValue @VisibleForTesting ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) { ImmutableList.Builder<Server> results = ImmutableList.builder(); List<Server> toProcess = new ArrayList<>(secondList); for (Server firstServer : firstList) { if (toProcess.contains(firstServer)) { Server found = toProcess.get(secondList.indexOf(firstServer)); results.add(merge(firstServer, found)); toProcess.remove(found); } else { results.add(firstServer); } } results.addAll(toProcess); return results.build(); } @Inject  ConfigurationParser(ProcessConfigUtils processConfigUtils); ImmutableList parseServers(Iterable<File> processConfigFiles, boolean continueOnJsonError);  }