@@ -41,7 +41,7 @@ public BasicDecimal32Vector(int size, int scale){
4141 public BasicDecimal32Vector (String [] data , int scale ) {
4242 super (DATA_FORM .DF_VECTOR );
4343 if (scale < 0 || scale > 9 ) {
44- throw new RuntimeException ("Scale out of bound (valid range: [0, 9], but get: " + scale + ") " );
44+ throw new RuntimeException ("Scale " + scale + "is out of bounds, it must be in [0,9]. " );
4545 }
4646 scale_ = scale ;
4747
@@ -50,7 +50,9 @@ public BasicDecimal32Vector(String[] data, int scale) {
5050 BigDecimal pow = BigDecimal .TEN .pow (scale_ );
5151 for (int i = 0 ; i < length ; i ++) {
5252 BigDecimal bd = new BigDecimal (data [i ]);
53- values [i ] = bd .multiply (pow ).intValue ();
53+ if (bd .multiply (pow ).intValue () > Integer .MIN_VALUE && bd .multiply (pow ).intValue () < Integer .MAX_VALUE ) {
54+ values [i ] = bd .multiply (pow ).intValue ();
55+ }
5456 }
5557
5658 size = length ;
@@ -180,7 +182,7 @@ public Entity get(int index) {
180182
181183 @ Override
182184 public void set (int index , Entity value ) throws Exception {
183- if (value .getDataType () != DT_DECIMAL32 ) {
185+ if (! value . isScalar () && value .getDataType () != DT_DECIMAL32 ) {
184186 throw new RuntimeException ("value type is not BasicDecimal32!" );
185187 }
186188
@@ -236,21 +238,21 @@ public void add(String value) {
236238 if (scale_ < 0 ){
237239 throw new RuntimeException ("Please set scale first." );
238240 }
239- if (size + 1 > capacity && values .length > 0 ){
241+
242+ if (size + 1 > capacity && values .length > 0 ) {
240243 values = Arrays .copyOf (values , values .length * 2 );
241- }else if (values .length <= 0 ){
242- values = Arrays . copyOf ( values , values . length + 1 ) ;
244+ } else if (values .length <= 0 ){
245+ values = new int [ 1 ] ;
243246 }
247+
244248 capacity = values .length ;
245249 if (value .equals ("0.0" ))
246250 values [size ] = 0 ;
247251 else {
248- BigDecimal pow = new BigDecimal (1 );
249- for (long i = 0 ; i < scale_ ; i ++) {
250- pow = pow .multiply (new BigDecimal (10 ));
251- }
252- BigDecimal dbvalue = new BigDecimal (value );
253- values [size ] = (dbvalue .multiply (pow )).intValue ();
252+ BigDecimal pow = BigDecimal .TEN .pow (scale_ );
253+ BigDecimal bd = new BigDecimal (value );
254+ if (checkDecimal32Range (bd .multiply (pow ).intValue ()))
255+ values [size ] = bd .multiply (pow ).intValue ();
254256 }
255257 size ++;
256258 }
@@ -291,13 +293,12 @@ public void addRange(String[] valueList) {
291293 throw new RuntimeException ("Please set scale first." );
292294 }
293295 int [] newIntValue = new int [valueList .length ];
296+ BigDecimal pow = BigDecimal .TEN .pow (scale_ );
294297 for (int i = 0 ; i < valueList .length ; i ++){
295- BigDecimal pow = new BigDecimal (1 );
296- for (long j = 0 ; j < scale_ ; j ++) {
297- pow = pow .multiply (new BigDecimal (10 ));
298- }
299- BigDecimal dbvalue = new BigDecimal (valueList [i ]);
300- newIntValue [i ] = (dbvalue .multiply (pow )).intValue ();
298+ BigDecimal bd = new BigDecimal (valueList [i ]);
299+ if (checkDecimal32Range (bd .multiply (pow ).intValue ()))
300+ newIntValue [i ] = bd .multiply (pow ).intValue ();
301+
301302 }
302303 values = Arrays .copyOf (values , newIntValue .length + values .length );
303304 System .arraycopy (newIntValue , 0 , values , size , newIntValue .length );
@@ -398,4 +399,8 @@ public int serialize(int indexStart, int offect, int targetNumElement, NumElemen
398399 numElementAndPartial .partial = 0 ;
399400 return targetNumElement * 4 ;
400401 }
402+
403+ private boolean checkDecimal32Range (int value ) {
404+ return value > Integer .MIN_VALUE && value < Integer .MAX_VALUE ;
405+ }
401406}
0 commit comments