Package gnu.lists

Class Pair

  • All Implemented Interfaces:
    BoundedHashable, Consumable, Sequence<java.lang.Object>, java.io.Externalizable, java.io.Serializable, java.lang.Comparable, java.lang.Iterable<java.lang.Object>, java.util.Collection<java.lang.Object>, java.util.List<java.lang.Object>
    Direct Known Subclasses:
    ImmutablePair, Translator.FormStack

    public class Pair
    extends LList
    implements java.io.Externalizable
    A "pair" object, as used in Lisp-like languages. When used to implement a list, the 'car' field contains an element's value, and the 'cdr' field points to either the next Pair or LList.Empty (which represents the end of the list). (The names "car" and "cdr" [pronounced "coulder"] are historical; better names might be "value" and "next".) While a Pair is normally usued to implement a linked list, sometimes the 'cdr' field points to some other non-list object; this is traditionally callled a "dotted list".
    See Also:
    Serialized Form
    • Field Detail

      • car

        protected java.lang.Object car
      • cdr

        protected java.lang.Object cdr
      • incompleteListMarker

        public static final Pair incompleteListMarker
        A special pair used to indicate incomplete input.
    • Constructor Detail

      • Pair

        public Pair​(java.lang.Object carval,
                    java.lang.Object cdrval)
      • Pair

        public Pair()
    • Method Detail

      • getCar

        public java.lang.Object getCar()
      • getCdr

        public java.lang.Object getCdr()
      • setCar

        public void setCar​(java.lang.Object car)
      • setCdr

        public void setCdr​(java.lang.Object cdr)
      • setCarBackdoor

        public void setCarBackdoor​(java.lang.Object car)
        May go away soon.
      • setCdrBackdoor

        public void setCdrBackdoor​(java.lang.Object cdr)
      • size

        public int size()
        Description copied from interface: Sequence
        See java.util.List.
        Specified by:
        size in interface java.util.Collection<java.lang.Object>
        Specified by:
        size in interface java.util.List<java.lang.Object>
        Specified by:
        size in interface Sequence<java.lang.Object>
        Overrides:
        size in class LList
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Sequence
        True is this sequence contains no elements.
        Specified by:
        isEmpty in interface java.util.Collection<java.lang.Object>
        Specified by:
        isEmpty in interface java.util.List<java.lang.Object>
        Specified by:
        isEmpty in interface Sequence<java.lang.Object>
        Overrides:
        isEmpty in class LList
      • length

        public int length()
      • hasNext

        public boolean hasNext​(int ipos)
        Overrides:
        hasNext in class LList
      • nextPos

        public int nextPos​(int ipos)
        Description copied from class: AbstractSequence
        Return the next position following the argument. The new position has the isAfter property. The argument is implicitly released (as in releasePos). Returns 0 if we are already at end of file.
        Overrides:
        nextPos in class LList
      • getPosNext

        public java.lang.Object getPosNext​(int ipos)
        Description copied from class: AbstractSequence
        Get the element following the specified position.
        Overrides:
        getPosNext in class LList
        Parameters:
        ipos - the specified position.
        Returns:
        the following element, or eofValue if there is none. Called by SeqPosition.getNext. FIXME Should change eof handling so return type can be E.
      • getPosPrevious

        public java.lang.Object getPosPrevious​(int ipos)
        Description copied from class: AbstractSequence
        Get the element before the specified position.
        Overrides:
        getPosPrevious in class LList
        Parameters:
        ipos - the specified position.
        Returns:
        the following element, or eofValue if there is none. FIXME Should change eof handling so return type can be E.
      • lastPair

        public Pair lastPair()
      • equals

        public static boolean equals​(Pair pair1,
                                     Pair pair2)
      • compareTo

        public static int compareTo​(Pair pair1,
                                    Pair pair2)
      • compareTo

        public int compareTo​(java.lang.Object obj)
        Specified by:
        compareTo in interface java.lang.Comparable
        Overrides:
        compareTo in class LList
      • get

        public java.lang.Object get​(int index)
        Description copied from interface: Sequence
        See java.util.List.
        Specified by:
        get in interface java.util.List<java.lang.Object>
        Specified by:
        get in interface Sequence<java.lang.Object>
        Overrides:
        get in class LList
      • equals

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.util.Collection<java.lang.Object>
        Specified by:
        equals in interface java.util.List<java.lang.Object>
        Overrides:
        equals in class LList
      • make

        public static Pair make​(java.lang.Object car,
                                java.lang.Object cdr)
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<java.lang.Object>
        Specified by:
        toArray in interface java.util.List<java.lang.Object>
        Overrides:
        toArray in class AbstractSequence<java.lang.Object>
      • toArray

        public java.lang.Object[] toArray​(java.lang.Object[] arr)
        Specified by:
        toArray in interface java.util.Collection<java.lang.Object>
        Specified by:
        toArray in interface java.util.List<java.lang.Object>
        Overrides:
        toArray in class AbstractSequence<java.lang.Object>
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class LList
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Overrides:
        readExternal in class LList
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readResolve

        public java.lang.Object readResolve()
                                     throws java.io.ObjectStreamException
        Needed to override readResolve in LList.
        Overrides:
        readResolve in class LList
        Throws:
        java.io.ObjectStreamException