01: /*
02: * $Id: DefaultItemReuseStrategy.java 458714 2006-01-17 13:47:11Z jcompagner $
03: * $Revision: 458714 $
04: * $Date: 2006-01-17 14:47:11 +0100 (Tue, 17 Jan 2006) $
05: *
06: * ====================================================================
07: * Licensed under the Apache License, Version 2.0 (the "License");
08: * you may not use this file except in compliance with the License.
09: * You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19: package wicket.extensions.markup.html.repeater.refreshing;
20:
21: import java.util.Iterator;
22:
23: import wicket.model.IModel;
24:
25: /**
26: * Implementation of <code>IItemReuseStrategy</code> that returns new items
27: * every time.
28: *
29: * @see wicket.extensions.markup.html.repeater.refreshing.IItemReuseStrategy
30: *
31: * @author Igor Vaynberg (ivaynberg)
32: *
33: */
34: public class DefaultItemReuseStrategy implements IItemReuseStrategy {
35: private static final long serialVersionUID = 1L;
36:
37: private static final IItemReuseStrategy instance = new DefaultItemReuseStrategy();
38:
39: /**
40: * @return static instance of this strategy
41: */
42: public static IItemReuseStrategy getInstance() {
43: return instance;
44: }
45:
46: /**
47: * @see wicket.extensions.markup.html.repeater.refreshing.IItemReuseStrategy#getItems(wicket.extensions.markup.html.repeater.refreshing.IItemFactory,
48: * java.util.Iterator, java.util.Iterator)
49: */
50: public Iterator getItems(final IItemFactory factory,
51: final Iterator newModels, final Iterator existingItems) {
52: return new Iterator() {
53: private int index = 0;
54:
55: public void remove() {
56: throw new UnsupportedOperationException();
57: }
58:
59: public boolean hasNext() {
60: return newModels.hasNext();
61: }
62:
63: public Object next() {
64: final IModel model = (IModel) newModels.next();
65:
66: Item item = factory.newItem(index, model);
67: index++;
68:
69: return item;
70: }
71:
72: };
73: }
74:
75: }
|