1 /*
2  * Hunt - A refined core library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 module hunt.collection.AbstractSequentialList;
13 
14 import hunt.collection.AbstractList;
15 import hunt.collection.Deque;
16 import hunt.collection.List;
17 
18 import hunt.Exceptions;
19 
20 
21 /**
22  * This class provides a skeletal implementation of the <tt>List</tt>
23  * interface to minimize the effort required to implement this interface
24  * backed by a "sequential access" data store (such as a linked list).  For
25  * random access data (such as an array), <tt>AbstractList</tt> should be used
26  * in preference to this class.<p>
27  *
28  * This class is the opposite of the <tt>AbstractList</tt> class in the sense
29  * that it implements the "random access" methods (<tt>get(int index)</tt>,
30  * <tt>set(int index, E element)</tt>, <tt>add(int index, E element)</tt> and
31  * <tt>remove(int index)</tt>) on top of the list's list iterator, instead of
32  * the other way around.<p>
33  *
34  * To implement a list the programmer needs only to extend this class and
35  * provide implementations for the <tt>listIterator</tt> and <tt>size</tt>
36  * methods.  For an unmodifiable list, the programmer need only implement the
37  * list iterator's <tt>hasNext</tt>, <tt>next</tt>, <tt>hasPrevious</tt>,
38  * <tt>previous</tt> and <tt>index</tt> methods.<p>
39  *
40  * For a modifiable list the programmer should additionally implement the list
41  * iterator's <tt>set</tt> method.  For a variable-size list the programmer
42  * should additionally implement the list iterator's <tt>remove</tt> and
43  * <tt>add</tt> methods.<p>
44  *
45  * The programmer should generally provide a void (no argument) and collection
46  * constructor, as per the recommendation in the <tt>Collection</tt> interface
47  * specification.<p>
48  *
49  * This class is a member of the
50  * <a href="{@docRoot}/../technotes/guides/collections/index.html">
51  * Java Collections Framework</a>.
52  *
53  * @author  Josh Bloch
54  * @author  Neal Gafter
55  * @see Collection
56  * @see List
57  * @see AbstractList
58  * @see AbstractCollection
59  */
60 
61 abstract class AbstractSequentialList(E) : AbstractList!E {
62     /**
63      * Sole constructor.  (For invocation by subclass constructors, typically
64      * implicit.)
65      */
66     protected this() {
67     }
68 
69 //     /**
70 //      * Returns the element at the specified position in this list.
71 //      *
72 //      * <p>This implementation first gets a list iterator pointing to the
73 //      * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
74 //      * the element using <tt>ListIterator.next</tt> and returns it.
75 //      *
76 //      * @throws IndexOutOfBoundsException {@inheritDoc}
77 //      */
78 //     override E get(int index) {
79 //         try {
80 //             return listIterator(index).next();
81 //         } catch (NoSuchElementException exc) {
82 //             throw new IndexOutOfBoundsException("Index: " ~ index);
83 //         }
84 //     }
85 
86 //     /**
87 //      * Replaces the element at the specified position in this list with the
88 //      * specified element (optional operation).
89 //      *
90 //      * <p>This implementation first gets a list iterator pointing to the
91 //      * indexed element (with <tt>listIterator(index)</tt>).  Then, it gets
92 //      * the current element using <tt>ListIterator.next</tt> and replaces it
93 //      * with <tt>ListIterator.set</tt>.
94 //      *
95 //      * <p>Note that this implementation will throw an
96 //      * <tt>UnsupportedOperationException</tt> if the list iterator does not
97 //      * implement the <tt>set</tt> operation.
98 //      *
99 //      * @throws UnsupportedOperationException {@inheritDoc}
100 //      * @throws ClassCastException            {@inheritDoc}
101 //      * @throws NullPointerException          {@inheritDoc}
102 //      * @throws IllegalArgumentException      {@inheritDoc}
103 //      * @throws IndexOutOfBoundsException     {@inheritDoc}
104 //      */
105 //     E set(int index, E element) {
106 //         try {
107 //             ListIterator!E e = listIterator(index);
108 //             E oldVal = e.next();
109 //             e.set(element);
110 //             return oldVal;
111 //         } catch (NoSuchElementException exc) {
112 //             throw new IndexOutOfBoundsException("Index: " ~index);
113 //         }
114 //     }
115 
116 //     /**
117 //      * Inserts the specified element at the specified position in this list
118 //      * (optional operation).  Shifts the element currently at that position
119 //      * (if any) and any subsequent elements to the right (adds one to their
120 //      * indices).
121 //      *
122 //      * <p>This implementation first gets a list iterator pointing to the
123 //      * indexed element (with <tt>listIterator(index)</tt>).  Then, it
124 //      * inserts the specified element with <tt>ListIterator.add</tt>.
125 //      *
126 //      * <p>Note that this implementation will throw an
127 //      * <tt>UnsupportedOperationException</tt> if the list iterator does not
128 //      * implement the <tt>add</tt> operation.
129 //      *
130 //      * @throws UnsupportedOperationException {@inheritDoc}
131 //      * @throws ClassCastException            {@inheritDoc}
132 //      * @throws NullPointerException          {@inheritDoc}
133 //      * @throws IllegalArgumentException      {@inheritDoc}
134 //      * @throws IndexOutOfBoundsException     {@inheritDoc}
135 //      */
136 //     void add(int index, E element) {
137 //         try {
138 //             listIterator(index).add(element);
139 //         } catch (NoSuchElementException exc) {
140 //             throw new IndexOutOfBoundsException("Index: " ~ index.to!string);
141 //         }
142 //     }
143 
144 //     /**
145 //      * Removes the element at the specified position in this list (optional
146 //      * operation).  Shifts any subsequent elements to the left (subtracts one
147 //      * from their indices).  Returns the element that was removed from the
148 //      * list.
149 //      *
150 //      * <p>This implementation first gets a list iterator pointing to the
151 //      * indexed element (with <tt>listIterator(index)</tt>).  Then, it removes
152 //      * the element with <tt>ListIterator.remove</tt>.
153 //      *
154 //      * <p>Note that this implementation will throw an
155 //      * <tt>UnsupportedOperationException</tt> if the list iterator does not
156 //      * implement the <tt>remove</tt> operation.
157 //      *
158 //      * @throws UnsupportedOperationException {@inheritDoc}
159 //      * @throws IndexOutOfBoundsException     {@inheritDoc}
160 //      */
161 //     E remove(int index) {
162 //         try {
163 //             ListIterator!E e = listIterator(index);
164 //             E outCast = e.next();
165 //             e.remove();
166 //             return outCast;
167 //         } catch (NoSuchElementException exc) {
168 //             throw new IndexOutOfBoundsException("Index: " ~ index.to!string);
169 //         }
170 //     }
171 
172 
173 //     // Bulk Operations
174 
175 //     /**
176 //      * Inserts all of the elements in the specified collection into this
177 //      * list at the specified position (optional operation).  Shifts the
178 //      * element currently at that position (if any) and any subsequent
179 //      * elements to the right (increases their indices).  The new elements
180 //      * will appear in this list in the order that they are returned by the
181 //      * specified collection's iterator.  The behavior of this operation is
182 //      * undefined if the specified collection is modified while the
183 //      * operation is in progress.  (Note that this will occur if the specified
184 //      * collection is this list, and it's nonempty.)
185 //      *
186 //      * <p>This implementation gets an iterator over the specified collection and
187 //      * a list iterator over this list pointing to the indexed element (with
188 //      * <tt>listIterator(index)</tt>).  Then, it iterates over the specified
189 //      * collection, inserting the elements obtained from the iterator into this
190 //      * list, one at a time, using <tt>ListIterator.add</tt> followed by
191 //      * <tt>ListIterator.next</tt> (to skip over the added element).
192 //      *
193 //      * <p>Note that this implementation will throw an
194 //      * <tt>UnsupportedOperationException</tt> if the list iterator returned by
195 //      * the <tt>listIterator</tt> method does not implement the <tt>add</tt>
196 //      * operation.
197 //      *
198 //      * @throws UnsupportedOperationException {@inheritDoc}
199 //      * @throws ClassCastException            {@inheritDoc}
200 //      * @throws NullPointerException          {@inheritDoc}
201 //      * @throws IllegalArgumentException      {@inheritDoc}
202 //      * @throws IndexOutOfBoundsException     {@inheritDoc}
203 //      */
204 //     // bool addAll(int index, Collection<E> c) {
205 //     //     try {
206 //     //         bool modified = false;
207 //     //         ListIterator!E e1 = listIterator(index);
208 //     //         Iterator<E> e2 = c.iterator();
209 //     //         while (e2.hasNext()) {
210 //     //             e1.add(e2.next());
211 //     //             modified = true;
212 //     //         }
213 //     //         return modified;
214 //     //     } catch (NoSuchElementException exc) {
215 //     //         throw new IndexOutOfBoundsException("Index: " ~index);
216 //     //     }
217 //     // }
218 
219 
220     // Iterators
221 
222 }