Class OrderedPSet<E>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, PCollection<E>, PSet<E>

    public class OrderedPSet<E>
    extends AbstractUnmodifiableSet<E>
    implements PSet<E>, java.io.Serializable
    Like PSet but preserves insertion order. Persistent equivalent of LinkedHashSet.

    (Note: this is different from PSortedSet, which keeps elements in the order specified by Comparable.compareTo(Object) or Comparator.compare(Object, Object).)

    See Also:
    Serialized Form
    • Field Detail

      • EMPTY

        private static final OrderedPSet<java.lang.Object> EMPTY
      • ids

        private final PMap<E,​java.lang.Long> ids
      • elements

        private final PSortedMap<java.lang.Long,​E> elements
    • Constructor Detail

      • OrderedPSet

        private OrderedPSet​(PMap<E,​java.lang.Long> ids,
                            PSortedMap<java.lang.Long,​E> elements)
    • Method Detail

      • from

        public static <E> OrderedPSet<E> from​(java.util.Collection<? extends E> list)
      • singleton

        public static <E> OrderedPSet<E> singleton​(E e)
      • plus

        public OrderedPSet<E> plus​(E e)
        Specified by:
        plus in interface PCollection<E>
        Specified by:
        plus in interface PSet<E>
        Returns:
        a collection which contains e and all of the elements of this
      • plusAll

        public OrderedPSet<E> plusAll​(java.util.Collection<? extends E> list)
        Specified by:
        plusAll in interface PCollection<E>
        Specified by:
        plusAll in interface PSet<E>
        Returns:
        a collection which contains all of the elements of list and this
      • minus

        public OrderedPSet<E> minus​(java.lang.Object e)
        Specified by:
        minus in interface PCollection<E>
        Specified by:
        minus in interface PSet<E>
        Returns:
        this with a single instance of e removed, if e is in this
      • minusAll

        public OrderedPSet<E> minusAll​(java.util.Collection<?> list)
        Specified by:
        minusAll in interface PCollection<E>
        Specified by:
        minusAll in interface PSet<E>
        Returns:
        this with all elements of list completely removed
      • intersect

        public OrderedPSet<E> intersect​(java.util.Collection<? extends E> list)
        Specified by:
        intersect in interface PSet<E>
        Returns:
        the equivalent of this.minusAll(this.minusAll(list)).
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>