MCPcopy Create free account
hub / github.com/davidgiven/luje / LinkIterator

Class LinkIterator

lib/java/util/LinkedList.java:51–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 }
50
51 private static final class LinkIterator<ET> implements ListIterator<ET> {
52 int pos, expectedModCount;
53
54 final LinkedList<ET> list;
55
56 Link<ET> link, lastLink;
57
58 LinkIterator(LinkedList<ET> object, int location) {
59 list = object;
60 expectedModCount = list.modCount;
61 if (0 <= location && location <= list.size) {
62 // pos ends up as -1 if list is empty, it ranges from -1 to
63 // list.size - 1
64 // if link == voidLink then pos must == -1
65 link = list.voidLink;
66 if (location < list.size / 2) {
67 for (pos = -1; pos + 1 < location; pos++) {
68 link = link.next;
69 }
70 } else {
71 for (pos = list.size; pos >= location; pos--) {
72 link = link.previous;
73 }
74 }
75 } else {
76 throw new IndexOutOfBoundsException();
77 }
78 }
79
80 public void add(ET object) {
81 if (expectedModCount == list.modCount) {
82 Link<ET> next = link.next;
83 Link<ET> newLink = new Link<ET>(object, link, next);
84 link.next = newLink;
85 next.previous = newLink;
86 link = newLink;
87 lastLink = null;
88 pos++;
89 expectedModCount++;
90 list.size++;
91 list.modCount++;
92 } else {
93 throw new ConcurrentModificationException();
94 }
95 }
96
97 public boolean hasNext() {
98 return link.next != list.voidLink;
99 }
100
101 public boolean hasPrevious() {
102 return link != list.voidLink;
103 }
104
105 public ET next() {
106 if (expectedModCount == list.modCount) {
107 LinkedList.Link<ET> next = link.next;
108 if (next != list.voidLink) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected