Amazon { public List<String> reorderLines(int logFileSize, List<String> logLines) { List<String> words = new ArrayList<>(); if (logFileSize == 0 || logLines.size() == 0) { return words; } List<String> integers = new ArrayList<>(); for (String fline : logLines) { String line = fline.trim(); int sp1 = line.indexOf(' '); int sp2 = line.indexOf(' ', sp1 + 1); if (line.substring(sp1 + 1, sp2).trim().matches("\\d+")) { integers.add(line); } else { words.add(line); } } Collections.sort(words, (s1, s2) -> { String r1 = s1.substring(s1.indexOf(' ')).trim(); String r2 = s2.substring(s2.indexOf(' ')).trim(); if (r1.equals(r2)) { String identifier1 = s1.substring(0, s1.indexOf(' ')); String identifier2 = s2.substring(0, s2.indexOf(' ')); Pattern p = Pattern.compile("([a-z]+)(\\d+)"); Matcher m1 = p.matcher(identifier1); Matcher m2 = p.matcher(identifier2); if (m1.find() && m2.find()) { int i1 = Integer.parseInt(m1.group(2)); int i2 = Integer.parseInt(m2.group(2)); String is1 = m1.group(1); String is2 = m2.group(1); if (i1 == i2) { return is1.compareTo(is2); } else { return Integer.compare(i1, i2); } } return 0; } else { return r1.compareTo(r2); } }); words.addAll(integers); return words; }  List<String> retrieveMostFrequentlyUsedWords(String literatureText,
                                                        List<String> wordsToExclude); List<String> reorderLines(int logFileSize, List<String> logLines);  }
@Test(dataProvider = "lines") public void testReorderLines(List<String> logLines, List<String> expected) { Amazon s = new Amazon(); assertEquals(expected, s.reorderLines(logLines.size(), logLines)); }