@@ -136,24 +136,29 @@ public static PersistentEntities of(MappingContext<?, ?>... contexts) {
136136 * @return result of the {@link BiFunction}.
137137 */
138138 public <T > Optional <T > mapOnContext (Class <?> type ,
139- BiFunction <MappingContext <?, ? extends PersistentProperty <?>>, PersistentEntity <?, ?>, T > combiner ) {
139+ BiFunction <MappingContext <?, ? extends PersistentProperty <?>>, PersistentEntity <?, ?>, @ Nullable T > combiner ) {
140140
141141 Assert .notNull (type , "Type must not be null" );
142142 Assert .notNull (combiner , "Combining BiFunction must not be null" );
143143
144144 Collection <? extends MappingContext <?, ? extends PersistentProperty <?>>> mappingContexts = getMappingContexts ();
145145
146146 if (mappingContexts .size () == 1 ) {
147- return mappingContexts .stream () //
148- .filter (it -> it .getPersistentEntity (type ) != null ) //
149- .map (it -> combiner .apply (it , it .getRequiredPersistentEntity (type ))) //
150- .findFirst ();
147+ for (MappingContext <?, ? extends PersistentProperty <?>> it : mappingContexts ) {
148+ if (it .getPersistentEntity (type ) != null ) {
149+ return Optional .ofNullable (combiner .apply (it , it .getRequiredPersistentEntity (type )));
150+ }
151+ }
152+ return Optional .empty ();
153+ }
154+
155+ for (MappingContext <?, ? extends PersistentProperty <?>> it : mappingContexts ) {
156+ if (it .hasPersistentEntityFor (type )) {
157+ return Optional .ofNullable (combiner .apply (it , it .getRequiredPersistentEntity (type )));
158+ }
151159 }
152160
153- return mappingContexts .stream () //
154- .filter (it -> it .hasPersistentEntityFor (type )) //
155- .map (it -> combiner .apply (it , it .getRequiredPersistentEntity (type ))) //
156- .findFirst ();
161+ return Optional .empty ();
157162 }
158163
159164 /**
0 commit comments