@Test public void testOutOfIndex(){ MyIterableLinkedList<String> data = new MyIterableLinkedList<>(); assertThrows(IndexOutOfBoundsException.class, () -> data.get(-5)); assertThrows(IndexOutOfBoundsException.class, () -> data.get(42)); }
public T get(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(); } ListNode current = head; int counter = 0; while (current != null) { if (counter == index) { return current.value; } current = current.next; counter++; } assert false; return null; }
MyIterableLinkedList implements Iterable<T> { public T get(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(); } ListNode current = head; int counter = 0; while (current != null) { if (counter == index) { return current.value; } current = current.next; counter++; } assert false; return null; } }
MyIterableLinkedList implements Iterable<T> { public T get(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(); } ListNode current = head; int counter = 0; while (current != null) { if (counter == index) { return current.value; } current = current.next; counter++; } assert false; return null; }  }
MyIterableLinkedList implements Iterable<T> { public T get(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(); } ListNode current = head; int counter = 0; while (current != null) { if (counter == index) { return current.value; } current = current.next; counter++; } assert false; return null; }  @Override Iterator<T> iterator(); void delete(int index); T get(int index); void add(T value); int size(); boolean isEmpty(); boolean contains(T value); }
MyIterableLinkedList implements Iterable<T> { public T get(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(); } ListNode current = head; int counter = 0; while (current != null) { if (counter == index) { return current.value; } current = current.next; counter++; } assert false; return null; }  @Override Iterator<T> iterator(); void delete(int index); T get(int index); void add(T value); int size(); boolean isEmpty(); boolean contains(T value);  }