Package org.moeaframework.analysis.io
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 Summary
ConstructorDescriptionResultFileReader
(File file) Constructs a result file reader for reading the contents of the specified result file.ResultFileReader
(Reader reader) Constructs a result file reader for reading the contents of the specified result file.ResultFileReader
(Problem problem, File file) Constructs a result file reader for reading the contents of the specified result file.ResultFileReader
(Problem problem, Reader reader) Constructs a result file reader for reading the contents of the specified result file.ResultFileReader
(Problem problem, Reader reader, boolean allowLegacyFormat) Constructs a result file reader for reading the contents of the specified result file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Decodes string representations of decision variables, returning the variable with the decoded value.Returns the error handler used by this reader.Returns the problem instance used by this reader.boolean
hasNext()
iterator()
next()
static ResultFileReader
Opens the result file for reading.static ResultFileReader
openLegacy
(Problem problem, File file) Opens the result file for reading, supporting older legacy file formats.void
remove()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
ResultFileReader
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
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
Constructs a result file reader for reading the contents of the specified result file.- Parameters:
problem
- the problem, ifnull
a problem "stub" will be generatedfile
- the result file- Throws:
IOException
- if an I/O error occurred
-
ResultFileReader
Constructs a result file reader for reading the contents of the specified result file.- Parameters:
problem
- the problem, ifnull
a problem "stub" will be generatedreader
- 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, ifnull
a problem "stub" will be generatedreader
- the reader containing the result fileallowLegacyFormat
- allows reading legacy file formats for backwards compatibility- Throws:
IOException
- if an I/O error occurred
-
-
Method Details
-
getProblem
Returns the problem instance used by this reader. This is either the problem instance passed into the constructor or aProblemStub
if the problem was reconstructed from the result file.- Returns:
- the problem instance
-
getErrorHandler
Returns the error handler used by this reader.- Returns:
- the error handler
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
next
- Specified by:
next
in interfaceIterator<ResultEntry>
-
iterator
- Specified by:
iterator
in interfaceIterable<ResultEntry>
-
hasNext
public boolean hasNext()- Specified by:
hasNext
in interfaceIterator<ResultEntry>
-
remove
public void remove()- Specified by:
remove
in interfaceIterator<ResultEntry>
-
decode
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 variablestring
- 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
Opens the result file for reading.- Parameters:
problem
- the problemfile
- the file containing the results- Returns:
- the result file reader
- Throws:
IOException
- if an I/O error occurred
-
openLegacy
Opens the result file for reading, supporting older legacy file formats.- Parameters:
problem
- the problemfile
- the file containing the results- Returns:
- the result file reader
- Throws:
IOException
- if an I/O error occurred
-