OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 110 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
110 ilm 1
package org.openconcerto.modules.reports.olap.renderer;
2
 
3
import java.util.HashMap;
4
import java.util.Map;
5
 
6
public class Matrix {
7
    private final Map<Long, MatrixCell> map = new HashMap<Long, MatrixCell>();
8
    private final int width;
9
    private final int height;
10
 
11
    /**
12
     * Creats a Matrix.
13
     *
14
     * @param width Width of matrix
15
     * @param height Height of matrix
16
     */
17
    public Matrix(int width, int height) {
18
        this.width = width;
19
        this.height = height;
20
    }
21
 
22
    /**
23
     * Sets the value at a particular coordinate
24
     *
25
     * @param x X coordinate
26
     * @param y Y coordinate
27
     * @param value Value
28
     */
159 ilm 29
    public void set(int x, int y, String value) {
110 ilm 30
        set(x, y, value, false, false);
31
    }
32
 
33
    /**
34
     * Sets the value at a particular coordinate
35
     *
36
     * @param x X coordinate
37
     * @param y Y coordinate
38
     * @param value Value
39
     * @param right Whether value is right-justified
40
     * @param sameAsPrev Whether value is the same as the previous value. If true, some formats
41
     *        separators between cells
42
     */
43
    void set(int x, int y, String value, boolean right, boolean sameAsPrev) {
44
        map.put(getOffset(x, y), new MatrixCell(value, right, sameAsPrev));
45
        assert x >= 0 && x < width : x;
46
        assert y >= 0 && y < height : y;
47
    }
48
 
49
    private final Long getOffset(int x, int y) {
50
        return Long.valueOf(x + y * width);
51
    }
52
 
53
    /**
54
     * Returns the cell at a particular coordinate.
55
     *
56
     * @param x X coordinate
57
     * @param y Y coordinate
58
     * @return Cell
59
     */
60
    public MatrixCell get(int x, int y) {
61
        return map.get(getOffset(x, y));
62
    }
63
 
64
    public int getWidth() {
65
        return width;
66
    }
67
 
68
    public int getHeight() {
69
        return height;
70
    }
71
}