@Test public void smoke() { FileNamePattern fileNamePattern = new FileNamePattern("smoke-%d-%i.gz", context); SizeAndTimeBasedArchiveRemover remover = new SizeAndTimeBasedArchiveRemover(fileNamePattern, null); File[] fileArray = new File[2]; File[] expected = new File[2]; fileArray[0] = expected[1] = new File("/tmp/smoke-1970-01-01-0.gz"); fileArray[1] = expected[0] = new File("/tmp/smoke-1970-01-01-1.gz"); remover.descendingSort(fileArray, new Date(0)); assertArrayEquals(expected, fileArray); }
@Override protected void descendingSort(File[] matchingFileArray, Date date) { String regexForIndexExtreaction = createStemRegex(date); final Pattern pattern = Pattern.compile(regexForIndexExtreaction); Arrays.sort(matchingFileArray, new Comparator<File>() { @Override public int compare(final File f1, final File f2) { int index1 = extractIndex(pattern, f1); int index2 = extractIndex(pattern, f2); if (index1 == index2) return 0; if (index2 < index1) return -1; else return 1; } private int extractIndex(Pattern pattern, File f1) { Matcher matcher = pattern.matcher(f1.getName()); if (matcher.find()) { String indexAsStr = matcher.group(1); if (indexAsStr == null || indexAsStr.isEmpty()) return NO_INDEX; else return Integer.parseInt(indexAsStr); } else return NO_INDEX; } }); }
SizeAndTimeBasedArchiveRemover extends TimeBasedArchiveRemover { @Override protected void descendingSort(File[] matchingFileArray, Date date) { String regexForIndexExtreaction = createStemRegex(date); final Pattern pattern = Pattern.compile(regexForIndexExtreaction); Arrays.sort(matchingFileArray, new Comparator<File>() { @Override public int compare(final File f1, final File f2) { int index1 = extractIndex(pattern, f1); int index2 = extractIndex(pattern, f2); if (index1 == index2) return 0; if (index2 < index1) return -1; else return 1; } private int extractIndex(Pattern pattern, File f1) { Matcher matcher = pattern.matcher(f1.getName()); if (matcher.find()) { String indexAsStr = matcher.group(1); if (indexAsStr == null || indexAsStr.isEmpty()) return NO_INDEX; else return Integer.parseInt(indexAsStr); } else return NO_INDEX; } }); } }
SizeAndTimeBasedArchiveRemover extends TimeBasedArchiveRemover { @Override protected void descendingSort(File[] matchingFileArray, Date date) { String regexForIndexExtreaction = createStemRegex(date); final Pattern pattern = Pattern.compile(regexForIndexExtreaction); Arrays.sort(matchingFileArray, new Comparator<File>() { @Override public int compare(final File f1, final File f2) { int index1 = extractIndex(pattern, f1); int index2 = extractIndex(pattern, f2); if (index1 == index2) return 0; if (index2 < index1) return -1; else return 1; } private int extractIndex(Pattern pattern, File f1) { Matcher matcher = pattern.matcher(f1.getName()); if (matcher.find()) { String indexAsStr = matcher.group(1); if (indexAsStr == null || indexAsStr.isEmpty()) return NO_INDEX; else return Integer.parseInt(indexAsStr); } else return NO_INDEX; } }); } SizeAndTimeBasedArchiveRemover(FileNamePattern fileNamePattern, RollingCalendar rc); }
SizeAndTimeBasedArchiveRemover extends TimeBasedArchiveRemover { @Override protected void descendingSort(File[] matchingFileArray, Date date) { String regexForIndexExtreaction = createStemRegex(date); final Pattern pattern = Pattern.compile(regexForIndexExtreaction); Arrays.sort(matchingFileArray, new Comparator<File>() { @Override public int compare(final File f1, final File f2) { int index1 = extractIndex(pattern, f1); int index2 = extractIndex(pattern, f2); if (index1 == index2) return 0; if (index2 < index1) return -1; else return 1; } private int extractIndex(Pattern pattern, File f1) { Matcher matcher = pattern.matcher(f1.getName()); if (matcher.find()) { String indexAsStr = matcher.group(1); if (indexAsStr == null || indexAsStr.isEmpty()) return NO_INDEX; else return Integer.parseInt(indexAsStr); } else return NO_INDEX; } }); } SizeAndTimeBasedArchiveRemover(FileNamePattern fileNamePattern, RollingCalendar rc);  }
SizeAndTimeBasedArchiveRemover extends TimeBasedArchiveRemover { @Override protected void descendingSort(File[] matchingFileArray, Date date) { String regexForIndexExtreaction = createStemRegex(date); final Pattern pattern = Pattern.compile(regexForIndexExtreaction); Arrays.sort(matchingFileArray, new Comparator<File>() { @Override public int compare(final File f1, final File f2) { int index1 = extractIndex(pattern, f1); int index2 = extractIndex(pattern, f2); if (index1 == index2) return 0; if (index2 < index1) return -1; else return 1; } private int extractIndex(Pattern pattern, File f1) { Matcher matcher = pattern.matcher(f1.getName()); if (matcher.find()) { String indexAsStr = matcher.group(1); if (indexAsStr == null || indexAsStr.isEmpty()) return NO_INDEX; else return Integer.parseInt(indexAsStr); } else return NO_INDEX; } }); } SizeAndTimeBasedArchiveRemover(FileNamePattern fileNamePattern, RollingCalendar rc);   }