| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package eu.simuline.octave.type; |
| 17 | |
|
| 18 | |
import java.util.Arrays; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | 0 | public final class OctaveSparseBoolean implements OctaveObject { |
| 26 | |
|
| 27 | |
private static final int PRIME = 31; |
| 28 | |
|
| 29 | |
private final int rows; |
| 30 | |
|
| 31 | |
private final int columns; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
private int nnz; |
| 37 | |
|
| 38 | |
private final int[] rowIndexes; |
| 39 | |
|
| 40 | |
private final int[] columnIndexes; |
| 41 | |
|
| 42 | |
private final boolean[] data; |
| 43 | |
|
| 44 | |
private OctaveSparseBoolean(final int rows, |
| 45 | |
final int columns, |
| 46 | |
final int nnz, |
| 47 | |
final int[] rowIndexes, |
| 48 | |
final int[] columnIndexes, |
| 49 | 20 | final boolean[] data) { |
| 50 | 20 | this.rows = rows; |
| 51 | 20 | this.columns = columns; |
| 52 | 20 | this.nnz = nnz; |
| 53 | 20 | this.rowIndexes = rowIndexes; |
| 54 | 20 | this.columnIndexes = columnIndexes; |
| 55 | 20 | this.data = data; |
| 56 | 20 | } |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
public OctaveSparseBoolean(final int rows, |
| 64 | |
final int columns, |
| 65 | |
final int nnz) { |
| 66 | |
|
| 67 | 20 | this(rows, columns, 0, new int[nnz], new int[nnz], new boolean[nnz]); |
| 68 | 20 | } |
| 69 | |
|
| 70 | |
@Override |
| 71 | |
public OctaveSparseBoolean shallowCopy() { |
| 72 | 0 | return new OctaveSparseBoolean(this.rows, |
| 73 | |
this.columns, |
| 74 | |
this.nnz, |
| 75 | |
this.rowIndexes, |
| 76 | |
this.columnIndexes, |
| 77 | |
this.data); |
| 78 | |
} |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
@SuppressWarnings("checkstyle:nowhitespaceafter") |
| 86 | |
public void set(final boolean value, final int row, final int column) { |
| 87 | 16 | this.data [nnz] = value; |
| 88 | 16 | this.rowIndexes [nnz] = row; |
| 89 | 16 | this.columnIndexes[nnz] = column; |
| 90 | 16 | ++this.nnz; |
| 91 | 16 | } |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
public int getRows() { |
| 97 | 12 | return this.rows; |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
public int getColumns() { |
| 104 | 12 | return this.columns; |
| 105 | |
} |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
public int getNnz() { |
| 111 | 12 | return this.nnz; |
| 112 | |
} |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
@edu.umd.cs.findbugs.annotations.SuppressWarnings |
| 118 | |
(value = "EI_EXPOSE_REP", |
| 119 | |
justification = "Not woth fixing: class has to be rewritten anyway. ") |
| 120 | |
public int[] getRowIndexes() { |
| 121 | 12 | return this.rowIndexes; |
| 122 | |
} |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
@edu.umd.cs.findbugs.annotations.SuppressWarnings |
| 128 | |
(value = "EI_EXPOSE_REP", |
| 129 | |
justification = "Not woth fixing: class has to be rewritten anyway. ") |
| 130 | |
public int[] getColumnIndexes() { |
| 131 | 12 | return this.columnIndexes; |
| 132 | |
} |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
@edu.umd.cs.findbugs.annotations.SuppressWarnings |
| 138 | |
(value = "EI_EXPOSE_REP", |
| 139 | |
justification = "Not woth fixing: class has to be rewritten anyway. ") |
| 140 | |
public boolean[] getData() { |
| 141 | 12 | return this.data; |
| 142 | |
} |
| 143 | |
|
| 144 | |
@Override |
| 145 | |
public int hashCode() { |
| 146 | 6 | int result = 1; |
| 147 | 6 | result = PRIME * result + Arrays.hashCode(columnIndexes); |
| 148 | 6 | result = PRIME * result + columns; |
| 149 | 6 | result = PRIME * result + Arrays.hashCode(data); |
| 150 | 6 | result = PRIME * result + nnz; |
| 151 | 6 | result = PRIME * result + Arrays.hashCode(rowIndexes); |
| 152 | 6 | result = PRIME * result + rows; |
| 153 | 6 | return result; |
| 154 | |
} |
| 155 | |
|
| 156 | |
@Override |
| 157 | |
@SuppressWarnings("PMD.NPathComplexity") |
| 158 | |
public boolean equals(final Object obj) { |
| 159 | 2 | if (this == obj) { |
| 160 | 0 | return true; |
| 161 | |
} |
| 162 | 2 | if (obj == null) { |
| 163 | 0 | return false; |
| 164 | |
} |
| 165 | 2 | if (getClass() != obj.getClass()) { |
| 166 | 0 | return false; |
| 167 | |
} |
| 168 | 2 | final OctaveSparseBoolean other = (OctaveSparseBoolean) obj; |
| 169 | 2 | if (!Arrays.equals(this.columnIndexes, other.columnIndexes)) { |
| 170 | 0 | return false; |
| 171 | |
} |
| 172 | 2 | if (this.columns != other.columns) { |
| 173 | 0 | return false; |
| 174 | |
} |
| 175 | 2 | if (!Arrays.equals(this.data, other.data)) { |
| 176 | 0 | return false; |
| 177 | |
} |
| 178 | 2 | if (this.nnz != other.nnz) { |
| 179 | 0 | return false; |
| 180 | |
} |
| 181 | 2 | if (!Arrays.equals(this.rowIndexes, other.rowIndexes)) { |
| 182 | 0 | return false; |
| 183 | |
} |
| 184 | 2 | return this.rows == other.rows; |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
} |
| 190 | |
|
| 191 | |
} |