Package org.moeaframework.analysis.io
Class MatrixReader
java.lang.Object
org.moeaframework.analysis.io.MatrixReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<double[]>
,Iterator<double[]>
- Direct Known Subclasses:
MetricFileReader
public class MatrixReader
extends Object
implements Iterable<double[]>, Iterator<double[]>, Closeable
Reader of files containing matrices. A matrix contains numerical data separated into rows and columns. The values
in a row are separated by whitespace.
The file can contain commented lines starting with '#' characters.
Parsing stops at the first error. Check the error
flag to determine if an error was encountered. An
exception may or may not be thrown, depending on the type of error and the value of the suppressExceptions
flag. If exceptions are suppressed, a warning message will be printed.
-
Constructor Summary
ConstructorDescriptionMatrixReader
(File file) Constructs a reader for loading a matrix contained in the specified file.MatrixReader
(File file, int numberOfColumns) Constructs a reader for loading a matrix contained in the specified file.MatrixReader
(Reader reader) Constructs a reader for loading a matrix accessed through the underlying reader.MatrixReader
(Reader reader, int numberOfColumns) Constructs a reader for loading a matrix accessed through the underlying reader. -
Method Summary
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
-
MatrixReader
Constructs a reader for loading a matrix contained in the specified file.- Parameters:
file
- the file containing the matrix- Throws:
FileNotFoundException
- if the file was not found
-
MatrixReader
Constructs a reader for loading a matrix contained in the specified file.- Parameters:
file
- the file containing the matrixnumberOfColumns
- the expected number of columns; or-1
if the matrix has no fixed column count- Throws:
FileNotFoundException
- if the file was not found
-
MatrixReader
Constructs a reader for loading a matrix accessed through the underlying reader.- Parameters:
reader
- the underlying reader
-
MatrixReader
Constructs a reader for loading a matrix accessed through the underlying reader.- Parameters:
reader
- the underlying readernumberOfColumns
- the expected number of columns; or-1
if the matrix has no fixed column count
-
-
Method Details
-
load
Loads the content of the file into a matrix.- Parameters:
file
- the file containing the matrix- Returns:
- the matrix
- Throws:
FileNotFoundException
- if the file was not foundIOException
- if an I/O error occurred while reading the file
-
iterator
-
hasNext
public boolean hasNext() -
next
public double[] next() -
remove
public void remove() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
readAll
public double[][] readAll()Reads the entire contents of the file.- Returns:
- the entire contents of the file
-