KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > collection > DList


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 //NOTE: Tabs are used instead of spaces for indentation.
25
// Make sure that your editor does not replace tabs with spaces.
26
// Set the tab length using your favourite editor to your
27
// visual preference.
28

29 /*
30  * Filename: DList.java
31  *
32  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
33  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
34  * All rights reserved.
35  *
36  * This software is the confidential and proprietary information
37  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
38  * You shall not disclose such Confidential Information and shall
39  * use it only in accordance with the terms of the license
40  * agreement you entered into with iPlanet/Sun Microsystems.
41  */

42  
43 /**
44  * <BR> <I>$Source: /cvs/glassfish/appserv-commons/src/java/com/sun/enterprise/util/collection/DList.java,v $</I>
45  * @author $Author: tcfujii $
46  * @version $Revision: 1.3 $ $Date: 2005/12/25 04:12:10 $
47  */

48  
49 package com.sun.enterprise.util.collection;
50
51 import java.util.*;
52
53 /**
54  * A DList is an implementation of an unsynchronized doubly linked list. Unlike
55  * java.util.LinkedList, each node in the DList (DListNode) can be delinked
56  * in constant time. However, to do this the application must have the reference
57  * of the node to be delinked. DLists are exrtemely usefull if nodes are
58  * removed/inserted quite frequently. DList is used in the implementation of
59  * com.sun.enterprise.util.cache.AdaptiveCache.
60  */

61 public class DList
62     implements List, DListNodeFactory
63 {
64     
65     protected DListNode first;
66     protected DListNode last;
67     protected int size = 0;
68     protected DListNodeFactory nodeFactory;
69     
70     /**
71      * Create a DList.
72      */

73     public DList() {
74         first = new DListNode(null);
75         last = new DListNode(null);
76         first.next = last;
77         last.prev = first;
78         first.prev = last.next = null;
79         this.nodeFactory = this;
80     }
81     
82     /**
83      * Create a DList.
84      */

85     public DList(DListNode firstNode, DListNode lastNode, DListNodeFactory factory) {
86         initDListWithNodes(firstNode, lastNode, factory);
87     }
88         
89     protected void initDListWithNodes(DListNode firstNode, DListNode lastNode, DListNodeFactory factory) {
90         first = firstNode;
91         last = lastNode;
92         first.next = last;
93         last.prev = first;
94         first.prev = last.next = null;
95         this.nodeFactory = (factory == null) ? this : factory;
96     }
97     
98     
99     /**
100      * Create a DList.
101      */

102     public DList(DListNodeFactory nodeFactory) {
103         first = new DListNode(null);
104         last = new DListNode(null);
105         first.next = last;
106         last.prev = first;
107         first.prev = last.next = null;
108         this.nodeFactory = nodeFactory;
109     }
110     
111     
112     private DList(DListNode firstNode, DListNode lastNode, int size, DListNodeFactory nodeFactory) {
113         first = firstNode;
114         last = lastNode;
115         this.size = size;
116         this.nodeFactory = nodeFactory;
117     }
118     
119     
120     
121     /**
122      * Inserts the object at the specified index. Note that this
123      * method is an O(n) operation as it has to iterate through the nodes
124      * in the list till the appropriate index is reached.
125      * @return The DListNode holding this object or null if the index is invalid.
126      */

127     public void add(int index, Object JavaDoc object) {
128         insertAt(index, object);
129         size++;
130     }
131     
132     /**
133      * Inserts the object at the end of the list.
134      * @return The DListNode holding this object or null if the index is invalid.
135      */

136     public boolean add(Object JavaDoc object) {
137         last.insertBefore(nodeFactory.createDListNode(object));
138         size++;
139         return true;
140     }
141     
142     /**
143      * Inserts the object at the specified index. Note that this
144      * method is an O(n) operation as it has to iterate through the nodes
145      * in the list till the appropriate index is reached.
146      * @return The DListNode holding this object or null if the index is invalid.
147      */

148     public boolean addAll(Collection collection) {
149         Iterator iter = collection.iterator();
150         boolean added = false;
151         while (iter.hasNext()) {
152             add(iter.next());
153             added = true;
154         }
155         
156         size += collection.size();
157         return added;
158     }
159     
160     /**
161      * Inserts the object at the specified index. Note that this
162      * method is an O(n) operation as it has to iterate through the nodes
163      * in the list till the appropriate index is reached.
164      * @return The DListNode holding this object or null if the index is invalid.
165      */

166     public boolean addAll(int index, Collection collection) {
167         DListNode node = getDListNodeAt(index);
168         Iterator iter = collection.iterator();
169         boolean added = iter.hasNext();
170         DListNode head = new DListNode(null);
171         DListNode last = head;
172         while (iter.hasNext()) {
173             last.insertAfter(nodeFactory.createDListNode(iter.next()));
174             last = last.next;
175         }
176         if (head != last) {
177             node.prev.next = head.next;
178             node.prev = last;
179             
180             head.next.prev = node;
181             last.next = node;
182         }
183         
184         size += collection.size();
185         return added;
186     }
187     
188     public void clear() {
189         first.next = last;
190         last.prev = first;
191         size = 0;
192     }
193     
194     public boolean contains(Object JavaDoc o) {
195         return (indexOf(o) != -1);
196     }
197     
198     public boolean containsAll(Collection collection) {
199         Iterator iter = collection.iterator();
200         while (iter.hasNext()) {
201             Object JavaDoc o = iter.next();
202             if (indexOf(o) == -1) {
203                 return false;
204             }
205         }
206         return true;
207     }
208     
209     public boolean equals(Object JavaDoc o) {
210         if (o instanceof List) {
211             List list = (List) o;
212             if (list.size() != size()) {
213                 return false;
214             }
215             
216             Object JavaDoc myObj = null, otherObj = null;
217             DListNode node = first;
218             for (int i=0; i<size; i++) {
219                 myObj = node.next.object;
220                 otherObj = list.get(i);
221                 if (! myObj.equals(otherObj)) {
222                     return false;
223                 }
224                 node = node.next;
225             }
226             return true;
227         }
228         return false;
229     }
230     
231     public int hashCode() {
232         int hashCode = 1;
233         DListNode node = first;
234         Object JavaDoc myObj = null;
235         for (int i=0; i<size; i++) {
236             myObj = node.next.object;
237             hashCode = 31*hashCode + (myObj==null ? 0 : myObj.hashCode());
238             node = node.next;
239         }
240         return hashCode;
241     }
242     
243     /**
244      * Return the object at the specified index
245      * @param The index between 0 and size()-1
246      */

247     public Object JavaDoc get(int index) {
248         DListNode node = getDListNodeAt(index);
249         return (node == null) ? null : node.object;
250     }
251     
252     
253     /**
254      * Obtains the index at which this object appears in the list. The method relies on the
255      * equals() method to identify objects in the list. Note that this
256      * method is an O(n) operation as it has to iterate through the nodes
257      * in the list till a match is found.
258      * @return The (0 based) index at which this object appears in the list -1 if not found.
259      */

260     public int indexOf(Object JavaDoc o) {
261         int index = 0;
262         for (DListNode node = first.next; node != last; node = node.next) {
263             if (node.object.equals(o)) {
264                 return index;
265             }
266             index++;
267         }
268         return -1;
269     }
270     
271     /**
272      * Returns true if this list contains no elements.
273      * @return true if this list contains no elements false otherwise.
274      */

275     public boolean isEmpty() {
276         return (this.size > 0);
277     }
278     
279     /**
280      * Returns an iterator for iterating the entries in the list. Each object returned
281      * by the iterator.next() is the actual object added to the list.
282      * @return An iterator.
283      */

284     public Iterator iterator() {
285         return new DListIterator(first, last, false, 0);
286     }
287     
288     /**
289      * Returns the index in this list of the last occurrence of the specified element,
290      * or -1 if this list does not contain this element. More formally, returns the highest
291      * index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
292      * @param element to search for.
293      * @return the index in this list of the last occurrence of the specified element,
294      * or -1 if this list does not contain this element.
295      */

296     public int lastIndexOf(Object JavaDoc obj) {
297         int index = size - 1;
298         for (DListNode node = last.prev; node != first; node = node.prev) {
299             if (node.object.equals(obj)) {
300                 return index;
301             }
302             index--;
303         }
304         return -1;
305     }
306     
307     /**
308      * Returns a list iterator of the elements in this list (in proper sequence).
309      * retrieve the object.
310      * @return A ListIterator.
311      */

312     public ListIterator listIterator() {
313         return new DListIterator(first, last, true, 0);
314     }
315     
316     /**
317      * Returns a list iterator of the elements in this list (in proper sequence), starting
318      * at the specified position in this list. The specified index indicates the first element
319      * that would be returned by an initial call to the next method. An initial call to the
320      * previous method would return the element with the specified index minus one.
321      * @param index of first element to be returned from the list iterator (by a call to the next method).
322      * @return a list iterator of the elements in this list (in proper sequence), starting
323         at the specified position in this list.
324      */

325     public ListIterator listIterator(int index) {
326         return new DListIterator(first, last, true, index);
327     }
328     
329     /**
330      * Removes the element at the specified position in this list (optional operation).
331      * Shifts any subsequent elements to the left (subtracts one from their indices).
332      * @return the element that was removed from the list.
333      */

334     public Object JavaDoc remove(int index) {
335         DListNode node = getDListNodeAt(index);
336         node.delink();
337         size--;
338         Object JavaDoc object = node.object;
339         destroyDListNode(node);
340         return object;
341     }
342
343     /**
344      * Removes the first occurrence in this list of the specified element (optional operation).
345      * If this list does not contain the element, it is unchanged. More formally,
346      * removes the element with the lowest index i such that
347      * (o==null ? get(i)==null : o.equals(get(i))) (if such an element exists).
348      * @return true if this list contained the specified element.
349      */

350     public boolean remove(Object JavaDoc object) {
351         DListNode node = getDListNode(object);
352         if (node == null) {
353             return false;
354         } else {
355             node.delink();
356             destroyDListNode(node);
357             size--;
358             return true;
359         }
360     }
361
362     public boolean removeAll(Collection collection) {
363         Iterator iter = collection.iterator();
364         boolean removed = false;
365         while (iter.hasNext()) {
366             if (remove(iter.next())) {
367                 size--;
368                 removed = true;
369             }
370         }
371         return removed;
372     }
373
374     public boolean retainAll(Collection collection) {
375         
376         boolean removed = false;
377         DListNode node = first;
378         DListNode dnode = null;
379         while (node.next != last) {
380             dnode = node.next;
381             if (collection.contains(dnode.object)) {
382                 dnode.delink();
383                 destroyDListNode(dnode);
384                 size--;
385                 removed = true;
386             } else {
387                 node = node.next;
388             }
389         }
390         return removed;
391     }
392
393     /**
394      * Return the object at the specified index
395      * @param The index between 0 and size()-1
396      */

397     public Object JavaDoc set(int index, Object JavaDoc object) {
398         DListNode node = getDListNodeAt(index);
399         Object JavaDoc oldObject = (node == null) ? null : node.object;
400         node.object = object;
401         return oldObject;
402     }
403     
404     
405     /**
406      * Inserts the object at the specified index. Note that this
407      * method is an O(n) operation as it has to iterate through the nodes
408      * in the list till the appropriate index is reached.
409      * @return The DListNode holding this object or null if the index is invalid.
410      */

411     public DListNode insertAt(int index, Object JavaDoc object) {
412         if ((index < 0) || (index >= size)) {
413             return null;
414         }
415         int mid = size >> 1; //Divide by 2!!
416
DListNode node = null;
417         if (index <= mid) {
418             node = first.next;
419             for (int i=0; i<index ; i++) {
420                 node = node.next;
421             }
422         } else {
423             index = size - index - 1;
424             node = last.prev;
425             for (int i=0; i<index ; i++) {
426                 node = node.prev;
427             }
428         }
429         DListNode newNode = nodeFactory.createDListNode(object);
430         node.insertBefore(newNode);
431         size++;
432         return newNode;
433     }
434     
435     /**
436      * Obtain the size of the list.
437      * @return The number of entries in the list.
438      */

439     public int size() {
440         return size;
441     }
442     
443     
444     /**
445      * Returns a view of the portion of this list between the specified fromIndex,
446      * inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the
447      * returned list is empty.) The returned list is backed by this list, so changes
448      * in the returned list are reflected in this list, and vice-versa. The returned list supports
449      * all of the optional list operations supported by this list.
450      * <p> This method eliminates the need for explicit range operations (of the sort
451      * that commonly exist for arrays). Any operation that expects a list can be used as a
452      * range operation by passing a subList view instead of a whole list. For example,
453      * the following idiom removes a range of elements from a list:
454      * <p> list.subList(from, to).clear();
455      * <p>Similar idioms may be constructed for indexOf and lastIndexOf, and all of the
456      * algorithms in the Collections class can be applied to a subList.
457      * <p>The semantics of this list returned by this method become undefined if the backing
458      * list (i.e., this list) is structurally modified in any way other than via the
459      * returned list. (Structural modifications are those that change the size of this
460      * list, or otherwise perturb it in such a fashion that iterations in progress may yield
461      * incorrect results.)
462      * @param low endpoint (inclusive) of the subList.
463      * @param high endpoint (exclusive) of the subList.
464      */

465     public List subList(int fromIndex, int toIndex) {
466         System.out.println("subList(" + fromIndex + ", " + toIndex + ")");
467         DListNode startNode = getDListNodeAt(fromIndex);
468         System.out.println("nodeAt(" + fromIndex + "): " + startNode.object);
469         DListNode toNode = getDListNodeAt(toIndex);
470         System.out.println("nodeAt(" + toIndex + "): " + toNode.object);
471         return new DList(startNode.prev, toNode, toIndex - fromIndex, nodeFactory);
472     }
473     
474     
475     
476     /**
477      * Returns an array containing all of the elements in this collection. If the collection
478      * makes any guarantees as to what order its elements are returned by its iterator, this
479      * method must return the elements in the same order.
480      * <p> The returned array will be "safe" in that no references to it are maintained by this
481      * collection. (In other words, this method must allocate a new array even if this
482      * collection is backed by an array). The caller is thus free to modify the returned array.
483      * @return an array containing all of the elements in this collection.
484      */

485     public Object JavaDoc[] toArray() {
486         Object JavaDoc[] array = new Object JavaDoc[size];
487         int index = 0;
488         for (DListNode node = first.next; node != last; node = node.next) {
489             array[index++] = node.object;
490         }
491         return array;
492     }
493     
494     /**
495      * Returns an array containing all of the elements in this collection whose runtime type
496      * is that of the specified array. If the collection fits in the specified array, it is
497      * returned therein. Otherwise, a new array is allocated with the runtime type of the
498      * specified array and the size of this collection.
499      * <p> If this collection fits in the specified array with room to spare (i.e., the
500      * array has more elements than this collection), the element in the array immediately
501      * following the end of the collection is set to null. This is useful in determining
502      * the length of this collection only if the caller knows that this collection does
503      * not contain any null elements.)
504      * <p> If this collection makes any guarantees as to what order its elements are returned
505      * by its iterator, this method must return the elements in the same order.
506      * <p>Like the toArray method, this method acts as bridge between array-based and
507      * collection-based APIs. Further, this method allows precise control over the runtime
508      * type of the output array, and may, under certain circumstances, be used to save allocation costs.
509      * <p>Suppose l is a List known to contain only strings. The following code can be
510      * used to dump the list into a newly allocated array of String:
511      * <p>String[] x = (String[]) v.toArray(new String[0]);
512      * @return an array containing all of the elements in this collection.
513      */

514     public Object JavaDoc[] toArray(Object JavaDoc[] array) {
515         
516         if (array.length < size) {
517             array = (Object JavaDoc[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), size);
518         }
519         
520         int index = 0;
521         for (DListNode node = first.next; node != last; node = node.next) {
522             array[index++] = node.object;
523         }
524
525         if (array.length > size) {
526             array[size] = null;
527         }
528             
529         return array;
530
531     }
532     
533
534     /*******************************************************************************************************/
535     /*******************************************************************************************************/
536     /*******************************************************************************************************/
537     /*******************************************************************************************************/
538     /*******************************************************************************************************/
539
540     public DListNode createDListNode(Object JavaDoc object) {
541         return new DListNode(object);
542     }
543     
544     public void destroyDListNode(DListNode node) {
545     }
546     
547     public DListNodeFactory getDListNodeFactory() {
548         return this.nodeFactory;
549     }
550     
551     public void setDListNodeFactory(DListNodeFactory nodeFactory) {
552         this.nodeFactory = nodeFactory;
553     }
554     
555     /**
556      * Add a DListNode as the first node in the list.
557      * @param node The node to be added.
558      */

559     public void addAsFirstNode(DListNode node) {
560         DListNode fNode = first.next;
561         node.next = fNode;
562         node.prev = first;
563         fNode.prev = first.next = node;
564         size++;
565     }
566
567     /**
568      * Add an object as the first node in the list.
569      * @param object The object to be added.
570      * @return The DListNode enclosing the object. This
571      * DListNode object can later be used to delink
572      * the object from the list in constant time.
573      */

574     public DListNode addAsFirstObject(Object JavaDoc object) {
575         DListNode node = nodeFactory.createDListNode(object);
576         addAsFirstNode(node);
577         return node;
578     }
579     
580     /**
581      * Add a DListNode as the last node in the list.
582      * @param node The node to be added.
583      */

584     public void addAsLastNode(DListNode node) {
585         DListNode lNode = last.prev;
586         node.next = last;
587         node.prev = lNode;
588         lNode.next = last.prev = node;
589         size++;
590     }
591     
592     /**
593      * Add an object as the last node in the list.
594      * @param object The object to be added.
595      * @return The DListNode enclosing the object. This
596      * DListNode object can later be used to delink
597      * the object from the list in constant time.
598      */

599     public DListNode addAsLastObject(Object JavaDoc obj) {
600         DListNode node= nodeFactory.createDListNode(obj);
601         addAsLastNode(node);
602         return node;
603     }
604     
605     /**
606      * Removes the first DListNode from the list.
607      * @return The DListNode at the head of the list or null if the list is empty.
608      */

609     public DListNode delinkFirstNode() {
610         if (size > 0) {
611             DListNode node = first.next;
612             node.delink();
613             size--;
614             return node;
615         }
616         return null;
617     }
618     
619     /**
620      * Removes the first object from the list.
621      * @return The object at the head of the list or null if the list is empty.
622      */

623     public Object JavaDoc removeFirstObject() {
624         DListNode node = delinkFirstNode();
625         if (node == null) {
626             return null;
627         } else {
628             Object JavaDoc object = node.object;
629             destroyDListNode(node);
630             return object;
631         }
632     }
633     
634     
635     /**
636      * Removes the last DListNode from the list.
637      * @return The DListNode at the tail of the list or null if the list is empty.
638      */

639     public DListNode delinkLastNode() {
640         if (size > 0) {
641             DListNode node = last.prev;
642             node.delink();
643             size--;
644             return node;
645         }
646         return null;
647     }
648     
649     /**
650      * Removes the last object from the list.
651      * @return The object at the tail of the list or null if the list is empty.
652      */

653     public Object JavaDoc removeLastObject() {
654         DListNode node = delinkLastNode();
655         if (node == null) {
656             return null;
657         } else {
658             Object JavaDoc object = node.object;
659             destroyDListNode(node);
660             return object;
661         }
662     }
663         
664
665     /**
666      * Obtains the DListNode that contains this object. The method relies on the
667      * equals() method to identify objects in the list. Note that this
668      * method is an O(n) operation as it has to iterate through the nodes
669      * in the list till a match is found.
670      * @return The DListNode holding this object or null if the object is not in the list.
671      */

672     public DListNode getDListNode(Object JavaDoc o) {
673         for (DListNode node = first.next; node != last; node = node.next) {
674             if (node.object.equals(o)) {
675                 return node;
676             }
677         }
678         return null;
679     }
680     
681     public void delink(DListNode node) {
682         node.delink();
683         size--;
684     }
685     
686     /**
687      * Obtains the DListNode at the specified index. Note that this
688      * method is an O(n) operation as it has to iterate through the nodes
689      * in the list till a match is found.
690      * @return The DListNode at the specifed index or null if the index is invalid.
691      */

692     public DListNode getDListNodeAt(int index) {
693         if ((index < 0) || (index >= size)) {
694             throw new ArrayIndexOutOfBoundsException JavaDoc("DList size: " + size + "; index: " + index);
695         }
696         int mid = size >> 1; //Divide by 2!!
697
DListNode node = null;
698         if (index <= mid) {
699             node = first.next;
700             for (int i=0; i<index ; i++) {
701                 node = node.next;
702             }
703         } else {
704             index = size - index - 1;
705             node = last.prev;
706             for (int i=0; i<index ; i++) {
707                 node = node.prev;
708             }
709         }
710         return node;
711     }
712     
713     public DListNode getFirstDListNode() {
714         return (size == 0) ? null : first.next;
715     }
716     
717     public DListNode getLastDListNode() {
718         return (size == 0) ? null : last.prev;
719     }
720     
721     public DListNode getNextNode(DListNode node) {
722         DListNode nextNode = node.next;
723         return (nextNode == last) ? null : nextNode;
724     }
725     
726     public DListNode getPreviousNode(DListNode node) {
727         DListNode prevNode = node.prev;
728         return (prevNode == first) ? null : prevNode;
729     }
730     
731     /**
732      * Returns an iterator for iterating the entries in the list. Each object returned
733      * by the iterator.next() is an instance of DListNode. Use DListNode.object to
734      * retrieve the object.
735      * @return An iterator.
736      */

737     public Iterator nodeIterator() {
738         return new DListIterator( first, last, true, 0);
739     }
740     
741
742     
743     
744     
745     
746     /************************************************************************/
747     /* ************** AN INNER CLASS FOR SUPPORTING ITERATOR ************** */
748     
749     private class DListIterator
750         implements java.util.ListIterator JavaDoc
751     {
752         DListNode firstNode;
753         DListNode lastNode;
754         DListNode currentNode;
755         boolean toReturnNode;
756         int currentIndex = -1;
757         
758         DListIterator(DListNode firstNode, DListNode lastNode, boolean toReturnNode, int skip) {
759             this.firstNode = this.currentNode = firstNode;
760             this.lastNode = lastNode;
761             this.toReturnNode = toReturnNode;
762             
763             for (int i=0; i<skip; i++) {
764                 currentNode = currentNode.next;
765             }
766             this.currentIndex = skip;
767             
768         }
769         
770         DListIterator(int startIndex, int endIndex, boolean toReturnNode, int skip) {
771             this.firstNode = this.currentNode = firstNode;
772             this.lastNode = getDListNodeAt(endIndex);
773             this.toReturnNode = toReturnNode;
774             
775             for (int i=0; i<skip; i++) {
776                 currentNode = currentNode.next;
777             }
778             this.currentIndex = skip;
779             
780         }
781         
782         public void add(Object JavaDoc obj) {
783             currentNode.insertAfter(nodeFactory.createDListNode(obj));
784         }
785         
786         public boolean hasNext() {
787             return (currentNode.next != lastNode);
788         }
789         
790         public boolean hasPrevious() {
791             return (currentNode != firstNode);
792         }
793         
794         public Object JavaDoc next() {
795             if (currentNode.next == lastNode) {
796                 throw new java.util.NoSuchElementException JavaDoc("No next after this element");
797             }
798             currentNode = currentNode.next;
799             currentIndex++;
800             return (toReturnNode ? currentNode : currentNode.object);
801         }
802         
803         public int nextIndex() {
804             return (currentIndex+1);
805         }
806         
807         public Object JavaDoc previous() {
808             if (currentNode == firstNode) {
809                 throw new java.util.NoSuchElementException JavaDoc("No previous before this element");
810             }
811             DListNode node = currentNode;
812             currentNode = currentNode.prev;
813             currentIndex--;
814             return (toReturnNode ? node : node.object);
815         }
816         
817         public int previousIndex() {
818             return (currentIndex-1);
819         }
820         
821         public void remove() {
822             throw new UnsupportedOperationException JavaDoc("list.remove() not supported by DList iterator....");
823         }
824         
825         public void set(Object JavaDoc o) {
826             throw new UnsupportedOperationException JavaDoc("list.remove() not supported by DList iterator....");
827         }
828     }
829
830
831 }
Popular Tags