Java Reference
In-Depth Information
implementing the collections
api LinkedList class
17.5
In this section we implement the Collections API LinkedList class discussed
in Section 6.5. Although we present lots of code, we described most of the
techniques earlier in this chapter.
As we indicated previously, we need a class to store the basic list node, a
class for the iterator, and a class for the list itself. The skeleton for the
LinkedList class is shown in Figure 17.20. LinkedList implements the List
and Queue interfaces and, as usual, it extends AbstractCollection . Line 5
begins the declaration for the Node class, which is nested and private. Line 7
begins the declaration for the LinkedListIterator , which is a private inner
1 package weiss.util;
2 public class LinkedList<AnyType> extends AbstractCollection<AnyType>
3 implements List<AnyType>, Queue<AnyType>
4 {
5 private static class Node<AnyType>
6 { /* Figure 17.21 */ }
7 private class LinkedListIterator<AnyType> implements ListIterator<AnyType>
8 { /* Figure 17.30 */ }
9
10 public LinkedList( )
11 { /* Figure 17.22 */ }
12 public LinkedList( Collection<? extends AnyType> other )
13 { /* Figure 17.22 */ }
14
15 public int size( )
16 { /* Figure 17.23 */ }
17 public boolean contains( Object x )
18 { /* Figure 17.23 */ }
19 public boolean add( AnyType x )
20 { /* Figure 17.24 */ }
21 public void add( int idx, AnyType x )
22 { /* Figure 17.24 */ }
23 public void addFirst( AnyType x )
24 { /* Figure 17.24 */ }
25 public void addLast( AnyType x )
26 { /* Figure 17.24 */ }
27 public AnyType element( )
28 { /* Added in Java 5; same as getFirst */ }
29 public AnyType getFirst( )
30 { /* Figure 17.25 */ }
31 public AnyType getLast( )
32
{ /* Figure 17.25 */ }
figure 17.20a
Class skeleton for standard LinkedList class ( continues )
 
 
Search WWH ::




Custom Search