14
14
15
15
public class BasicDecimal32Vector extends AbstractVector {
16
16
private int scale_ = -1 ;
17
- private int [] values ;
17
+ private int [] unscaledValues ;
18
18
private int size ;
19
19
private int capacity ;
20
20
@@ -27,18 +27,18 @@ public BasicDecimal32Vector(int size, int scale){
27
27
if (scale < 0 || scale > 9 )
28
28
throw new RuntimeException ("Scale " + scale + " is out of bounds, it must be in [0,9]." );
29
29
this .scale_ = scale ;
30
- this .values = new int [size ];
30
+ this .unscaledValues = new int [size ];
31
31
32
- this .size = values .length ;
33
- capacity = values .length ;
32
+ this .size = unscaledValues .length ;
33
+ capacity = unscaledValues .length ;
34
34
}
35
35
36
36
BasicDecimal32Vector (DATA_FORM df , int size ){
37
37
super (df );
38
- values = new int [size ];
38
+ unscaledValues = new int [size ];
39
39
40
- this .size = values .length ;
41
- capacity = values .length ;
40
+ this .size = unscaledValues .length ;
41
+ capacity = unscaledValues .length ;
42
42
}
43
43
44
44
public BasicDecimal32Vector (String [] data , int scale ) {
@@ -48,12 +48,12 @@ public BasicDecimal32Vector(String[] data, int scale) {
48
48
this .scale_ = scale ;
49
49
50
50
int length = data .length ;
51
- values = new int [length ];
51
+ unscaledValues = new int [length ];
52
52
for (int i = 0 ; i < length ; i ++) {
53
53
BigDecimal bd = new BigDecimal (data [i ]);
54
54
BigDecimal multipliedValue = bd .scaleByPowerOfTen (scale ).setScale (0 , RoundingMode .HALF_UP );
55
55
if (multipliedValue .intValue () > Integer .MIN_VALUE && multipliedValue .intValue () < Integer .MAX_VALUE )
56
- values [i ] = multipliedValue .intValue ();
56
+ unscaledValues [i ] = multipliedValue .intValue ();
57
57
}
58
58
59
59
size = length ;
@@ -65,17 +65,17 @@ public BasicDecimal32Vector(String[] data, int scale) {
65
65
if (scale < 0 || scale > 9 )
66
66
throw new RuntimeException ("Scale " + scale + " is out of bounds, it must be in [0,9]." );
67
67
this .scale_ = scale ;
68
- this .values = dataValue ;
69
- this .size = values .length ;
70
- capacity = values .length ;
68
+ this .unscaledValues = dataValue ;
69
+ this .size = unscaledValues .length ;
70
+ capacity = unscaledValues .length ;
71
71
}
72
72
73
73
public BasicDecimal32Vector (DATA_FORM df , ExtendedDataInput in , int extra ) throws IOException {
74
74
super (df );
75
75
int rows = in .readInt ();
76
76
int cols = in .readInt ();
77
77
int size = rows * cols ;
78
- values = new int [size ];
78
+ unscaledValues = new int [size ];
79
79
if (extra != -1 )
80
80
scale_ = extra ;
81
81
else
@@ -92,13 +92,13 @@ public BasicDecimal32Vector(DATA_FORM df, ExtendedDataInput in, int extra) throw
92
92
ByteBuffer byteBuffer = ByteBuffer .wrap (buf , 0 , len ).order (bo );
93
93
for (int i = 0 ; i < end ; i ++){
94
94
int value = byteBuffer .getInt (i * 4 );
95
- values [i + start ] = value ;
95
+ unscaledValues [i + start ] = value ;
96
96
}
97
97
off += len ;
98
98
}
99
99
100
- this .size = values .length ;
101
- capacity = values .length ;
100
+ this .size = unscaledValues .length ;
101
+ capacity = unscaledValues .length ;
102
102
}
103
103
104
104
@ Deprecated
@@ -116,9 +116,9 @@ public BasicDecimal32Vector(double[] data, int scale){
116
116
BigDecimal dbvalue = new BigDecimal (Double .toString (data [i ]));
117
117
newIntValue [i ] = (dbvalue .multiply (pow )).intValue ();
118
118
}
119
- values = newIntValue ;
120
- this .size = values .length ;
121
- capacity = values .length ;
119
+ unscaledValues = newIntValue ;
120
+ this .size = unscaledValues .length ;
121
+ capacity = unscaledValues .length ;
122
122
}
123
123
124
124
@ Override
@@ -132,19 +132,19 @@ public void deserialize(int start, int count, ExtendedDataInput in) throws IOExc
132
132
int end = len / 4 ;
133
133
ByteBuffer byteBuffer = ByteBuffer .wrap (buf , 0 , len ).order (bo );
134
134
for (int i = 0 ; i < end ; i ++)
135
- values [i + start ] = byteBuffer .getInt (i * 4 );
135
+ unscaledValues [i + start ] = byteBuffer .getInt (i * 4 );
136
136
off += len ;
137
137
start += end ;
138
138
}
139
139
140
- this .size = values .length ;
141
- capacity = values .length ;
140
+ this .size = unscaledValues .length ;
141
+ capacity = unscaledValues .length ;
142
142
}
143
143
144
144
@ Override
145
145
protected void writeVectorToOutputStream (ExtendedDataOutput out ) throws IOException {
146
146
int [] data = new int [size ];
147
- System .arraycopy (values , 0 , data , 0 , size );
147
+ System .arraycopy (unscaledValues , 0 , data , 0 , size );
148
148
out .writeInt (scale_ );
149
149
out .writeIntArray (data );
150
150
}
@@ -159,7 +159,7 @@ public Vector getSubVector(int[] indices) {
159
159
int length = indices .length ;
160
160
int [] sub = new int [length ];
161
161
for (int i =0 ; i <length ; ++i )
162
- sub [i ] = values [indices [i ]];
162
+ sub [i ] = unscaledValues [indices [i ]];
163
163
return new BasicDecimal32Vector (sub , scale_ );
164
164
}
165
165
@@ -170,17 +170,17 @@ public int asof(Scalar value) {
170
170
171
171
@ Override
172
172
public boolean isNull (int index ) {
173
- return values [index ] == Integer .MIN_VALUE ;
173
+ return unscaledValues [index ] == Integer .MIN_VALUE ;
174
174
}
175
175
176
176
@ Override
177
177
public void setNull (int index ) {
178
- values [index ] = Integer .MIN_VALUE ;
178
+ unscaledValues [index ] = Integer .MIN_VALUE ;
179
179
}
180
180
181
181
@ Override
182
182
public Entity get (int index ) {
183
- return new BasicDecimal32 (new int []{scale_ , values [index ]});
183
+ return new BasicDecimal32 (new int []{scale_ , unscaledValues [index ]});
184
184
}
185
185
186
186
@ Override
@@ -193,7 +193,7 @@ public void set(int index, Entity value) throws Exception {
193
193
DATA_TYPE type = value .getDataType ();
194
194
if (scale_ < 0 ) scale_ = newScale ;
195
195
if (((Scalar )value ).isNull ())
196
- values [index ] = Integer .MIN_VALUE ;
196
+ unscaledValues [index ] = Integer .MIN_VALUE ;
197
197
else {
198
198
if (scale_ != newScale ) {
199
199
BigInteger newValue = BigInteger .valueOf (((BasicDecimal32 ) (value )).getInt ());
@@ -205,9 +205,9 @@ public void set(int index, Entity value) throws Exception {
205
205
pow = pow .pow (scale_ - newScale );
206
206
newValue = newValue .multiply (pow );
207
207
}
208
- values [index ] = newValue .intValue ();
208
+ unscaledValues [index ] = newValue .intValue ();
209
209
}else {
210
- values [index ] = ((BasicDecimal32 ) value ).getInt ();
210
+ unscaledValues [index ] = ((BasicDecimal32 ) value ).getInt ();
211
211
}
212
212
}
213
213
}
@@ -220,7 +220,7 @@ public Class<?> getElementClass() {
220
220
@ Override
221
221
public void serialize (int start , int count , ExtendedDataOutput out ) throws IOException {
222
222
for (int i = 0 ; i < count ; i ++){
223
- out .writeInt (values [start + i ]);
223
+ out .writeInt (unscaledValues [start + i ]);
224
224
}
225
225
}
226
226
@@ -230,52 +230,52 @@ public int getUnitLength() {
230
230
}
231
231
232
232
public void add (String value ) {
233
- if (size + 1 > capacity && values .length > 0 ) {
234
- values = Arrays .copyOf (values , values .length * 2 );
235
- } else if (values .length <= 0 ){
236
- values = new int [1 ];
233
+ if (size + 1 > capacity && unscaledValues .length > 0 ) {
234
+ unscaledValues = Arrays .copyOf (unscaledValues , unscaledValues .length * 2 );
235
+ } else if (unscaledValues .length <= 0 ){
236
+ unscaledValues = new int [1 ];
237
237
}
238
238
239
- capacity = values .length ;
239
+ capacity = unscaledValues .length ;
240
240
if (value .equals ("0.0" ))
241
- values [size ] = 0 ;
241
+ unscaledValues [size ] = 0 ;
242
242
else if (value .equals ("" ))
243
- values [size ] = Integer .MIN_VALUE ;
243
+ unscaledValues [size ] = Integer .MIN_VALUE ;
244
244
else {
245
245
BigDecimal pow = BigDecimal .TEN .pow (scale_ );
246
246
BigDecimal bd = new BigDecimal (value );
247
247
if (checkDecimal32Range (bd .multiply (pow ).intValue ()))
248
- values [size ] = bd .multiply (pow ).intValue ();
248
+ unscaledValues [size ] = bd .multiply (pow ).intValue ();
249
249
}
250
250
size ++;
251
251
}
252
252
253
253
@ Deprecated
254
254
public void add (double value ) {
255
- if (size + 1 > capacity && values .length > 0 ){
256
- values = Arrays .copyOf (values , values .length * 2 );
257
- }else if (values .length <= 0 ){
258
- values = Arrays .copyOf (values , values .length + 1 );
255
+ if (size + 1 > capacity && unscaledValues .length > 0 ){
256
+ unscaledValues = Arrays .copyOf (unscaledValues , unscaledValues .length * 2 );
257
+ }else if (unscaledValues .length <= 0 ){
258
+ unscaledValues = Arrays .copyOf (unscaledValues , unscaledValues .length + 1 );
259
259
}
260
- capacity = values .length ;
260
+ capacity = unscaledValues .length ;
261
261
if (value == 0.0 )
262
- values [size ] = 0 ;
262
+ unscaledValues [size ] = 0 ;
263
263
else {
264
264
BigDecimal pow = new BigDecimal (1 );
265
265
for (long i = 0 ; i < scale_ ; i ++) {
266
266
pow = pow .multiply (new BigDecimal (10 ));
267
267
}
268
268
BigDecimal dbvalue = new BigDecimal (Double .toString (value ));
269
- values [size ] = (dbvalue .multiply (pow )).intValue ();
269
+ unscaledValues [size ] = (dbvalue .multiply (pow )).intValue ();
270
270
}
271
271
size ++;
272
272
}
273
273
274
274
void addRange (int [] valueList ) {
275
- values = Arrays .copyOf (values , valueList .length + values .length );
276
- System .arraycopy (valueList , 0 , values , size , valueList .length );
275
+ unscaledValues = Arrays .copyOf (unscaledValues , valueList .length + unscaledValues .length );
276
+ System .arraycopy (valueList , 0 , unscaledValues , size , valueList .length );
277
277
size += valueList .length ;
278
- capacity = values .length ;
278
+ capacity = unscaledValues .length ;
279
279
}
280
280
281
281
public void addRange (String [] valueList ) {
@@ -287,10 +287,10 @@ public void addRange(String[] valueList) {
287
287
newIntValue [i ] = bd .multiply (pow ).intValue ();
288
288
289
289
}
290
- values = Arrays .copyOf (values , newIntValue .length + values .length );
291
- System .arraycopy (newIntValue , 0 , values , size , newIntValue .length );
290
+ unscaledValues = Arrays .copyOf (unscaledValues , newIntValue .length + unscaledValues .length );
291
+ System .arraycopy (newIntValue , 0 , unscaledValues , size , newIntValue .length );
292
292
size += newIntValue .length ;
293
- capacity = values .length ;
293
+ capacity = unscaledValues .length ;
294
294
}
295
295
296
296
@ Deprecated
@@ -304,10 +304,10 @@ public void addRange(double[] valueList) {
304
304
BigDecimal dbvalue = new BigDecimal (Double .toString (valueList [i ]));
305
305
newIntValue [i ] = (dbvalue .multiply (pow )).intValue ();
306
306
}
307
- values = Arrays .copyOf (values , newIntValue .length + values .length );
308
- System .arraycopy (newIntValue , 0 , values , size , newIntValue .length );
307
+ unscaledValues = Arrays .copyOf (unscaledValues , newIntValue .length + unscaledValues .length );
308
+ System .arraycopy (newIntValue , 0 , unscaledValues , size , newIntValue .length );
309
309
size += newIntValue .length ;
310
- capacity = values .length ;
310
+ capacity = unscaledValues .length ;
311
311
}
312
312
313
313
@ Override
@@ -337,7 +337,7 @@ public int getScale(){
337
337
@ JsonIgnore
338
338
public int [] getdataArray (){
339
339
int [] data = new int [size ];
340
- System .arraycopy (values , 0 , data , 0 , size );
340
+ System .arraycopy (unscaledValues , 0 , data , 0 , size );
341
341
return data ;
342
342
}
343
343
@@ -371,7 +371,7 @@ public int serialize(int indexStart, int offect, int targetNumElement, NumElemen
371
371
targetNumElement = Math .min ((out .remaining () / getUnitLength ()), targetNumElement );
372
372
for (int i = 0 ; i < targetNumElement ; ++i )
373
373
{
374
- out .putInt (values [indexStart + i ]);
374
+ out .putInt (unscaledValues [indexStart + i ]);
375
375
}
376
376
numElementAndPartial .numElement = targetNumElement ;
377
377
numElementAndPartial .partial = 0 ;
@@ -381,4 +381,8 @@ public int serialize(int indexStart, int offect, int targetNumElement, NumElemen
381
381
private boolean checkDecimal32Range (int value ) {
382
382
return value > Integer .MIN_VALUE && value < Integer .MAX_VALUE ;
383
383
}
384
+
385
+ public int [] getUnscaledValues () {
386
+ return unscaledValues ;
387
+ }
384
388
}
0 commit comments