@@ -250,7 +250,7 @@ private ParameterValueProvider<MongoPersistentProperty> getParameterProvider(Mon
250
250
Bson source , DefaultSpELExpressionEvaluator evaluator , ObjectPath path ) {
251
251
252
252
MongoDbPropertyValueProvider provider = new MongoDbPropertyValueProvider (source , evaluator , path );
253
- PersistentEntityParameterValueProvider <MongoPersistentProperty > parameterProvider = new PersistentEntityParameterValueProvider <MongoPersistentProperty >(
253
+ PersistentEntityParameterValueProvider <MongoPersistentProperty > parameterProvider = new PersistentEntityParameterValueProvider <>(
254
254
entity , provider , path .getCurrentObject ());
255
255
256
256
return new ConverterAwareSpELExpressionParameterValueProvider (evaluator , conversionService , parameterProvider ,
@@ -273,7 +273,7 @@ private <S extends Object> S read(final MongoPersistentEntity<S> entity, final D
273
273
DocumentAccessor documentAccessor = new DocumentAccessor (bson );
274
274
275
275
// make sure id property is set before all other properties
276
- Optional <Object > idValue = idProperty .filter (it -> documentAccessor . hasValue ( it ) ).map (it -> {
276
+ Optional <Object > idValue = idProperty .filter (documentAccessor :: hasValue ).map (it -> {
277
277
278
278
Optional <Object > value = getValueInternal (it , bson , evaluator , path );
279
279
accessor .setProperty (it , value );
@@ -285,42 +285,38 @@ private <S extends Object> S read(final MongoPersistentEntity<S> entity, final D
285
285
idValue .isPresent () ? idProperty .map (it -> bson .get (it .getFieldName ())).orElse (null ) : null );
286
286
287
287
// Set properties not already set in the constructor
288
- entity .doWithProperties (new PropertyHandler <MongoPersistentProperty >() {
289
- public void doWithPersistentProperty (MongoPersistentProperty prop ) {
288
+ entity .doWithProperties ((PropertyHandler <MongoPersistentProperty >) prop -> {
290
289
291
- // we skip the id property since it was already set
292
- if (idProperty != null && idProperty .equals (prop )) {
293
- return ;
294
- }
295
-
296
- if (entity .isConstructorArgument (prop ) || !documentAccessor .hasValue (prop )) {
297
- return ;
298
- }
290
+ // we skip the id property since it was already set
291
+ if (idProperty != null && idProperty .equals (prop )) {
292
+ return ;
293
+ }
299
294
300
- accessor .setProperty (prop , getValueInternal (prop , bson , evaluator , currentPath ));
295
+ if (entity .isConstructorArgument (prop ) || !documentAccessor .hasValue (prop )) {
296
+ return ;
301
297
}
298
+
299
+ accessor .setProperty (prop , getValueInternal (prop , bson , evaluator , currentPath ));
302
300
});
303
301
304
302
// Handle associations
305
- entity .doWithAssociations (new AssociationHandler <MongoPersistentProperty >() {
306
- public void doWithAssociation (Association <MongoPersistentProperty > association ) {
303
+ entity .doWithAssociations ((AssociationHandler <MongoPersistentProperty >) association -> {
307
304
308
- final MongoPersistentProperty property = association .getInverse ();
309
- Object value = documentAccessor .get (property );
305
+ final MongoPersistentProperty property = association .getInverse ();
306
+ Object value = documentAccessor .get (property );
310
307
311
- if (value == null || entity .isConstructorArgument (property )) {
312
- return ;
313
- }
308
+ if (value == null || entity .isConstructorArgument (property )) {
309
+ return ;
310
+ }
314
311
315
- DBRef dbref = value instanceof DBRef ? (DBRef ) value : null ;
312
+ DBRef dbref = value instanceof DBRef ? (DBRef ) value : null ;
316
313
317
- DbRefProxyHandler handler = new DefaultDbRefProxyHandler (spELContext , mappingContext ,
318
- MappingMongoConverter .this );
319
- DbRefResolverCallback callback = new DefaultDbRefResolverCallback (bson , currentPath , evaluator ,
320
- MappingMongoConverter .this );
314
+ DbRefProxyHandler handler = new DefaultDbRefProxyHandler (spELContext , mappingContext ,
315
+ MappingMongoConverter .this );
316
+ DbRefResolverCallback callback = new DefaultDbRefResolverCallback (bson , currentPath , evaluator ,
317
+ MappingMongoConverter .this );
321
318
322
- accessor .setProperty (property , dbRefResolver .resolveDbRef (property , dbref , callback , handler ));
323
- }
319
+ accessor .setProperty (property , dbRefResolver .resolveDbRef (property , dbref , callback , handler ));
324
320
});
325
321
326
322
return result ;
@@ -430,31 +426,26 @@ protected void writeInternal(Object obj, final Bson bson, MongoPersistentEntity<
430
426
prop -> dbObjectAccessor .computeIfAbsent (prop , () -> idMapper .convertId (accessor .getProperty (prop ))));
431
427
432
428
// Write the properties
433
- entity .doWithProperties (new PropertyHandler <MongoPersistentProperty >() {
434
- public void doWithPersistentProperty (MongoPersistentProperty prop ) {
429
+ entity .doWithProperties ((PropertyHandler <MongoPersistentProperty >) prop -> {
435
430
436
- if (idProperty .map (it -> it .equals (prop )).orElse (false ) || !prop .isWritable ()) {
437
- return ;
438
- }
431
+ if (idProperty .map (it -> it .equals (prop )).orElse (false ) || !prop .isWritable ()) {
432
+ return ;
433
+ }
439
434
440
- accessor .getProperty (prop ).ifPresent (it -> {
441
- if (!conversions .isSimpleType (it .getClass ())) {
435
+ accessor .getProperty (prop ).ifPresent (it -> {
436
+ if (!conversions .isSimpleType (it .getClass ())) {
442
437
443
- writePropertyInternal (it , bson , prop );
444
- } else {
445
- writeSimpleInternal (it , bson , prop );
446
- }
447
- });
448
- }
438
+ writePropertyInternal (it , bson , prop );
439
+ } else {
440
+ writeSimpleInternal (it , bson , prop );
441
+ }
442
+ });
449
443
});
450
444
451
- entity .doWithAssociations (new AssociationHandler <MongoPersistentProperty >() {
445
+ entity .doWithAssociations (( AssociationHandler <MongoPersistentProperty >) association -> {
452
446
453
- public void doWithAssociation (Association <MongoPersistentProperty > association ) {
454
-
455
- MongoPersistentProperty inverseProp = association .getInverse ();
456
- accessor .getProperty (inverseProp ).ifPresent (it -> writePropertyInternal (it , bson , inverseProp ));
457
- }
447
+ MongoPersistentProperty inverseProp = association .getInverse ();
448
+ accessor .getProperty (inverseProp ).ifPresent (it -> writePropertyInternal (it , bson , inverseProp ));
458
449
});
459
450
}
460
451
@@ -562,7 +553,7 @@ protected List<Object> createCollection(Collection<?> collection, MongoPersisten
562
553
return writeCollectionInternal (collection , Optional .of (property .getTypeInformation ()), new BasicDBList ());
563
554
}
564
555
565
- List <Object > dbList = new ArrayList <Object >( );
556
+ List <Object > dbList = new ArrayList <>( collection . size () );
566
557
567
558
for (Object element : collection ) {
568
559
@@ -624,7 +615,7 @@ protected Bson createMap(Map<Object, Object> map, MongoPersistentProperty proper
624
615
private BasicDBList writeCollectionInternal (Collection <?> source , Optional <TypeInformation <?>> type ,
625
616
BasicDBList sink ) {
626
617
627
- Optional <TypeInformation <?>> componentType = type .flatMap (it -> it . getComponentType () );
618
+ Optional <TypeInformation <?>> componentType = type .flatMap (TypeInformation :: getComponentType );
628
619
629
620
for (Object element : source ) {
630
621
@@ -758,7 +749,7 @@ protected String potentiallyUnescapeMapKey(String source) {
758
749
*/
759
750
protected void addCustomTypeKeyIfNecessary (Optional <TypeInformation <?>> type , Object value , Bson bson ) {
760
751
761
- Optional <Class <?>> actualType = type .map (it -> it . getActualType ()) .map (it -> it . getType () );
752
+ Optional <Class <?>> actualType = type .map (TypeInformation :: getActualType ) .map (TypeInformation :: getType );
762
753
Class <?> reference = actualType .orElse (Object .class );
763
754
Class <?> valueType = ClassUtils .getUserClass (value .getClass ());
764
755
@@ -904,7 +895,7 @@ private Object readCollectionOrArray(TypeInformation<?> targetType, List sourceV
904
895
Class <?> rawComponentType = componentType .getType ();
905
896
906
897
collectionType = Collection .class .isAssignableFrom (collectionType ) ? collectionType : List .class ;
907
- Collection <Object > items = targetType .getType ().isArray () ? new ArrayList <Object >( )
898
+ Collection <Object > items = targetType .getType ().isArray () ? new ArrayList <>( sourceValue . size () )
908
899
: CollectionFactory .createCollection (collectionType , rawComponentType , sourceValue .size ());
909
900
910
901
if (sourceValue .isEmpty ()) {
@@ -964,8 +955,8 @@ protected Map<Object, Object> readMap(TypeInformation<?> type, Bson bson, Object
964
955
Class <?> mapType = typeMapper .readType (bson , type ).getType ();
965
956
966
957
Optional <TypeInformation <?>> valueType = type .getMapValueType ();
967
- Class <?> rawKeyType = type .getComponentType ().map (it -> it . getType () ).orElse (null );
968
- Class <?> rawValueType = type .getMapValueType ().map (it -> it . getType () ).orElse (null );
958
+ Class <?> rawKeyType = type .getComponentType ().map (TypeInformation :: getType ).orElse (null );
959
+ Class <?> rawValueType = type .getMapValueType ().map (TypeInformation :: getType ).orElse (null );
969
960
970
961
Map <String , Object > sourceMap = asMap (bson );
971
962
Map <Object , Object > map = CollectionFactory .createMap (mapType , rawKeyType , sourceMap .keySet ().size ());
@@ -1008,7 +999,7 @@ protected Map<Object, Object> readMap(TypeInformation<?> type, Bson bson, Object
1008
999
}
1009
1000
1010
1001
@ SuppressWarnings ("unchecked" )
1011
- private Map <String , Object > asMap (Bson bson ) {
1002
+ private static Map <String , Object > asMap (Bson bson ) {
1012
1003
1013
1004
if (bson instanceof Document ) {
1014
1005
return (Document ) bson ;
@@ -1022,7 +1013,7 @@ private Map<String, Object> asMap(Bson bson) {
1022
1013
String .format ("Cannot read %s. as map. Given Bson must be a Document or DBObject!" , bson .getClass ()));
1023
1014
}
1024
1015
1025
- private void addToMap (Bson bson , String key , Object value ) {
1016
+ private static void addToMap (Bson bson , String key , Object value ) {
1026
1017
1027
1018
if (bson instanceof Document ) {
1028
1019
((Document ) bson ).put (key , value );
@@ -1037,7 +1028,7 @@ private void addToMap(Bson bson, String key, Object value) {
1037
1028
}
1038
1029
1039
1030
@ SuppressWarnings ("unchecked" )
1040
- private void addAllToMap (Bson bson , Map value ) {
1031
+ private static void addAllToMap (Bson bson , Map value ) {
1041
1032
1042
1033
if (bson instanceof Document ) {
1043
1034
((Document ) bson ).putAll (value );
@@ -1053,7 +1044,7 @@ private void addAllToMap(Bson bson, Map value) {
1053
1044
String .format ("Cannot add all to %s. Given Bson must be a Document or DBObject." , bson .getClass ()));
1054
1045
}
1055
1046
1056
- private void removeFromMap (Bson bson , String key ) {
1047
+ private static void removeFromMap (Bson bson , String key ) {
1057
1048
1058
1049
if (bson instanceof Document ) {
1059
1050
((Document ) bson ).remove (key );
@@ -1120,7 +1111,7 @@ public Object convertToMongoType(Object obj, TypeInformation<?> typeInformation)
1120
1111
1121
1112
if (obj instanceof Map ) {
1122
1113
1123
- Map <Object , Object > converted = new LinkedHashMap <Object , Object >( );
1114
+ Map <Object , Object > converted = new LinkedHashMap <>((( Map ) obj ). size (), 1 );
1124
1115
Document result = new Document ();
1125
1116
1126
1117
for (Map .Entry <Object , Object > entry : ((Map <Object , Object >) obj ).entrySet ()) {
@@ -1254,7 +1245,7 @@ public <T> Optional<T> getPropertyValue(MongoPersistentProperty property) {
1254
1245
return Optional
1255
1246
1256
1247
.ofNullable (property .getSpelExpression ()//
1257
- .map (it -> evaluator . evaluate ( it ) )//
1248
+ .map (evaluator :: evaluate )//
1258
1249
.orElseGet (() -> source .get (property )))//
1259
1250
.map (it -> readValue (it , property .getTypeInformation (), path ));
1260
1251
}
@@ -1337,7 +1328,7 @@ private <T> T readAndConvertDBRef(DBRef dbref, TypeInformation<?> type, ObjectPa
1337
1328
private void bulkReadAndConvertDBRefMapIntoTarget (TypeInformation <?> valueType , Class <?> rawValueType ,
1338
1329
Map <String , Object > sourceMap , Map <Object , Object > targetMap ) {
1339
1330
1340
- LinkedHashMap <String , Object > referenceMap = new LinkedHashMap <String , Object >(sourceMap );
1331
+ LinkedHashMap <String , Object > referenceMap = new LinkedHashMap <>(sourceMap );
1341
1332
List <Object > convertedObjects = bulkReadAndConvertDBRefs ((List <DBRef >) new ArrayList (referenceMap .values ()),
1342
1333
valueType , ObjectPath .ROOT , rawValueType );
1343
1334
int index = 0 ;
@@ -1360,19 +1351,19 @@ private <T> List<T> bulkReadAndConvertDBRefs(List<DBRef> dbrefs, TypeInformation
1360
1351
? Collections .singletonList (readRef (dbrefs .iterator ().next ())) : bulkReadRefs (dbrefs );
1361
1352
String collectionName = dbrefs .iterator ().next ().getCollectionName ();
1362
1353
1363
- List <T > targeList = new ArrayList <T >(dbrefs .size ());
1354
+ List <T > targeList = new ArrayList <>(dbrefs .size ());
1364
1355
1365
1356
for (Document document : referencedRawDocuments ) {
1366
1357
1367
1358
if (document != null ) {
1368
- maybeEmitEvent (new AfterLoadEvent <T >(document , (Class <T >) rawType , collectionName ));
1359
+ maybeEmitEvent (new AfterLoadEvent <>(document , (Class <T >) rawType , collectionName ));
1369
1360
}
1370
1361
1371
1362
final T target = (T ) read (type , document , path );
1372
1363
targeList .add (target );
1373
1364
1374
1365
if (target != null ) {
1375
- maybeEmitEvent (new AfterConvertEvent <T >(document , target , collectionName ));
1366
+ maybeEmitEvent (new AfterConvertEvent <>(document , target , collectionName ));
1376
1367
}
1377
1368
}
1378
1369
@@ -1421,7 +1412,7 @@ private static boolean isCollectionOfDbRefWhereBulkFetchIsPossible(Iterable<Obje
1421
1412
1422
1413
Assert .notNull (source , "Iterable of DBRefs must not be null!" );
1423
1414
1424
- Set <String > collectionsFound = new HashSet <String >();
1415
+ Set <String > collectionsFound = new HashSet <>();
1425
1416
1426
1417
for (Object dbObjItem : source ) {
1427
1418
0 commit comments