Skip to content

Commit 296e979

Browse files
committed
DATAMONGO-2314 - Polishing.
Reformat code. Remove unnecessary warning suppressions. Switch to diamond syntax. Original pull request: #771.
1 parent 6178285 commit 296e979

File tree

1 file changed

+11
-12
lines changed
  • spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert

1 file changed

+11
-12
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,8 @@ public Document getMappedObject(Bson query, @Nullable MongoPersistentEntity<?> e
132132
// TODO: remove one once QueryMapper can work with Query instances directly
133133
if (Query.isRestrictedTypeKey(key)) {
134134

135-
@SuppressWarnings("unchecked")
136135
Set<Class<?>> restrictedTypes = BsonUtils.get(query, key);
137136
this.converter.getTypeMapper().writeTypeRestrictions(result, restrictedTypes);
138-
139137
continue;
140138
}
141139

@@ -282,7 +280,7 @@ protected Document getMappedKeyword(Keyword keyword, @Nullable MongoPersistentEn
282280
if (keyword.isOrOrNor() || (keyword.hasIterableValue() && !keyword.isGeometry())) {
283281

284282
Iterable<?> conditions = keyword.getValue();
285-
List<Object> newConditions = new ArrayList<Object>();
283+
List<Object> newConditions = new ArrayList<>();
286284

287285
for (Object condition : conditions) {
288286
newConditions.add(isDocument(condition) ? getMappedObject((Document) condition, entity)
@@ -293,11 +291,12 @@ protected Document getMappedKeyword(Keyword keyword, @Nullable MongoPersistentEn
293291
}
294292

295293
if (keyword.isSample()) {
296-
return exampleMapper.getMappedExample(keyword.<Example<?>> getValue(), entity);
294+
return exampleMapper.getMappedExample(keyword.getValue(), entity);
297295
}
298296

299297
if (keyword.isJsonSchema()) {
300-
return schemaMapper.mapSchema(new Document(keyword.getKey(), keyword.getValue()), entity != null ? entity.getType() : Object.class);
298+
return schemaMapper.mapSchema(new Document(keyword.getKey(), keyword.getValue()),
299+
entity != null ? entity.getType() : Object.class);
301300
}
302301

303302
return new Document(keyword.getKey(), convertSimpleOrDocument(keyword.getValue(), entity));
@@ -318,7 +317,7 @@ protected Document getMappedKeyword(Field property, Keyword keyword) {
318317
Object convertedValue = needsAssociationConversion ? convertAssociation(value, property)
319318
: getMappedValue(property.with(keyword.getKey()), value);
320319

321-
if(keyword.isSample() && convertedValue instanceof Document) {
320+
if (keyword.isSample() && convertedValue instanceof Document) {
322321
return (Document) convertedValue;
323322
}
324323

@@ -337,8 +336,8 @@ protected Document getMappedKeyword(Field property, Keyword keyword) {
337336
@SuppressWarnings("unchecked")
338337
protected Object getMappedValue(Field documentField, Object value) {
339338

340-
if(documentField.getProperty() != null && documentField.getProperty().hasExplicitWriteTarget()) {
341-
if(conversionService.canConvert(value.getClass(), documentField.getProperty().getFieldType())) {
339+
if (documentField.getProperty() != null && documentField.getProperty().hasExplicitWriteTarget()) {
340+
if (conversionService.canConvert(value.getClass(), documentField.getProperty().getFieldType())) {
342341
value = conversionService.convert(value, documentField.getProperty().getFieldType());
343342
}
344343
}
@@ -351,7 +350,7 @@ protected Object getMappedValue(Field documentField, Object value) {
351350

352351
if (valueDbo.containsField("$in") || valueDbo.containsField("$nin")) {
353352
String inKey = valueDbo.containsField("$in") ? "$in" : "$nin";
354-
List<Object> ids = new ArrayList<Object>();
353+
List<Object> ids = new ArrayList<>();
355354
for (Object id : (Iterable<?>) valueDbo.get(inKey)) {
356355
ids.add(convertId(id, getIdTypeForField(documentField)));
357356
}
@@ -370,7 +369,7 @@ else if (isDocument(value)) {
370369

371370
if (valueDbo.containsKey("$in") || valueDbo.containsKey("$nin")) {
372371
String inKey = valueDbo.containsKey("$in") ? "$in" : "$nin";
373-
List<Object> ids = new ArrayList<Object>();
372+
List<Object> ids = new ArrayList<>();
374373
for (Object id : (Iterable<?>) valueDbo.get(inKey)) {
375374
ids.add(convertId(id, getIdTypeForField(documentField)));
376375
}
@@ -451,8 +450,8 @@ protected boolean isAssociationConversionNecessary(Field documentField, @Nullabl
451450
@SuppressWarnings("unchecked")
452451
protected Object convertSimpleOrDocument(Object source, @Nullable MongoPersistentEntity<?> entity) {
453452

454-
if(source instanceof Example) {
455-
return exampleMapper.getMappedExample((Example)source, entity);
453+
if (source instanceof Example) {
454+
return exampleMapper.getMappedExample((Example) source, entity);
456455
}
457456

458457
if (source instanceof List) {

0 commit comments

Comments
 (0)