Package org.moeaframework.util.io
Class MatrixIO
java.lang.Object
org.moeaframework.util.io.MatrixIO
Static methods for reading and writing matrices. Each row in the matrix maps to a row in the file, and each row
is expected to contain the same number of values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[][]
Loads the content of the file into a matrix.static double[][]
Loads the content of the reader into a matrix.static double[]
loadColumn
(File file, int index) Loads a single column from the file into a matrix.static double[]
loadColumn
(Reader reader, int index) Loads a single column from the reader into a matrix.static void
Saves a matrix to a file.static void
Saves a matrix to a file.static void
Saves a matrix to the writer.static void
Saves a matrix to the writer.
-
Method Details
-
load
Loads the content of the reader into a matrix.- Parameters:
reader
- the reader containing the matrix- Returns:
- the matrix values
- Throws:
IOException
- if an I/O error occurred while reading the file
-
load
Loads the content of the file into a matrix.- Parameters:
file
- the file containing the matrix- Returns:
- the matrix values
- Throws:
FileNotFoundException
- if the file was not foundIOException
- if an I/O error occurred while reading the file
-
loadColumn
Loads a single column from the reader into a matrix.- Parameters:
reader
- the reader containing the matrixindex
- the index of the column- Returns:
- the column values
- Throws:
IOException
- if an I/O error occurred while reading the fileIndexOutOfBoundsException
- if the index is not a valid column
-
loadColumn
Loads a single column from the file into a matrix.- Parameters:
file
- the file containing the matrixindex
- the index of the column- Returns:
- the column values
- Throws:
FileNotFoundException
- if the file was not foundIOException
- if an I/O error occurred while reading the fileIndexOutOfBoundsException
- if the index is not a valid column
-
save
Saves a matrix to the writer.- Parameters:
writer
- the writermatrix
- a 2D array containing the matrix
-
save
Saves a matrix to a file.- Parameters:
file
- the filematrix
- a 2D array containing the matrix- Throws:
IOException
- if an I/O error occurred while writing the file
-
save
Saves a matrix to the writer.- Parameters:
writer
- the writermatrix
- an iterator over the rows in the matrix
-
save
Saves a matrix to a file.- Parameters:
file
- the filematrix
- an iterator over the rows in the matrix- Throws:
IOException
- if an I/O error occurred while writing the file
-