001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.markup.repeater;
018
019import java.util.Iterator;
020
021import org.apache.wicket.model.IModel;
022import org.apache.wicket.util.io.IClusterable;
023
024
025/**
026 * Interface for item reuse strategies.
027 * <p>
028 * <u>Notice:</u> Child items will be rendered in the order they are provided by the returned
029 * iterator, so it is important that the strategy preserve this order
030 * </p>
031 * 
032 * @author Igor Vaynberg (ivaynberg)
033 * 
034 */
035public interface IItemReuseStrategy extends IClusterable
036{
037
038        /**
039         * Returns an iterator over items that will be added to the view. The iterator needs to return
040         * all the items because the old ones are removed prior to the new ones added.
041         * 
042         * @param <T>
043         *            type of Item
044         * 
045         * @param factory
046         *            implementation of IItemFactory
047         * @param newModels
048         *            iterator over models for items
049         * @param existingItems
050         *            iterator over child items
051         * @return iterator over items that will be added after all the old items are moved.
052         */
053        <T> Iterator<Item<T>> getItems(IItemFactory<T> factory, Iterator<IModel<T>> newModels,
054                Iterator<Item<T>> existingItems);
055}