@@ -679,17 +679,17 @@ private void readAssociation(Association<MongoPersistentProperty> association, P
679
679
* in between.
680
680
*/
681
681
if (value instanceof Document document ) {
682
- if (property .isMap ()) {
683
- if (document .isEmpty () || document .values (). iterator (). next ( ) instanceof DBRef ) {
682
+ if (property .isMap ()) {
683
+ if (document .isEmpty () || peek ( document .values ()) instanceof DBRef ) {
684
684
accessor .setProperty (property , dbRefResolver .resolveDbRef (property , null , callback , handler ));
685
685
} else {
686
686
accessor .setProperty (property , readMap (context , document , property .getTypeInformation ()));
687
687
}
688
688
} else {
689
689
accessor .setProperty (property , read (property .getActualType (), document ));
690
690
}
691
- } else if (value instanceof Collection <?> collection && collection .size () > 0
692
- && collection . iterator (). next ( ) instanceof Document ) {
691
+ } else if (value instanceof Collection <?> collection && ! collection .isEmpty ()
692
+ && peek ( collection ) instanceof Document ) {
693
693
accessor .setProperty (property , readCollectionOrArray (context , collection , property .getTypeInformation ()));
694
694
} else {
695
695
accessor .setProperty (property , dbRefResolver .resolveDbRef (property , null , callback , handler ));
@@ -722,8 +722,8 @@ public DBRef toDBRef(Object object, @Nullable MongoPersistentProperty referringP
722
722
}
723
723
724
724
// DATAMONGO-913
725
- if (object instanceof LazyLoadingProxy ) {
726
- return (( LazyLoadingProxy ) object ) .toDBRef ();
725
+ if (object instanceof LazyLoadingProxy proxy ) {
726
+ return proxy .toDBRef ();
727
727
}
728
728
729
729
return createDBRef (object , referringProperty );
@@ -1022,11 +1022,13 @@ protected List<Object> createCollection(Collection<?> collection, MongoPersisten
1022
1022
.getPointer ();
1023
1023
}).collect (Collectors .toList ());
1024
1024
1025
- return writeCollectionInternal (targetCollection , TypeInformation .of (DocumentPointer .class ), new ArrayList <>(targetCollection .size ()));
1025
+ return writeCollectionInternal (targetCollection , TypeInformation .of (DocumentPointer .class ),
1026
+ new ArrayList <>(targetCollection .size ()));
1026
1027
}
1027
1028
1028
1029
if (property .hasExplicitWriteTarget ()) {
1029
- return writeCollectionInternal (collection , new FieldTypeInformation <>(property ), new ArrayList <>(collection .size ()));
1030
+ return writeCollectionInternal (collection , new FieldTypeInformation <>(property ),
1031
+ new ArrayList <>(collection .size ()));
1030
1032
}
1031
1033
1032
1034
return writeCollectionInternal (collection , property .getTypeInformation (), new ArrayList <>(collection .size ()));
@@ -1674,7 +1676,7 @@ private Object readDBRef(ConversionContext context, @Nullable DBRef dbref, TypeI
1674
1676
}
1675
1677
1676
1678
List <Object > result = bulkReadAndConvertDBRefs (context , Collections .singletonList (dbref ), type );
1677
- return CollectionUtils .isEmpty (result ) ? null : result . iterator (). next ( );
1679
+ return CollectionUtils .isEmpty (result ) ? null : peek ( result );
1678
1680
}
1679
1681
1680
1682
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
@@ -1699,10 +1701,9 @@ private <T> List<T> bulkReadAndConvertDBRefs(ConversionContext context, List<DBR
1699
1701
return Collections .emptyList ();
1700
1702
}
1701
1703
1702
- List <Document > referencedRawDocuments = dbrefs .size () == 1
1703
- ? Collections .singletonList (readRef (dbrefs .iterator ().next ()))
1704
+ List <Document > referencedRawDocuments = dbrefs .size () == 1 ? Collections .singletonList (readRef (peek (dbrefs )))
1704
1705
: bulkReadRefs (dbrefs );
1705
- String collectionName = dbrefs . iterator (). next ( ).getCollectionName ();
1706
+ String collectionName = peek ( dbrefs ).getCollectionName ();
1706
1707
1707
1708
List <T > targetList = new ArrayList <>(dbrefs .size ());
1708
1709
@@ -1847,6 +1848,10 @@ private static boolean isCollectionOfDbRefWhereBulkFetchIsPossible(Iterable<?> s
1847
1848
return true ;
1848
1849
}
1849
1850
1851
+ private static <T > T peek (Iterable <T > result ) {
1852
+ return result .iterator ().next ();
1853
+ }
1854
+
1850
1855
static Predicate <MongoPersistentProperty > isIdentifier (PersistentEntity <?, ?> entity ) {
1851
1856
return entity ::isIdProperty ;
1852
1857
}
@@ -1925,7 +1930,8 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
1925
1930
1926
1931
public MongoDbPropertyValueProvider withContext (ConversionContext context ) {
1927
1932
1928
- return context == this .context ? this : new MongoDbPropertyValueProvider (context , accessor , evaluator );
1933
+ return context == this .context ? this
1934
+ : new MongoDbPropertyValueProvider (context , accessor , evaluator );
1929
1935
}
1930
1936
}
1931
1937
0 commit comments