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 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 final boolean[] data) {
50 this.rows = rows;
51 this.columns = columns;
52 this.nnz = nnz;
53 this.rowIndexes = rowIndexes;
54 this.columnIndexes = columnIndexes;
55 this.data = data;
56 }
57
58
59
60
61
62
63 public OctaveSparseBoolean(final int rows,
64 final int columns,
65 final int nnz) {
66
67 this(rows, columns, 0, new int[nnz], new int[nnz], new boolean[nnz]);
68 }
69
70 @Override
71 public OctaveSparseBoolean shallowCopy() {
72 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 this.data [nnz] = value;
88 this.rowIndexes [nnz] = row;
89 this.columnIndexes[nnz] = column;
90 ++this.nnz;
91 }
92
93
94
95
96 public int getRows() {
97 return this.rows;
98 }
99
100
101
102
103 public int getColumns() {
104 return this.columns;
105 }
106
107
108
109
110 public int getNnz() {
111 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 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 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 return this.data;
142 }
143
144 @Override
145 public int hashCode() {
146 int result = 1;
147 result = PRIME * result + Arrays.hashCode(columnIndexes);
148 result = PRIME * result + columns;
149 result = PRIME * result + Arrays.hashCode(data);
150 result = PRIME * result + nnz;
151 result = PRIME * result + Arrays.hashCode(rowIndexes);
152 result = PRIME * result + rows;
153 return result;
154 }
155
156 @Override
157 @SuppressWarnings("PMD.NPathComplexity")
158 public boolean equals(final Object obj) {
159 if (this == obj) {
160 return true;
161 }
162 if (obj == null) {
163 return false;
164 }
165 if (getClass() != obj.getClass()) {
166 return false;
167 }
168 final OctaveSparseBoolean other = (OctaveSparseBoolean) obj;
169 if (!Arrays.equals(this.columnIndexes, other.columnIndexes)) {
170 return false;
171 }
172 if (this.columns != other.columns) {
173 return false;
174 }
175 if (!Arrays.equals(this.data, other.data)) {
176 return false;
177 }
178 if (this.nnz != other.nnz) {
179 return false;
180 }
181 if (!Arrays.equals(this.rowIndexes, other.rowIndexes)) {
182 return false;
183 }
184 return this.rows == other.rows;
185
186
187
188
189 }
190
191 }