Class FSet.Cons<E>

  • Type Parameters:
    E - the element type
    All Implemented Interfaces:
    Serializable, Iterable<E>
    Enclosing class:
    FSet<E>

    public static final class FSet.Cons<E>
    extends FSet<E>
    Class representing a functional set.
    See Also:
    Serialized Form
    • Field Detail

      • head

        private final E head
        The head element
      • tail

        private final FSet<E> tail
        The tail list
      • size

        private final int size
        The number of elements
    • Constructor Detail

      • Cons

        private Cons​(E head,
                     FSet<E> tail)
        Private constructor initializing head and tail.
        Parameters:
        head - the head element
        tail - the tail set
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Returns false as this list is not empty.
        Specified by:
        isEmpty in class FSet<E>
        Returns:
        false
      • size

        public int size()
        Returns the number of elements of this functional set.
        Specified by:
        size in class FSet<E>
        Returns:
        the number of elements in this set.
      • head

        public E head()
        Returns the first element of this set.
        Specified by:
        head in class FSet<E>
        Returns:
        the first element
      • tail

        public FSet<E> tail()
        Returns the tail of this set.
        Specified by:
        tail in class FSet<E>
        Returns:
        the tail
      • hashCode

        public int hashCode()
        Returns a hash code value for the set. It is computed from the hash code of the head element and the hash code of the tail.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code
      • equals

        public boolean equals​(Object obj)
        Indicates whether some other object is "equal to" this set. The object is equal to this set, if it is a functional set and the head element and the tail are equal.
        Overrides:
        equals in class Object
        Returns:
        true if this set is the same as the argument; false otherwise.