Polishing.

Invert types to retain check to avoid double negation.

See #4674
Original pull request: #4718
This commit is contained in:
Mark Paluch
2024-06-11 09:30:14 +02:00
parent 03de6f0e5a
commit 3ad09242c1

View File

@@ -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<Class<?>> types = Set.of(Pattern.class, BsonRegularExpression.class);
private final Set<Class<?>> 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());
}
}
}