01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.domutil;
15:
16: import java.util.ListIterator;
17: import java.util.NoSuchElementException;
18: import org.itsnat.impl.core.util.*;
19: import org.w3c.dom.Element;
20:
21: /**
22: *
23: * @author jmarranz
24: */
25: public class ElementListFreeListIteratorImpl extends
26: ElementListFreeIteratorImpl implements ListIterator {
27: protected Element prevElem;
28:
29: /**
30: * Creates a new instance of ElementListFreeListIteratorImpl
31: */
32: public ElementListFreeListIteratorImpl(
33: ElementListFreeInternal list, int nextIndex) {
34: super (list, nextIndex);
35:
36: this .prevElem = list.getElementAt(nextIndex - 1);
37: }
38:
39: public boolean hasPrevious() {
40: return (prevElem != null);
41: }
42:
43: public Object previous() {
44: if (prevElem == null)
45: throw new NoSuchElementException();
46:
47: this .nextIndex--;
48: this .currIndex = nextIndex;
49:
50: this .nextElem = currElem;
51: this .currElem = prevElem;
52: this .prevElem = list.getPreviousSiblingElement(currIndex,
53: currElem); // Devuelve null si no hay más
54:
55: return currElem;
56: }
57:
58: public Object next() {
59: Object res = super .next();
60:
61: this .prevElem = currElem;
62:
63: return res;
64: }
65:
66: public int nextIndex() {
67: return nextIndex;
68: }
69:
70: public int previousIndex() {
71: return nextIndex - 1;
72: }
73:
74: public void set(Object o) {
75: if (currIndex == -1)
76: throw new IllegalStateException(); // Pues es el que queremos cambiar y lo mismo nos lo cargamos antes o bien no hemos llamado a next() nunca
77: ElementPair res = list.setElementAt2(currIndex, (Element) o);
78: this .currElem = res.getNewElem();
79: }
80:
81: public void add(Object o) {
82: Element currElem = (Element) o;
83: this.currElem = list.insertBeforeElement(nextIndex, currElem,
84: nextElem);
85: this.prevElem = this.currElem;
86: nextIndex++;
87: currIndex++;
88: }
89:
90: }
|