}
public void repeatItems(Iterable<T> items, ItemProcessor<T> itemProcessor)
{
Map<T, List<Template>> templatesByItemReplacement= new LinkedHashMap<T, List<Template>>();
TemplateHandler templateHandler= ServiceLocator.getInstance().getTemplateHandler();
Entry<T, List<Template>> entry= null;
Iterator<Entry<T, List<Template>>> entriesIterator= shownTemplates.entrySet().iterator();
if (updating)
{
if (!shownTemplates.isEmpty())
entry= entriesIterator.next();
}
for (T item : items)
{
List<Template> templatesOfItem= templatesByItem.get(item);
if (templatesOfItem == null || templatesOfItem.isEmpty())
{
List<Template> repeatChildren= itemProcessor.getRepeatTemplates(item);
for (Template template : repeatChildren)
templateHandler.makeInvisible(template);
templatesOfItem= templateHandler.cloneTemplates(repeatChildren);
insertTemplates(itemProcessor, item, templatesOfItem, entry);
for (Template repeatChild : templatesOfItem)
templateHandler.makeVisible(repeatChild);
itemProcessor.fillTemplates(item, templatesOfItem);
if (templatesOfItem.size() == 1)
itemProcessor.fillTemplate(item, templatesOfItem.get(0));
}