From ad45069f503a61b5d3829912a016f3be019bb020 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 11 Jun 2024 09:30:14 +0200 Subject: [PATCH] Polishing. Invert types to retain check to avoid double negation. See #4674 Original pull request: #4718 --- .../data/mongodb/core/convert/QueryMapper.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java index 32738d8b0..d8135849b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java @@ -816,7 +816,7 @@ public class QueryMapper { @Nullable public Object convertId(@Nullable Object id, Class targetType) { - if (!SpecialTypeTreatment.INSTANCE.isConversionCandidate(id)) { + if (Quirks.skipConversion(id)) { return id; } @@ -881,8 +881,7 @@ public class QueryMapper { private Object applyFieldTargetTypeHintToValue(Field documentField, @Nullable Object value) { if (value == null || documentField.getProperty() == null || !documentField.getProperty().hasExplicitWriteTarget() - || value instanceof Document || value instanceof DBObject - || !SpecialTypeTreatment.INSTANCE.isConversionCandidate(value)) { + || value instanceof Document || value instanceof DBObject || Quirks.skipConversion(value)) { return value; } @@ -1611,20 +1610,19 @@ public class QueryMapper { } /* - * Types that must not be converted + * Types that must not be converted. */ - enum SpecialTypeTreatment { + static class Quirks { - INSTANCE; + private static final Set> types = Set.of(Pattern.class, BsonRegularExpression.class); - private final Set> types = Set.of(Pattern.class, BsonRegularExpression.class); + static boolean skipConversion(@Nullable Object value) { - boolean isConversionCandidate(@Nullable Object value) { if (value == null) { return false; } - return !types.contains(value.getClass()); + return types.contains(value.getClass()); } } }