SinglyLinkedList implements PStack<E> { @Override public PStack<E> push(E e) { Objects.requireNonNull(e); return new SinglyLinkedList<>(e, this); } 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 equality() { Object a = new Object(); Object b = new Object(); Object c = new Object(); PStack<Object> s1 = PCollections.emptyStack().push(b).push(a); PStack<Object> s2 = PCollections.emptyStack().push(b).push(a); assertThat(s1) .isNotNull() .isEqualTo(s2) .isEqualTo(s1) .hasSameHashCodeAs(s2) .hasSameHashCodeAs(s2); s1 = PCollections.emptyStack().push(b).push(a); s2 = PCollections.emptyStack().push(c).push(a); assertThat(s1).isNotEqualTo(s2); }