Class ResultFileReader

java.lang.Object
org.moeaframework.analysis.io.ResultFileReader
All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<ResultEntry>, Iterator<ResultEntry>

public class ResultFileReader extends Object implements Closeable, Iterator<ResultEntry>, Iterable<ResultEntry>
Reads result files created by ResultFileWriter.

By default, this reader will suppress any errors reading the contents, unless a serious I/O error occurred. Consequently, reading stops when invalid or incomplete data is detected. Callers should use getErrorHandler() to check if any errors occurred or to change the error handling behavior.

See Also:
  • Constructor Details

    • ResultFileReader

      public ResultFileReader(File file) throws IOException
      Constructs a result file reader for reading the contents of the specified result file.
      Parameters:
      file - the result file
      Throws:
      IOException - if an I/O error occurred
    • ResultFileReader

      public ResultFileReader(Reader reader) throws IOException
      Constructs a result file reader for reading the contents of the specified result file.
      Parameters:
      reader - the reader containing the result file
      Throws:
      IOException - if an I/O error occurred
    • ResultFileReader

      public ResultFileReader(Problem problem, File file) throws IOException
      Constructs a result file reader for reading the contents of the specified result file.
      Parameters:
      problem - the problem, if null a problem "stub" will be generated
      file - the result file
      Throws:
      IOException - if an I/O error occurred
    • ResultFileReader

      public ResultFileReader(Problem problem, Reader reader) throws IOException
      Constructs a result file reader for reading the contents of the specified result file.
      Parameters:
      problem - the problem, if null a problem "stub" will be generated
      reader - the reader containing the result file
      Throws:
      IOException - if an I/O error occurred
    • ResultFileReader

      public ResultFileReader(Problem problem, Reader reader, boolean allowLegacyFormat) throws IOException
      Constructs a result file reader for reading the contents of the specified result file.
      Parameters:
      problem - the problem, if null a problem "stub" will be generated
      reader - the reader containing the result file
      allowLegacyFormat - allows reading legacy file formats for backwards compatibility
      Throws:
      IOException - if an I/O error occurred
  • Method Details

    • getProblem

      public Problem getProblem()
      Returns the problem instance used by this reader. This is either the problem instance passed into the constructor or a ProblemStub if the problem was reconstructed from the result file.
      Returns:
      the problem instance
    • getErrorHandler

      public ErrorHandler getErrorHandler()
      Returns the error handler used by this reader.
      Returns:
      the error handler
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • next

      public ResultEntry next()
      Specified by:
      next in interface Iterator<ResultEntry>
    • iterator

      public Iterator<ResultEntry> iterator()
      Specified by:
      iterator in interface Iterable<ResultEntry>
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<ResultEntry>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<ResultEntry>
    • decode

      public Variable decode(Variable variable, String string) throws IOException
      Decodes string representations of decision variables, returning the variable with the decoded value. Depending on the implementation and variable type, the same variable as provided in the arguments or a new variable will be returned.
      Parameters:
      variable - the decision variable
      string - the string representation of the decision variable
      Returns:
      the variable with the decoded value
      Throws:
      IOException - if an error occurred during decoding and the error handler is configured to throw
      See Also:
    • open

      public static ResultFileReader open(Problem problem, File file) throws IOException
      Opens the result file for reading.
      Parameters:
      problem - the problem
      file - the file containing the results
      Returns:
      the result file reader
      Throws:
      IOException - if an I/O error occurred
    • openLegacy

      public static ResultFileReader openLegacy(Problem problem, File file) throws IOException
      Opens the result file for reading, supporting older legacy file formats.
      Parameters:
      problem - the problem
      file - the file containing the results
      Returns:
      the result file reader
      Throws:
      IOException - if an I/O error occurred