Class ResultWriter

java.lang.Object
org.moeaframework.analysis.io.ResultWriter
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
MetricFileWriter, ResultFileWriter

public abstract class ResultWriter extends Object implements Closeable
Abstract class for result writers.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new result writer.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Checks the last modified timestamp of the input and output files, throwing if the input is newer than the output.
    abstract int
    Returns the number of entries in the file.
    static boolean
    replace(File source, File destination)
    Replaces the destination file with the source file, but only if content is different.
    abstract void
    Writes the specified non-dominated population and optional attributes to the file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.io.Closeable

    close
  • Constructor Details

    • ResultWriter

      public ResultWriter()
      Constructs a new result writer.
  • Method Details

    • getNumberOfEntries

      public abstract int getNumberOfEntries()
      Returns the number of entries in the file. If the file already existed, this returns the number of complete entries in the output file. This value is incremented on every invocation to the write(org.moeaframework.analysis.series.ResultEntry) method.
      Returns:
      the number of entries in the file
    • write

      public abstract void write(ResultEntry entry) throws IOException
      Writes the specified non-dominated population and optional attributes to the file.
      Parameters:
      entry - the non-dominated population and optional attributes
      Throws:
      IOException - if an I/O error occurred
    • replace

      public static boolean replace(File source, File destination) throws IOException
      Replaces the destination file with the source file, but only if content is different. This avoids changing the modification timestamp on the file if the files are identical.
      Parameters:
      source - the source file, which is required to exist
      destination - the destination file, which might not exist
      Returns:
      true if the destination was updated; false otherwise
      Throws:
      IOException - if an I/O error occurred
    • failIfOutdated

      public static void failIfOutdated(CommandLineUtility cli, File input, File output)
      Checks the last modified timestamp of the input and output files, throwing if the input is newer than the output. This check should be performed before appending to existing files.
      Parameters:
      cli - the command line utility
      input - the input file
      output - the output file