SinglyLinkedList implements PStack<E> { @Override public int size() { return 1 + (next == null ? 0 : next.size()); } private  SinglyLinkedList(E element); private  SinglyLinkedList(E element, SinglyLinkedList<E> next); @Override PStack<E> push(E e); @Override E peek(); @Override E peek(int i); @Override PStack<E> pop(); @Override boolean isEmpty(); @Override void forEach(Consumer<E> action); @Override boolean anyMatch(Predicate<E> predicate); @Override int size(); @Override int hashCode(); @Override String toString(); @Override boolean equals(Object obj);  }
@Test void size() { PStack<Object> s = PCollections.emptyStack(); assertThat(s.size()).isZero(); s = s.push(new Object()); assertThat(s.size()).isEqualTo(1); s = s.push(new Object()); assertThat(s.size()).isEqualTo(2); s = s.pop().pop(); assertThat(s.size()).isZero(); }