Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b07f6ea7

Přidáno uživatelem Michal Linha před téměř 4 roky(ů)

re #7885 #8134re #8154 re #8136 added comments and connected switch to allow user to set if he wants to see empty rows or columns in the final table

Zobrazit rozdíly:

src/main/java/vldc/aswi/utils/Converter.java
11 11
import java.util.concurrent.TimeUnit;
12 12

  
13 13
/**
14
 * Class for converting classes.
14
 * Class used to convert original table to contingency table.
15 15
 */
16 16
public class Converter {
17 17

  
18
    /**
19
     * Stores information about whether user set switch to show empty rows and columns to ON.
20
     */
18 21
    private final boolean isNotRemoveEmpty;
19 22

  
23
    /**
24
     * Map of original table.
25
     */
20 26
    private final Map<String, TableColumn> tableColumns;
27

  
28
    /**
29
     * List of names and user names of selected rows.
30
     */
21 31
    private final List<NameUserName> rowNames;
32

  
33
    /**
34
     * List of names and user names of selected columns.
35
     */
22 36
    private final List<NameUserName> columnNames;
37

  
38
    /**
39
     * List of information about selected value and functions.
40
     */
23 41
    private final List<ValueFunction> valueFunctions;
24 42

  
43
    /**
44
     * List of columns node of contingency table going from left to right.
45
     */
25 46
    private List<Node> columnNodes;
47

  
48
    /**
49
     * Formatter of the cell content.
50
     */
26 51
    private final DecimalFormat decimalFormat = new DecimalFormat("0.###");
27 52

  
53
    /**
54
     * Creates and initializes converter.
55
     * @param tableColumns Map of original table.
56
     * @param rowNames List of names and user names of selected rows.
57
     * @param columnNames List of names and user names of selected columns.
58
     * @param valueFunctions List of information about selected value and functions.
59
     * @param isNotRemoveEmpty Stores information about whether user set switch to show empty rows and columns to ON.
60
     */
28 61
    public Converter(Map<String, TableColumn> tableColumns, List<NameUserName> rowNames, List<NameUserName> columnNames,
29 62
                     List<ValueFunction> valueFunctions, boolean isNotRemoveEmpty) {
30 63
        this.tableColumns = tableColumns;
......
126 159
        List<String> prevValues = new ArrayList<>();
127 160
        int prevSize = 0;
128 161
        for (ValueFunction valueFunction : valueFunctions) {
129
            headerRows.get(0).addTableRowCell(new ContingencyTableRowCell(valueFunction.getFunction() + " z " + valueFunction.getName(), 0));
162
            headerRows.get(0).addTableRowCell(new ContingencyTableRowCell(valueFunction.getFunction() + " z " + valueFunction.getParameterName(), 0));
130 163
            for (Node columnNode : columnNodes) {
131 164
                for (int i = 0; i < columnNode.getValues().size(); i++) {
132 165
                    String value = columnNode.getValues().get(i);
......
162 195
                headerRows.get(i).addTableRowCell(new ContingencyTableRowCell("", 1));
163 196
            }
164 197
            headerRows.get(0).addTableRowCell(new ContingencyTableRowCell("Celkový " + valueFunction.getFunction() +
165
                    " z " + valueFunction.getName(), 1));
198
                    " z " + valueFunction.getParameterName(), 1));
166 199
        }
167 200

  
168 201
        return headerRows;
......
315 348
        }
316 349

  
317 350
        DoubleWrapper[] totals = new DoubleWrapper[valueFunctions.size()];
318
        initializeWrapperField(totals);
351
        initializeDoubleWrapperField(totals);
319 352

  
320 353
        DoubleWrapper[] totalsAvgSum = new DoubleWrapper[valueFunctions.size()];
321
        initializeWrapperField(totalsAvgSum);
354
        initializeDoubleWrapperField(totalsAvgSum);
322 355

  
323 356
        boolean[] isFilledValueCells = new boolean[valueFunctions.size()];
324 357
        //hodnota
......
419 452
        return ids;
420 453
    }
421 454

  
455
    /**
456
     * Checks if column is usable by going through all values of columns of a node in the original table.
457
     * @param columnNodeValues Values of a column node.
458
     * @return True if all values of a node are present in the original table columns.
459
     */
422 460
    private boolean checkIfColumnIsUsable(List<String> columnNodeValues) {
423 461
        for (int i = 0; i < tableColumns.get(columnNames.get(0).getName()).getValues().size(); i++) {
424 462
            boolean isUsable = true;
......
437 475
        return false;
438 476
    }
439 477

  
478
    /**
479
     * Computes value of the cell in regards to function.
480
     * @param valueFunction Function that should be computed for a cell.
481
     * @param result Variable to which result is saved.
482
     * @param resultAvgSum Variable to which sum is saved of a function is AVG.
483
     * @param columnNode Column node of a cell.
484
     * @param isFirstMinMax Tells if the counted value is the first value of the MIN or MAX function.
485
     * @param usableID ID of the row in the original table.
486
     * @param isValueTotal Tells if a value is total value for the given function.
487
     * @param isSingleValueRow Tells whether a row only has single value (only represents one column of the original table).
488
     */
440 489
    private void computeValues(ValueFunction valueFunction, DoubleWrapper result, DoubleWrapper resultAvgSum, Node columnNode,
441 490
                               BooleanWrapper isFirstMinMax, int usableID, boolean isValueTotal, boolean isSingleValueRow) {
442 491
        switch (valueFunction.getFunction()) {
......
458 507
        }
459 508
    }
460 509

  
510
    /**
511
     * Generates a cell with filled data.
512
     * @param function Name of the function.
513
     * @param totalResult Result of COUNT function to be saved.
514
     * @param totalResultSum Result of SUM function to be saved.
515
     * @param totalMin Result of MIN function to be saved.
516
     * @param totalMax Result of MAX function to be saved.
517
     * @param totalResultAvgSum Result of sum of AVG function to be saved.
518
     * @param totalResultAvg Result of count of AVG function to be saved.
519
     * @return Generated and filled cell.
520
     */
461 521
    private ContingencyTableRowCell generateFilledCell(String function, double totalResult, double totalResultSum,
462 522
                                                       double totalMin, double totalMax, double totalResultAvgSum,
463 523
                                                       double totalResultAvg) {
......
487 547
        return cell;
488 548
    }
489 549

  
490
    private void initializeWrapperField(DoubleWrapper[] field) {
550
    /**
551
     * Initializes a filled of the values of a DoubleWrapper type.
552
     * @param field Field to be initialized.
553
     */
554
    private void initializeDoubleWrapperField(DoubleWrapper[] field) {
491 555
        for (int i = 0; i < field.length; i++) {
492 556
            field[i] = new DoubleWrapper(0);
493 557
        }
494 558
    }
495 559

  
560
    /**
561
     * Calculates COUNT function.
562
     * @param valueFunction Function that should be computed for a cell.
563
     * @param result Variable to which result is saved.
564
     * @param columnNode Column node of a cell.
565
     * @param isValueTotal Tells if a value is total value for the given function.
566
     * @param isSingleValueRow Tells whether a row only has single value (only represents one column of the original table).
567
     */
496 568
    private void count(ValueFunction valueFunction, DoubleWrapper result, Node columnNode, boolean isValueTotal,
497 569
                       boolean isSingleValueRow) {
498 570
        result.setValue(result.getValue() + 1);
......
504 576
        }
505 577
    }
506 578

  
579
    /**
580
     * Calculates SUM function.
581
     * @param valueFunction Function that should be computed for a cell.
582
     * @param result Variable to which result is saved.
583
     * @param columnNode Column node of a cell.
584
     * @param usableID ID of the row in the original table.
585
     * @param isValueTotal Tells if a value is total value for the given function.
586
     * @param isSingleValueRow Tells whether a row only has single value (only represents one column of the original table).
587
     */
507 588
    private void sum(ValueFunction valueFunction, DoubleWrapper result, Node columnNode, int usableID, boolean isValueTotal,
508 589
                     boolean isSingleValueRow) {
509 590
        if (valueFunction.getType().equals("Číslo")) {
......
517 598
        }
518 599
    }
519 600

  
601
    /**
602
     * Calculates MIN function.
603
     * @param valueFunction Function that should be computed for a cell.
604
     * @param result Variable to which result is saved.
605
     * @param columnNode Column node of a cell.
606
     * @param isFirstMinMax Tells if the counted value is the first value of the MIN or MAX function.
607
     * @param usableID ID of the row in the original table.
608
     * @param isValueTotal Tells if a value is total value for the given function.
609
     * @param isSingleValueRow Tells whether a row only has single value (only represents one column of the original table).
610
     */
520 611
    private void min(ValueFunction valueFunction, DoubleWrapper result, Node columnNode, BooleanWrapper isFirstMinMax,
521 612
                     int usableID, boolean isValueTotal, boolean isSingleValueRow) {
522 613
        if (valueFunction.getType().equals("Číslo")) {
......
546 637
        }
547 638
    }
548 639

  
640
    /**
641
     * Calculates MAX function.
642
     * @param valueFunction Function that should be computed for a cell.
643
     * @param result Variable to which result is saved.
644
     * @param columnNode Column node of a cell.
645
     * @param isFirstMinMax Tells if the counted value is the first value of the MIN or MAX function.
646
     * @param usableID ID of the row in the original table.
647
     * @param isValueTotal Tells if a value is total value for the given function.
648
     * @param isSingleValueRow Tells whether a row only has single value (only represents one column of the original table).
649
     */
549 650
    private void max(ValueFunction valueFunction, DoubleWrapper result, Node columnNode, BooleanWrapper isFirstMinMax,
550 651
                     int usableID, boolean isValueTotal, boolean isSingleValueRow) {
551 652
        if (valueFunction.getType().equals("Číslo")) {
......
575 676
        }
576 677
    }
577 678

  
679
    /**
680
     * Calculates AVG function.
681
     * @param valueFunction Function that should be computed for a cell.
682
     * @param result Variable to which count result is saved.
683
     * @param resultAvgSum Variable to which sum result is saved.
684
     * @param columnNode Column node of a cell.
685
     * @param usableID ID of the row in the original table.
686
     * @param isValueTotal Tells if a value is total value for the given function.
687
     * @param isSingleValueRow Tells whether a row only has single value (only represents one column of the original table).
688
     */
578 689
    private void average(ValueFunction valueFunction, DoubleWrapper result, DoubleWrapper resultAvgSum, Node columnNode,
579 690
                         int usableID, boolean isValueTotal, boolean isSingleValueRow) {
580 691
        if (valueFunction.getType().equals("Číslo")) {
......
591 702
        }
592 703
    }
593 704

  
705
    /**
706
     * Generates a final row, with total values of columns.
707
     * @return Final row filled with data.
708
     */
594 709
    private ContingencyTableRow createFinalRow() {
595 710
        ContingencyTableRow finalRow = new ContingencyTableRow(false, 0);
596 711
        finalRow.addTableRowCell(new ContingencyTableRowCell("Celkem", 1));

Také k dispozici: Unified diff