Projekt

Obecné

Profil

Stáhnout (2.04 KB) Statistiky
| Větev: | Revize:
1
package vldc.aswi.utils;
2

    
3
import vldc.aswi.model.table.TableColumn;
4
import vldc.aswi.model.table.contingencyTable.ContingencyTableRow;
5
import vldc.aswi.model.table.contingencyTable.ContingencyTableRowCell;
6

    
7
import java.util.ArrayList;
8
import java.util.List;
9
import java.util.Map;
10

    
11
/**
12
 * Class for converting classes.
13
 */
14
public class Converter {
15

    
16
    /**
17
     * Convert Map of TableColumns into list of ContingencyTableRow.
18
     * @param tableColumns - Map of TableColumn.
19
     * @return List of ContingencyTableRow.
20
     */
21
    public static List<ContingencyTableRow> convertTableColumnsToContingencyTableRows(Map<String, TableColumn> tableColumns) {
22
        List<ContingencyTableRow> contingencyTableRows = new ArrayList<>();
23

    
24
        // Create header row with column names.
25
        ContingencyTableRow contingencyTableRowHeader = new ContingencyTableRow(true, 0);
26
        for (String columnName : tableColumns.keySet()) {
27
            contingencyTableRowHeader.addTableRowCell(new ContingencyTableRowCell(columnName, 0));
28
        }
29
        contingencyTableRows.add(contingencyTableRowHeader);
30

    
31
        boolean listExpanded = false;
32

    
33
        // Create contingency table row.
34
        for (TableColumn tableColumn : tableColumns.values()) {
35
            List<String> values = tableColumn.getValues();
36

    
37
            // If list is not created, then create it.
38
            if (!listExpanded) {
39
                for (int j = 0; j < values.size(); j++) {
40
                    ContingencyTableRow contingencyTableRow = new ContingencyTableRow(false, 0);
41
                    contingencyTableRows.add(contingencyTableRow);
42
                }
43
                listExpanded = true;
44
            }
45

    
46
            // Iterate through all values and assign one value per one row.
47
            for (int j = 0; j < values.size(); j++) {
48
                ContingencyTableRowCell contingencyTableRowCell = new ContingencyTableRowCell(values.get(j), 0);
49
                contingencyTableRows.get(j + 1).addTableRowCell(contingencyTableRowCell);
50
            }
51
        }
52

    
53
        return contingencyTableRows;
54
    }
55
}
(1-1/3)