33import org .apache .arrow .vector .types .DateUnit ;
44import org .apache .arrow .vector .types .pojo .ArrowType ;
55
6- public class DateDay implements Scalar {
7- protected int value ;
8- protected boolean valid ;
6+ public class DateDay implements Scalar <Integer > {
7+ protected Integer value ;
98
109 public DateDay () {
1110 }
@@ -16,15 +15,15 @@ public DateDay(Object value) throws ValidationException {
1615
1716 @ Override
1817 public String toString () {
19- if (this .valid ) {
20- return Integer . toString ( this .value );
18+ if (this .value != null ) {
19+ return this .value . toString ( );
2120 }
2221 return NULL_VALUE_STRING ;
2322 }
2423
2524 @ Override
2625 public boolean isValid () {
27- return this .valid ;
26+ return this .value != null ;
2827 }
2928
3029 @ Override
@@ -35,20 +34,17 @@ public ArrowType dataType() {
3534 @ Override
3635 public void set (Object value ) throws ValidationException {
3736 if (value == null ) {
38- this .valid = false ;
3937 this .value = 0 ;
4038 return ;
4139 }
4240
43- if (value instanceof Scalar scalar ) {
41+ if (value instanceof Scalar <?> scalar ) {
4442 if (!scalar .isValid ()) {
45- this .valid = false ;
4643 this .value = 0 ;
4744 return ;
4845 }
4946
5047 if (scalar instanceof DateDay date ) {
51- this .valid = date .valid ;
5248 this .value = date .value ;
5349 return ;
5450 }
@@ -58,13 +54,11 @@ public void set(Object value) throws ValidationException {
5854 }
5955
6056 if (value instanceof Integer b ) {
61- this .valid = true ;
6257 this .value = b ;
6358 return ;
6459 }
6560
6661 if (value instanceof CharSequence sequence ) {
67- this .valid = true ;
6862 this .value = Integer .parseInt (sequence .toString ());
6963 return ;
7064 }
@@ -73,23 +67,18 @@ public void set(Object value) throws ValidationException {
7367 }
7468
7569 @ Override
76- public Object get () {
77- if (this .valid ) {
78- return this .value ;
79- }
80- return null ;
70+ public Integer get () {
71+ return this .value ;
8172 }
8273
8374 @ Override
8475 public boolean equals (Object other ) {
85- if (other == null ) {
86- return false ;
87- }
88-
89- if (!(other instanceof DateDay o )) {
90- return false ;
76+ if (other instanceof DateDay o ) {
77+ if (this .value == null ) {
78+ return o .value == null ;
79+ }
80+ return this .value .equals (o .value );
9181 }
92-
93- return (this .valid == o .valid ) && (this .value == o .value );
82+ return false ;
9483 }
9584}
0 commit comments