@@ -234,30 +234,15 @@ public static Object toClassWithRealEquals(@Nullable Object obj) {
234
234
235
235
@ SuppressWarnings ("unchecked" )
236
236
public static int compare (@ Nullable Object fieldValue , @ Nullable Object comparand ) {
237
- if (fieldValue == null ) {
238
- if (comparand == null ) {
239
- return 0 ;
240
- } else {
241
- return -1 ;
242
- }
243
- } else if (comparand == null ) {
244
- return 1 ;
245
- } else {
246
- return toComparable (fieldValue ).compareTo (toComparable (comparand ));
247
- }
237
+ return toComparable (fieldValue ).compareTo (toComparable (comparand ));
248
238
}
249
239
250
- @ Nullable
251
240
@ SpotBugsSuppressWarnings ("NP_BOOLEAN_RETURN_NULL" )
252
- private static Boolean compareEquals (Object value , Object comparand ) {
253
- if (value == null || comparand == null ) {
254
- return null ;
241
+ private static boolean compareEquals (@ Nonnull Object value , @ Nonnull Object comparand ) {
242
+ if (value instanceof Message ) {
243
+ return MessageHelpers . compareMessageEquals ( value , comparand ) ;
255
244
} else {
256
- if (value instanceof Message ) {
257
- return MessageHelpers .compareMessageEquals (value , comparand );
258
- } else {
259
- return toClassWithRealEquals (value ).equals (toClassWithRealEquals (comparand ));
260
- }
245
+ return toClassWithRealEquals (value ).equals (toClassWithRealEquals (comparand ));
261
246
}
262
247
}
263
248
@@ -301,6 +286,9 @@ private static Boolean compareStartsWith(@Nullable Object value, @Nullable Objec
301
286
@ Nullable
302
287
@ SpotBugsSuppressWarnings ("NP_BOOLEAN_RETURN_NULL" )
303
288
private static Boolean compareLike (@ Nullable Object value , @ Nullable Object pattern ) {
289
+ if (value == null ) {
290
+ return null ;
291
+ }
304
292
if (!(value instanceof String )) {
305
293
throw new RecordCoreException ("Illegal comparand value type: " + value );
306
294
}
@@ -639,7 +627,6 @@ public enum Type {
639
627
STARTS_WITH ,
640
628
NOT_NULL (false , true ),
641
629
IS_NULL (true , true ),
642
- NOT_DISTINCT_FROM (false ),
643
630
IN ,
644
631
TEXT_CONTAINS_ALL (true ),
645
632
TEXT_CONTAINS_ALL_WITHIN (true ),
@@ -651,7 +638,9 @@ public enum Type {
651
638
@ API (API .Status .EXPERIMENTAL )
652
639
SORT (false ),
653
640
@ API (API .Status .EXPERIMENTAL )
654
- LIKE ;
641
+ LIKE ,
642
+ IS_DISTINCT_FROM (true ),
643
+ NOT_DISTINCT_FROM (false );
655
644
656
645
@ Nonnull
657
646
private static final Supplier <BiMap <Type , PComparisonType >> protoEnumBiMapSupplier =
@@ -724,30 +713,44 @@ public static Type invertComparisonType(@Nonnull final Comparisons.Type type) {
724
713
@ Nullable
725
714
@ SpotBugsSuppressWarnings ("NP_BOOLEAN_RETURN_NULL" )
726
715
public static Boolean evalComparison (@ Nonnull Type type , @ Nullable Object value , @ Nullable Object comparand ) {
727
- if (value == null ) {
728
- return null ;
729
- }
730
716
switch (type ) {
731
717
case STARTS_WITH :
732
718
return compareStartsWith (value , comparand );
733
719
case IN :
734
720
return compareIn (value , comparand );
735
721
case EQUALS :
722
+ if (value == null || comparand == null ) {
723
+ return null ;
724
+ }
736
725
return compareEquals (value , comparand );
737
726
case NOT_EQUALS :
738
- if (comparand == null ) {
727
+ if (value == null || comparand == null ) {
739
728
return null ;
740
729
}
741
730
return !compareEquals (value , comparand );
731
+ case IS_DISTINCT_FROM :
732
+ return !compareNotDistinctFrom (value , comparand );
742
733
case NOT_DISTINCT_FROM :
743
734
return compareNotDistinctFrom (value , comparand );
744
735
case LESS_THAN :
736
+ if (value == null || comparand == null ) {
737
+ return null ;
738
+ }
745
739
return compare (value , comparand ) < 0 ;
746
740
case LESS_THAN_OR_EQUALS :
741
+ if (value == null || comparand == null ) {
742
+ return null ;
743
+ }
747
744
return compare (value , comparand ) <= 0 ;
748
745
case GREATER_THAN :
746
+ if (value == null || comparand == null ) {
747
+ return null ;
748
+ }
749
749
return compare (value , comparand ) > 0 ;
750
750
case GREATER_THAN_OR_EQUALS :
751
+ if (value == null || comparand == null ) {
752
+ return null ;
753
+ }
751
754
return compare (value , comparand ) >= 0 ;
752
755
case LIKE :
753
756
return compareLike (value , comparand );
0 commit comments