OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 25
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.openoffice.spreadsheet;
14
 package org.openconcerto.openoffice.spreadsheet;
15
 
15
 
16
import org.openconcerto.openoffice.ODDocument;
16
import org.openconcerto.openoffice.ODDocument;
-
 
17
import org.openconcerto.utils.CompareUtils;
17
 
18
 
18
import javax.swing.table.AbstractTableModel;
19
import javax.swing.table.AbstractTableModel;
19
 
20
 
20
public class SheetTableModel<D extends ODDocument> extends AbstractTableModel {
21
public class SheetTableModel<D extends ODDocument> extends AbstractTableModel {
21
 
22
 
Line 74... Line 75...
74
            throw new IndexOutOfBoundsException("row :" + rowIndex + " not between 0 and " + (this.getRowCount() - 1));
75
            throw new IndexOutOfBoundsException("row :" + rowIndex + " not between 0 and " + (this.getRowCount() - 1));
75
        if (columnIndex < 0 || columnIndex >= this.getColumnCount())
76
        if (columnIndex < 0 || columnIndex >= this.getColumnCount())
76
            throw new IndexOutOfBoundsException("column: " + columnIndex + " not between 0 and " + (this.getColumnCount() - 1));
77
            throw new IndexOutOfBoundsException("column: " + columnIndex + " not between 0 and " + (this.getColumnCount() - 1));
77
    }
78
    }
78
 
79
 
-
 
80
    @Override
-
 
81
    public int hashCode() {
-
 
82
        final int rowCount = getRowCount();
-
 
83
        final int columnCount = getColumnCount();
-
 
84
        final int prime = 17;
-
 
85
        int result = 1;
-
 
86
        result = prime * result + rowCount;
-
 
87
        result = prime * result + columnCount;
-
 
88
        // use some of the values
-
 
89
        final int maxX = Math.min(4, columnCount);
-
 
90
        final int maxY = Math.min(8, rowCount);
-
 
91
        for (int y = 0; y < maxY; y++) {
-
 
92
            for (int x = 0; x < maxX; x++) {
-
 
93
                final Object v = this.getValueAt(x, y);
-
 
94
                result = prime * result + (v == null ? 0 : v.hashCode());
-
 
95
            }
-
 
96
        }
-
 
97
        return result;
-
 
98
    }
-
 
99
 
-
 
100
    @Override
-
 
101
    public boolean equals(Object obj) {
-
 
102
        if (this == obj)
-
 
103
            return true;
-
 
104
        if (obj == null)
-
 
105
            return false;
-
 
106
        if (!(obj instanceof SheetTableModel))
-
 
107
            return false;
-
 
108
        final SheetTableModel<?> other = (SheetTableModel<?>) obj;
-
 
109
 
-
 
110
        final int rowCount = this.getRowCount();
-
 
111
        final int columnCount = this.getColumnCount();
-
 
112
        if (other.getRowCount() != rowCount || other.getColumnCount() != columnCount)
-
 
113
            return false;
-
 
114
 
-
 
115
        for (int y = 0; y < rowCount; y++) {
-
 
116
            for (int x = 0; x < columnCount; x++) {
-
 
117
                if (!CompareUtils.equals(this.getValueAt(x, y), other.getValueAt(x, y)))
-
 
118
                    return false;
-
 
119
            }
-
 
120
        }
-
 
121
        return true;
-
 
122
    }
-
 
123
 
79
    static public final class MutableTableModel<D extends ODDocument> extends SheetTableModel<D> {
124
    static public final class MutableTableModel<D extends ODDocument> extends SheetTableModel<D> {
80
 
125
 
81
        MutableTableModel(final Table<D> table, final int row, final int column) {
126
        MutableTableModel(final Table<D> table, final int row, final int column) {
82
            super(table, row, column);
127
            super(table, row, column);
83
        }
128
        }