jsint
Class Pair

java.lang.Object
  extended byjsint.Pair
All Implemented Interfaces:
SchemePair, java.io.Serializable

public class Pair
extends java.lang.Object
implements java.io.Serializable, SchemePair

A Pair has two fields, first and rest (sometimes called car and cdr). The empty list is represented as a Pair, with both fields empty. (In Scheme it is an error to ask access those fields, but we don't complain.)

Author:
Peter Norvig, Copyright 1998, peter@norvig.com, license subsequently modified by Jscheme project members licensed under zlib licence (see license.txt)
See Also:
Serialized Form

Field Summary
static Pair EMPTY
          The empty list.
 java.lang.Object first
          The first element of the pair.
 java.lang.Object rest
          The other element of the pair.
 
Constructor Summary
Pair(java.lang.Object first, java.lang.Object rest)
          Build a pair from two components.
 
Method Summary
 boolean equals(java.lang.Object that)
          Two pairs are equal if their first and rest fields are (equal?).
 java.lang.Object first()
          Return the second element of a list.
 java.lang.Object getEltNover2(int n)
           
 java.lang.Object getFirst()
          Return the first element of a list.
 java.lang.Object getRest()
          Return the second element of a list.
 int hashCode()
          Lists that are .equals have the same .hashCode().
 boolean isEmpty()
           
 int length()
          The length of a proper list.
 java.lang.Object listTail(int n)
          Find the nth tail of a list, zero-based.
 java.lang.Object nth(int n)
          Find the nth element of a list, zero-based
 java.lang.Object rest()
          Return the second element of a list.
 java.lang.Object reverse()
          Reverse the elements of a list.
 java.lang.Object second()
          Return the second element of a list.
 java.lang.Object setEltNover2(int n, java.lang.Object v)
           
 java.lang.Object setFirst(java.lang.Object x)
          Set the first element of a list.
 java.lang.Object setRest(java.lang.Object x)
          Return the second element of a list.
 java.lang.StringBuffer stringifyPair(boolean quoted, java.lang.StringBuffer buf)
          Build up a String representation of the Pair in a StringBuffer.
 java.lang.Object third()
          Return the third element of a list.
 java.lang.String toString()
          Return a String representation of the pair.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

first

public java.lang.Object first
The first element of the pair.


rest

public java.lang.Object rest
The other element of the pair.


EMPTY

public static final Pair EMPTY
The empty list. It's first and rest fields are also EMPTY.

Constructor Detail

Pair

public Pair(java.lang.Object first,
            java.lang.Object rest)
Build a pair from two components.

Method Detail

getFirst

public java.lang.Object getFirst()
Return the first element of a list.

Specified by:
getFirst in interface SchemePair

getRest

public java.lang.Object getRest()
Return the second element of a list.

Specified by:
getRest in interface SchemePair

setFirst

public java.lang.Object setFirst(java.lang.Object x)
Set the first element of a list.

Specified by:
setFirst in interface SchemePair

setRest

public java.lang.Object setRest(java.lang.Object x)
Return the second element of a list.

Specified by:
setRest in interface SchemePair

first

public java.lang.Object first()
Return the second element of a list.

Specified by:
first in interface SchemePair

rest

public java.lang.Object rest()
Return the second element of a list.

Specified by:
rest in interface SchemePair

second

public java.lang.Object second()
Return the second element of a list.

Specified by:
second in interface SchemePair

third

public java.lang.Object third()
Return the third element of a list.

Specified by:
third in interface SchemePair

reverse

public java.lang.Object reverse()
Reverse the elements of a list.

Specified by:
reverse in interface SchemePair

hashCode

public int hashCode()
Lists that are .equals have the same .hashCode().

Specified by:
hashCode in interface SchemePair

equals

public boolean equals(java.lang.Object that)
Two pairs are equal if their first and rest fields are (equal?).

Specified by:
equals in interface SchemePair

toString

public java.lang.String toString()
Return a String representation of the pair.

Specified by:
toString in interface SchemePair

stringifyPair

public java.lang.StringBuffer stringifyPair(boolean quoted,
                                            java.lang.StringBuffer buf)
Build up a String representation of the Pair in a StringBuffer.

Specified by:
stringifyPair in interface SchemePair

length

public int length()
The length of a proper list.

Specified by:
length in interface SchemePair

nth

public java.lang.Object nth(int n)
Find the nth element of a list, zero-based

Specified by:
nth in interface SchemePair

listTail

public java.lang.Object listTail(int n)
Find the nth tail of a list, zero-based.

Specified by:
listTail in interface SchemePair

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface SchemePair

getEltNover2

public java.lang.Object getEltNover2(int n)
Specified by:
getEltNover2 in interface SchemePair

setEltNover2

public java.lang.Object setEltNover2(int n,
                                     java.lang.Object v)
Specified by:
setEltNover2 in interface SchemePair