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 ;
59
61
* @author Mark Paluch
60
62
* @author Andreas Zink
61
63
* @author Ziemowit Stolarczyk
64
+ * @author Clément Petit
62
65
*/
63
66
public class Criteria implements CriteriaDefinition {
64
67
@@ -976,9 +979,9 @@ private boolean isEqual(Object left, Object right) {
976
979
return right == null ;
977
980
}
978
981
979
- if (Pattern . class . isInstance ( left ) ) {
982
+ if (left instanceof Pattern ) {
980
983
981
- if (!Pattern . class . isInstance (right )) {
984
+ if (!(right instanceof Pattern )) {
982
985
return false ;
983
986
}
984
987
@@ -989,6 +992,46 @@ private boolean isEqual(Object left, Object right) {
989
992
&& leftPattern .flags () == rightPattern .flags ();
990
993
}
991
994
995
+ if (left instanceof Document ) {
996
+ if (!(right instanceof Document )) {
997
+ return false ;
998
+ }
999
+ Document leftDocument = (Document ) left ;
1000
+ Document rightDocument = (Document ) right ;
1001
+ Iterator leftIterator = leftDocument .entrySet ().iterator ();
1002
+ Iterator rightIterator = rightDocument .entrySet ().iterator ();
1003
+
1004
+ while (leftIterator .hasNext () && rightIterator .hasNext ()) {
1005
+ Map .Entry leftEntry = (Map .Entry )leftIterator .next ();
1006
+ Map .Entry rightEntry = (Map .Entry )rightIterator .next ();
1007
+ if (!isEqual (leftEntry .getKey (), rightEntry .getKey ())) {
1008
+ return false ;
1009
+ }
1010
+ if (!isEqual (leftEntry .getValue (), rightEntry .getValue ())) {
1011
+ return false ;
1012
+ }
1013
+ }
1014
+ return !leftIterator .hasNext () && !rightIterator .hasNext ();
1015
+ }
1016
+
1017
+ if (Collection .class .isAssignableFrom (left .getClass ())) {
1018
+ if (!Collection .class .isAssignableFrom (right .getClass ())) {
1019
+ return false ;
1020
+ }
1021
+
1022
+ Collection leftCollection = (Collection ) left ;
1023
+ Collection rightCollection = (Collection ) right ;
1024
+ Iterator leftIterator = leftCollection .iterator ();
1025
+ Iterator rightIterator = rightCollection .iterator ();
1026
+
1027
+ while (leftIterator .hasNext () && rightIterator .hasNext ()) {
1028
+ if (!isEqual (leftIterator .next (), rightIterator .next ())) {
1029
+ return false ;
1030
+ }
1031
+ }
1032
+ return !leftIterator .hasNext () && !rightIterator .hasNext ();
1033
+ }
1034
+
992
1035
return ObjectUtils .nullSafeEquals (left , right );
993
1036
}
994
1037
0 commit comments