20
20
import java .util .ArrayList ;
21
21
import java .util .Arrays ;
22
22
import java .util .Collection ;
23
+ import java .util .Iterator ;
23
24
import java .util .LinkedHashMap ;
24
25
import java .util .List ;
26
+ import java .util .Map ;
25
27
import java .util .Map .Entry ;
26
28
import java .util .regex .Pattern ;
27
29
import java .util .stream .Collectors ;
58
60
* @author Christoph Strobl
59
61
* @author Mark Paluch
60
62
* @author Andreas Zink
63
+ * @author Clément Petit
61
64
*/
62
65
public class Criteria implements CriteriaDefinition {
63
66
@@ -901,9 +904,9 @@ private boolean isEqual(Object left, Object right) {
901
904
return right == null ;
902
905
}
903
906
904
- if (Pattern . class . isInstance ( left ) ) {
907
+ if (left instanceof Pattern ) {
905
908
906
- if (!Pattern . class . isInstance (right )) {
909
+ if (!(right instanceof Pattern )) {
907
910
return false ;
908
911
}
909
912
@@ -914,6 +917,46 @@ private boolean isEqual(Object left, Object right) {
914
917
&& leftPattern .flags () == rightPattern .flags ();
915
918
}
916
919
920
+ if (left instanceof Document ) {
921
+ if (!(right instanceof Document )) {
922
+ return false ;
923
+ }
924
+ Document leftDocument = (Document ) left ;
925
+ Document rightDocument = (Document ) right ;
926
+ Iterator leftIterator = leftDocument .entrySet ().iterator ();
927
+ Iterator rightIterator = rightDocument .entrySet ().iterator ();
928
+
929
+ while (leftIterator .hasNext () && rightIterator .hasNext ()) {
930
+ Map .Entry leftEntry = (Map .Entry )leftIterator .next ();
931
+ Map .Entry rightEntry = (Map .Entry )rightIterator .next ();
932
+ if (!isEqual (leftEntry .getKey (), rightEntry .getKey ())) {
933
+ return false ;
934
+ }
935
+ if (!isEqual (leftEntry .getValue (), rightEntry .getValue ())) {
936
+ return false ;
937
+ }
938
+ }
939
+ return !leftIterator .hasNext () && !rightIterator .hasNext ();
940
+ }
941
+
942
+ if (Collection .class .isAssignableFrom (left .getClass ())) {
943
+ if (!Collection .class .isAssignableFrom (right .getClass ())) {
944
+ return false ;
945
+ }
946
+
947
+ Collection leftCollection = (Collection ) left ;
948
+ Collection rightCollection = (Collection ) right ;
949
+ Iterator leftIterator = leftCollection .iterator ();
950
+ Iterator rightIterator = rightCollection .iterator ();
951
+
952
+ while (leftIterator .hasNext () && rightIterator .hasNext ()) {
953
+ if (!isEqual (leftIterator .next (), rightIterator .next ())) {
954
+ return false ;
955
+ }
956
+ }
957
+ return !leftIterator .hasNext () && !rightIterator .hasNext ();
958
+ }
959
+
917
960
return ObjectUtils .nullSafeEquals (left , right );
918
961
}
919
962
0 commit comments