home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / src / pair.java < prev    next >
Encoding:
Java Source  |  1996-09-13  |  1.2 KB  |  66 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2. // Portions Copyright(c) 1995, 1996 Hewlett-Packard Company.
  3.  
  4. package jgl;
  5.  
  6. /**
  7.  * A Pair is an object that contains two other objects. It is
  8.  * most commonly used for conveniently storing and passing pairs
  9.  * of objects.
  10.  * <p>
  11.  * @version 1.1
  12.  * @author ObjectSpace, Inc.
  13.  */
  14.  
  15. public class Pair
  16.   {
  17.   /**
  18.    * The first object.
  19.    */
  20.   public Object first;
  21.  
  22.   /**
  23.    * The second object.
  24.    */
  25.   public Object second;
  26.  
  27.   /**
  28.    * Construct myself to hold a pair of objects.
  29.    * @param x The first object.
  30.    * @param y The second object.
  31.    */
  32.   public Pair( Object x, Object y )
  33.     {
  34.     first = x;
  35.     second = y;
  36.     }
  37.  
  38.   /**
  39.    * Construct myself to hold a pair of objects initially null.
  40.    */
  41.   public Pair()
  42.     {
  43.     first = null;
  44.     second = null;
  45.     }
  46.  
  47.   /**
  48.    * Return a string that describes me.
  49.    */
  50.   public String toString()
  51.     {
  52.     return "Pair( " + first + ", " + second + " )";
  53.     }
  54.  
  55.   public boolean equals( Object object )
  56.     {
  57.     return object instanceof Pair && equals( (Pair) object );
  58.     }
  59.  
  60.   public boolean equals( Pair pair )
  61.     {
  62.     return first.equals( pair.first ) && second.equals( pair.second );
  63.     }
  64.   }
  65.  
  66.