@Test void saveToFileThrowsIllegalArgumentExceptionIfNamePrefixIsBlank(final @TempDir Path tempDir) { assertThrows(IllegalArgumentException.class, () -> persistedHistogram.saveToFile(tempDir, " \t \n ")); }
public Path saveToFile(final Path outputDirectory, final String namePrefix) throws IOException { requireNonNull(outputDirectory); final String prefix = namePrefix.trim(); if (prefix.isEmpty()) { throw new IllegalArgumentException("Name prefix cannot be blank!"); } final String fileNamePrefix = prefix + "-"; final Stream<Path> pathStream = find( outputDirectory, 1, (file, attrs) -> { if (!isRegularFile(file)) { return false; } final String fileName = file.getFileName().toString(); return fileName.endsWith(FILE_EXTENSION) && !fileName.endsWith(AGGREGATE_FILE_SUFFIX) && fileName.startsWith(fileNamePrefix); }); final int index = pathStream.mapToInt( (file) -> { final String fileName = file.getFileName().toString(); final int indexLength = fileName.length() - FILE_EXTENSION.length() - fileNamePrefix.length(); return parseIntAscii(fileName, fileNamePrefix.length(), indexLength); }) .max() .orElse(-1) + 1; return saveToFile(histogram, outputDirectory.resolve(fileNamePrefix + index + FILE_EXTENSION)); }
PersistedHistogram { public Path saveToFile(final Path outputDirectory, final String namePrefix) throws IOException { requireNonNull(outputDirectory); final String prefix = namePrefix.trim(); if (prefix.isEmpty()) { throw new IllegalArgumentException("Name prefix cannot be blank!"); } final String fileNamePrefix = prefix + "-"; final Stream<Path> pathStream = find( outputDirectory, 1, (file, attrs) -> { if (!isRegularFile(file)) { return false; } final String fileName = file.getFileName().toString(); return fileName.endsWith(FILE_EXTENSION) && !fileName.endsWith(AGGREGATE_FILE_SUFFIX) && fileName.startsWith(fileNamePrefix); }); final int index = pathStream.mapToInt( (file) -> { final String fileName = file.getFileName().toString(); final int indexLength = fileName.length() - FILE_EXTENSION.length() - fileNamePrefix.length(); return parseIntAscii(fileName, fileNamePrefix.length(), indexLength); }) .max() .orElse(-1) + 1; return saveToFile(histogram, outputDirectory.resolve(fileNamePrefix + index + FILE_EXTENSION)); } }
PersistedHistogram { public Path saveToFile(final Path outputDirectory, final String namePrefix) throws IOException { requireNonNull(outputDirectory); final String prefix = namePrefix.trim(); if (prefix.isEmpty()) { throw new IllegalArgumentException("Name prefix cannot be blank!"); } final String fileNamePrefix = prefix + "-"; final Stream<Path> pathStream = find( outputDirectory, 1, (file, attrs) -> { if (!isRegularFile(file)) { return false; } final String fileName = file.getFileName().toString(); return fileName.endsWith(FILE_EXTENSION) && !fileName.endsWith(AGGREGATE_FILE_SUFFIX) && fileName.startsWith(fileNamePrefix); }); final int index = pathStream.mapToInt( (file) -> { final String fileName = file.getFileName().toString(); final int indexLength = fileName.length() - FILE_EXTENSION.length() - fileNamePrefix.length(); return parseIntAscii(fileName, fileNamePrefix.length(), indexLength); }) .max() .orElse(-1) + 1; return saveToFile(histogram, outputDirectory.resolve(fileNamePrefix + index + FILE_EXTENSION)); } PersistedHistogram();   PersistedHistogram(final Histogram histogram); }
PersistedHistogram { public Path saveToFile(final Path outputDirectory, final String namePrefix) throws IOException { requireNonNull(outputDirectory); final String prefix = namePrefix.trim(); if (prefix.isEmpty()) { throw new IllegalArgumentException("Name prefix cannot be blank!"); } final String fileNamePrefix = prefix + "-"; final Stream<Path> pathStream = find( outputDirectory, 1, (file, attrs) -> { if (!isRegularFile(file)) { return false; } final String fileName = file.getFileName().toString(); return fileName.endsWith(FILE_EXTENSION) && !fileName.endsWith(AGGREGATE_FILE_SUFFIX) && fileName.startsWith(fileNamePrefix); }); final int index = pathStream.mapToInt( (file) -> { final String fileName = file.getFileName().toString(); final int indexLength = fileName.length() - FILE_EXTENSION.length() - fileNamePrefix.length(); return parseIntAscii(fileName, fileNamePrefix.length(), indexLength); }) .max() .orElse(-1) + 1; return saveToFile(histogram, outputDirectory.resolve(fileNamePrefix + index + FILE_EXTENSION)); } PersistedHistogram();   PersistedHistogram(final Histogram histogram); void reset(); void recordValue(final long value); void outputPercentileDistribution(final PrintStream printStream, final double outputValueUnitScalingRatio); Path saveToFile(final Path outputDirectory, final String namePrefix); }
PersistedHistogram { public Path saveToFile(final Path outputDirectory, final String namePrefix) throws IOException { requireNonNull(outputDirectory); final String prefix = namePrefix.trim(); if (prefix.isEmpty()) { throw new IllegalArgumentException("Name prefix cannot be blank!"); } final String fileNamePrefix = prefix + "-"; final Stream<Path> pathStream = find( outputDirectory, 1, (file, attrs) -> { if (!isRegularFile(file)) { return false; } final String fileName = file.getFileName().toString(); return fileName.endsWith(FILE_EXTENSION) && !fileName.endsWith(AGGREGATE_FILE_SUFFIX) && fileName.startsWith(fileNamePrefix); }); final int index = pathStream.mapToInt( (file) -> { final String fileName = file.getFileName().toString(); final int indexLength = fileName.length() - FILE_EXTENSION.length() - fileNamePrefix.length(); return parseIntAscii(fileName, fileNamePrefix.length(), indexLength); }) .max() .orElse(-1) + 1; return saveToFile(histogram, outputDirectory.resolve(fileNamePrefix + index + FILE_EXTENSION)); } PersistedHistogram();   PersistedHistogram(final Histogram histogram); void reset(); void recordValue(final long value); void outputPercentileDistribution(final PrintStream printStream, final double outputValueUnitScalingRatio); Path saveToFile(final Path outputDirectory, final String namePrefix);  }