Class FList.Cons<E>

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

    public static final class FList.Cons<E>
    extends FList<E>
    Class representing a functional list with a head element and tail list.
    See Also:
    Serialized Form
    • Field Detail

      • head

        private final E head
        The head element
      • tail

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

        private final int size
        The number of elements
    • Constructor Detail

      • Cons

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

      • isEmpty

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

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

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

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

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

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