private static void selectJunctionMerger(Station a, Station b, int dist) { String message = "The following junctions will be merged because they have stations that are near each-other.\n"; List<Station> stations = new ArrayList<Station>(); stations.add(a); stations.add(b); message += "Distance " + dist + "m"; for (Station s : stations) message += "\n " + s.getId() + "-" + s.getName() + "-" + s.getNiceName(); message += "\nSelect a name for the merged junction\n"; List<Junction> opts = new ArrayList<Junction>(); for (Station s : stations) opts.add(s.getJunction()); for (int i = 0; i < opts.size(); i++) { Junction junction = opts.get(i); String junctionStations = ""; if (junction.getStations().size() < 10) for (Station s : junction.getStations()) { junctionStations += "\n " + s.getId() + "-" + s.getName() + "-" + s.getNiceName(); } else junctionStations += "\n " + junction.getStations().size() + " stations."; message += "\n " + i + ". ---" + junction.getName() + "---" + junctionStations; } List<String> optNames = new ArrayList<String>(); for (Junction j : opts) optNames.add(j.getName()); String concat = concat(optNames); if (!concat.equals(optNames.get(0))) { optNames.add(concat); message += "\n " + opts.size() + ". ---" + concat + "---"; } String out = showInput(message); String name; try { name = optNames.get(Integer.parseInt(out)).trim(); } catch (NumberFormatException e) { name = out.trim(); } Junction merged = new Junction(name, null); merged.getStations().addAll(stations); for (Junction j : opts) if (nonEmpty(j.getName())) merged.getStations().addAll(j.getStations()); for (Station s : merged.getStations()) s.setJunction(merged); }