org.abora.white.collection.tables
Class Pair

java.lang.Object
  |
  +--org.abora.white.xpp.basic.Heaper
        |
        +--org.abora.white.collection.tables.Pair

public class Pair
extends Heaper

Sometimes you just want to pass around two things where the language only makes it convenient to pass around one. I know that the proper object-oriented (or even "structured") thing to do would be to create a type specific to the particular kind of pair which is being used for a particular purpose. However, sometimes it just seems like too much trouble. By using Pairs, we import the sins of Lisp. At least we don''t have RPLACA and RPLACD. Unlike Lisp's cons cell's "car" and "cdr", we call our two parts the "left" part and the "right" part. "pair(a,b)->left()" yields a and "pair(a,b)->right()" yields b.

Give us feedback: Should Pairs be removed? Do you know of any justification for them other than a bad simulation of "multiple-return-values" (as in Common Lisp, Forth, Postscript)?

The Pair code is currently in a state of transition. Old code (which we have yet to fix) uses Pairs with NULLs in their parts. Pairs will be changed to outlaw this usage. "fetchLeft" and "fetchRight" exist to support this obsolete usage, but will be retired. Don't use them.


Field Summary
protected  Heaper leftPart
           
protected  Heaper rightPart
           
 
Constructor Summary
protected Pair(Heaper a, Heaper b)
          create a new pair
protected Pair(Rcvr receiver)
           
 
Method Summary
 int actualHashForEqual()
          Defined by subclasses to produce the value returned by hashForEqual.
 Heaper fetchLeft()
          Returns the left part which obsoletely may be NULL
 Heaper fetchRight()
          Returns the right part which obsoletely may be NULL
 boolean isEqual(Heaper other)
          Return true if the two objects are equal.
 Heaper left()
          Returns the left part.
static Pair make(Heaper left, Heaper right)
          Create a new pair.
static Pair pairWithNulls(Heaper left, Heaper right)
          Create a new pair.
 void printOn(java.io.PrintWriter oo)
          This should rarely be overridden.
 Pair reversed()
          Returns a new pair which is the left-right reversal of me.
 Heaper right()
          Returns the right part.
 void sendSelfTo(Xmtr xmtr)
           
 
Methods inherited from class org.abora.white.xpp.basic.Heaper
destroy, destruct, equals, hashForEqual, printContentsOn, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

leftPart

protected Heaper leftPart

rightPart

protected Heaper rightPart
Constructor Detail

Pair

protected Pair(Heaper a,
               Heaper b)
create a new pair


Pair

protected Pair(Rcvr receiver)
Method Detail

make

public static Pair make(Heaper left,
                        Heaper right)
Create a new pair. Since it used to be normal to allow either left or right to be NULL (it is now obsolete but supported for the moment), and it is impossible to do a static check, this (normal) pseudo-constructor does a dynamic check. If you encounter this error, the quick fix is use the obsolete pseudo-constructor (pairWithNulls). The better fix is to stop using NULLs.


pairWithNulls

public static Pair pairWithNulls(Heaper left,
                                 Heaper right)
Create a new pair. Either may be NULL in order to support broken old code.


left

public Heaper left()
Returns the left part. Lispers may think 'car'.


right

public Heaper right()
Returns the right part. Lispers may think 'cdr'.


fetchLeft

public Heaper fetchLeft()
Returns the left part which obsoletely may be NULL


fetchRight

public Heaper fetchRight()
Returns the right part which obsoletely may be NULL


reversed

public Pair reversed()
Returns a new pair which is the left-right reversal of me. pair(a,b)->reversed() is the same as pair(b,a). Only works on non-obsolete Pairs--those whose parts are non-NULL


actualHashForEqual

public int actualHashForEqual()
Description copied from class: Heaper
Defined by subclasses to produce the value returned by hashForEqual.

Overrides:
actualHashForEqual in class Heaper

isEqual

public boolean isEqual(Heaper other)
Description copied from class: Heaper
Return true if the two objects are equal.

Specified by:
isEqual in class Heaper

printOn

public void printOn(java.io.PrintWriter oo)
Description copied from class: Heaper
This should rarely be overridden. In Tofu, it prints ClassName(...), where ... is either produced by printInsideOn or is ??? if printInsideOn it not overridden.

Overrides:
printOn in class Heaper

sendSelfTo

public void sendSelfTo(Xmtr xmtr)
Overrides:
sendSelfTo in class Heaper


Copyright © 2003 David G Jones. All Rights Reserved.
Original Udanax-Gold - Copyright © 1979-1999 Udanax.com. All rights reserved.