Skip to content

Commit fb598f0

Browse files
author
lucaijun
committed
AJ-464: fix number -2147483648 will cause error and add negative array can not build BasicMonthVector
1 parent a260dc6 commit fb598f0

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

src/com/xxdb/data/BasicIntVector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public BasicIntVector(int[] array, boolean copy){
5454
this.size = values.length;
5555
capaticy = values.length;
5656
}
57+
58+
protected BasicIntVector(DATA_FORM df) {
59+
super(df);
60+
}
5761

5862
protected BasicIntVector(DATA_FORM df, int size){
5963
super(df);

src/com/xxdb/data/BasicMonth.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class BasicMonth extends BasicInt{
2020

2121
public BasicMonth(int year, Month month){
2222
super(year * 12 + month.getValue()-1);
23-
if (getInt() < 0)
23+
if (getInt() < 0 && !isNull())
2424
throw new DateTimeException(String.format("year %d is invalid, it must be non-negative integer", year));
2525
}
2626
public BasicMonth(Calendar calendar){
@@ -36,7 +36,7 @@ public BasicMonth(ExtendedDataInput in) throws IOException {
3636

3737
protected BasicMonth(int value){
3838
super(value);
39-
if (getInt() < 0)
39+
if (getInt() < 0 && !isNull())
4040
throw new DateTimeException(String.format("number %d is invalid, it must be non-negative integer", getInt()));
4141
}
4242

src/com/xxdb/data/BasicMonthVector.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.xxdb.data;
22

33
import java.io.IOException;
4+
import java.time.DateTimeException;
45
import java.time.YearMonth;
56
import java.util.List;
67

@@ -18,17 +19,41 @@ public class BasicMonthVector extends BasicIntVector{
1819
public BasicMonthVector(int size){
1920
super(DATA_FORM.DF_VECTOR, size);
2021
}
21-
22-
public BasicMonthVector(List<Integer> list){
23-
super(list);
22+
23+
public BasicMonthVector(List<Integer> list) {
24+
super(DATA_FORM.DF_VECTOR);
25+
if (list != null) {
26+
values = new int[list.size()];
27+
for (int i = 0; i < list.size(); ++i) {
28+
if (list.get(i) != null) {
29+
if (list.get(i) < 0 && !list.get(i).equals(Integer.MIN_VALUE))
30+
throw new DateTimeException("Arrays cannot contain negative numbers");
31+
else
32+
values[i] = list.get(i);
33+
} else {
34+
values[i] = Integer.MIN_VALUE;
35+
}
36+
}
37+
}
38+
size = values.length;
39+
capaticy = values.length;
2440
}
25-
26-
public BasicMonthVector(int[] array){
27-
super(array);
41+
42+
public BasicMonthVector(int[] array) {
43+
this(array, true);
2844
}
29-
30-
protected BasicMonthVector(int[] array, boolean copy){
31-
super(array, copy);
45+
46+
protected BasicMonthVector(int[] array, boolean copy) {
47+
super(DATA_FORM.DF_VECTOR);
48+
for (int j : array) {
49+
if (j < 0 && j != Integer.MIN_VALUE) throw new DateTimeException("Arrays cannot contain negative numbers");
50+
}
51+
if (copy)
52+
values = array.clone();
53+
else
54+
values = array;
55+
size = values.length;
56+
capaticy = values.length;
3257
}
3358

3459
protected BasicMonthVector(DATA_FORM df, int size){

0 commit comments

Comments
 (0)