package model;

import java.io.*;

public class TitanDSM {
    private int sizeOfMatrix;
    private int[][] dataMatrix;
    private String[] nameOfClass;

    public TitanDSM(int sizeOfMatrix) {
        this.sizeOfMatrix = sizeOfMatrix;
        dataMatrix = new int[sizeOfMatrix][sizeOfMatrix];
        nameOfClass = new String[sizeOfMatrix];
    }

    public TitanDSM(File file) throws IOException {
        loadFromFile(file);
    }

    public int getSize() {
        return sizeOfMatrix;
    }

    public void setSize(int size) {
        sizeOfMatrix = size;
    }

    public int[][] getData() {
        return dataMatrix;
    }

    public void setData(int[][] data) {
        dataMatrix = data;
    }

    public String[] getNames() {
        return nameOfClass;
    }

    public void setNames(String[] names) {
        nameOfClass = names;
    }

    public void loadFromFile(File dsm) throws IOException {
        BufferedReader fileReader = new BufferedReader(new FileReader(dsm));
        String read;
        String[] temp;

        read = fileReader.readLine();
        sizeOfMatrix = Integer.parseInt(read);

        dataMatrix = new int[sizeOfMatrix][sizeOfMatrix];
        nameOfClass = new String[sizeOfMatrix];

        for (int i = 0; i < sizeOfMatrix; i++) {
            read = fileReader.readLine();
            temp = read.split(" ");
            for (int j = 0; j < sizeOfMatrix; j++) {
                dataMatrix[i][j] = Integer.parseInt(temp[j]);
            }
        }

        for (int i = 0; i < sizeOfMatrix; i++) {
            read = fileReader.readLine();
            nameOfClass[i] = read;
        }
    }
    public void saveToFile(String fileName) throws IOException{
        BufferedWriter out = new BufferedWriter(new FileWriter(fileName));

        out.write(String.valueOf(sizeOfMatrix));
        out.newLine();
        for(int i = 0; i < sizeOfMatrix; i++) {
            for(int j = 0; j < sizeOfMatrix; j++) {
                out.write(dataMatrix[i][j] + " ");
            }
            out.newLine();
        }
        for(int idx = 0; idx < sizeOfMatrix; idx++) {
            out.write(nameOfClass[idx]);
            out.newLine();
        }

        out.close();
    }

}
@@ -1632,24 +1632,25 @@
     %7D%0A    %7D%0A
+%0A
     public v
@@ -1841,32 +1841,33 @@
  out.newLine();%0A
+%0A
         for(int 
@@ -2044,32 +2044,33 @@
 ne();%0A        %7D%0A
+%0A
         for(int 
@@ -2074,19 +2074,15 @@
 nt i
-dx
  = 0; i
-dx
  %3C s
@@ -2095,18 +2095,16 @@
 atrix; i
-dx
 ++) %7B%0A  
@@ -2140,10 +2140,8 @@
 ss%5Bi
-dx
 %5D);%0A

clean code