View Javadoc

1   package org.lcsim.recon.tracking.trfutil;
2   import java.util.*;
3   /**
4    * Object-pair class modelled on C++ STL pair.
5    * @author Norman A. Graf
6    * @version 1.0
7    */
8   public class Pair
9   {
10      
11      private Object _first;
12      private Object _second;
13      
14      /**
15       * Constructor.
16       *
17       * @param   first  First Object to associate.
18       * @param   second Second Object to associate.
19       */
20      public Pair( Object first, Object second )
21      {
22          _first = first;
23          _second = second;
24      }
25      
26      /**
27       * Fetch the first object.
28       *
29       * @return Return by reference since we can't guarantee that clone() does the right thing.
30       */
31      public Object first()
32      {
33          return _first;
34      }
35      
36      
37      /**
38       * Fetch the second object.
39       *
40       * @return Return by reference since we can't guarantee that clone() does the right thing.
41       */
42      public Object second()
43      {
44          return _second;
45      }
46      
47      /**
48       * Equality test.
49       *
50       * @param   o Pair Object to test against.
51       * @return  true if Pairs are the same using equals(), <b>not </b> ==.
52       */
53      public boolean equals( Object o )
54      {
55          if ( o != null && o.getClass().equals(getClass()) )
56          {
57              return _first.equals(((Pair) o).first()) && _second.equals(((Pair)o).second());
58          }
59          return false;
60      }
61      
62      
63      /**
64       * Inequality test, convenience method.
65       *
66       * @param   o Pair Object to test against.
67       * @return  true if Pairs are the <b>not</b> the same using equals(), <b>not </b> ==.
68       */
69      public boolean notEquals( Object o )
70      {
71          return !equals(o);
72      }
73      
74      /**
75       * Compute a hash code for the pair.
76       *
77       * @return integer hash.
78       */
79      public int hashCode()
80      {
81          int result = 17;
82          result = 37*result + _first.hashCode();
83          result = 37*result +_second.hashCode();
84          return result;
85      }
86      
87      // output stream
88      
89      /**
90       * String representation of this Pair.
91       *
92       * @return   String representation of this Pair.
93       */
94      public String toString()
95      {
96          String className = getClass().getName();
97          int lastDot = className.lastIndexOf('.');
98          if(lastDot!=-1)className = className.substring(lastDot+1);
99          
100         return className+" ( "+_first+", "+_second+" )";
101     }
102 }