@Test public void fill() { { List<String> from = Arrays.asList("a", "b", "c"); SingleLinkedList<String> list = new SingleLinkedList<>(from); List<String> to = new ArrayList<>(); list.fill(to); assertThat(list.size(), is(3)); assertThat(list.get(0), is("a")); assertThat(list.get(1), is("b")); assertThat(list.get(2), is("c")); assertThat(to, is(from)); } { SingleLinkedList<String> list = new SingleLinkedList<>(); List<String> to = new ArrayList<>(); list.fill(to); assertThat(list.size(), is(0)); assertThat(to.size(), is(0)); } }
public <C extends Collection<? super E>> C fill(C target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } for (Node<E> node = head; node != null; node = node.next) { target.add(node.value); } return target; }
SingleLinkedList implements Iterable<E>, Serializable { public <C extends Collection<? super E>> C fill(C target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } for (Node<E> node = head; node != null; node = node.next) { target.add(node.value); } return target; } }
SingleLinkedList implements Iterable<E>, Serializable { public <C extends Collection<? super E>> C fill(C target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } for (Node<E> node = head; node != null; node = node.next) { target.add(node.value); } return target; } SingleLinkedList();  SingleLinkedList(List<? extends E> list);  SingleLinkedList(Iterable<? extends E> iterable); private  SingleLinkedList(Node<E> head); }
SingleLinkedList implements Iterable<E>, Serializable { public <C extends Collection<? super E>> C fill(C target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } for (Node<E> node = head; node != null; node = node.next) { target.add(node.value); } return target; } SingleLinkedList();  SingleLinkedList(List<? extends E> list);  SingleLinkedList(Iterable<? extends E> iterable); private  SingleLinkedList(Node<E> head); boolean isEmpty(); int size(); SingleLinkedList<E> concat(E element); E first(); SingleLinkedList<E> rest(); E get(int index); @Override Iterator<E> iterator(); C fill(C target); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
SingleLinkedList implements Iterable<E>, Serializable { public <C extends Collection<? super E>> C fill(C target) { if (target == null) { throw new IllegalArgumentException("target must not be null"); } for (Node<E> node = head; node != null; node = node.next) { target.add(node.value); } return target; } SingleLinkedList();  SingleLinkedList(List<? extends E> list);  SingleLinkedList(Iterable<? extends E> iterable); private  SingleLinkedList(Node<E> head); boolean isEmpty(); int size(); SingleLinkedList<E> concat(E element); E first(); SingleLinkedList<E> rest(); E get(int index); @Override Iterator<E> iterator(); C fill(C target); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }