/******************************************************************************************************************* * * A facility method that creates a composite {@link PresentationModel} out of a stream of objects. For each object * in the stream, its {@code PresentationModel} is created by means of invoking its {@link Presentable} role. * Then all the {@code PresentationModel}s are aggregated into the composite. * * This method accepts an {@link Iterable}. A function which creates specific roles for each * {@code PresentationModel} can be supplied. The function can return a single role or multiple roles in form of * an {@code Object[]}. * * @param i the {@code Iterable} * @param roleCreator the function to create roles * @return the composite {@code PresentationModel} * ******************************************************************************************************************/ @Nonnull public static <T extends As> PresentationModel toCompositePresentationModel ( final @Nonnull Iterable<T> i, final @Nonnull Function<T, Object> roleCreator) { return StreamSupport.stream(i.spliterator(), false) .map(o -> o.as(Presentable).createPresentationModel(array(roleCreator.apply(o)))) .collect(PresentationModelCollectors.toCompositePresentationModel()); }