View Javadoc

1   // jq_LineNumberBC.java, created Mon Feb  5 23:23:20 2001 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Class;
5   
6   /***
7    * This class matches bytecode indices to line numbers.
8    * It implements the Comparable interface; objects are compared based on their
9    * starting bytecode indices.
10   *
11   * @author  John Whaley <jwhaley@alum.mit.edu>
12   * @version $Id: jq_LineNumberBC.java 2091 2005-01-08 22:53:02Z joewhaley $
13   */
14  public class jq_LineNumberBC implements Comparable {
15  
16      /*** Starting bytecode index, inclusive. */
17      private char startPC;
18      /*** Corresponding line number. */
19      private char lineNum;
20  
21      /*** Constructs a new jq_LineNumberBC object with the given starting bytecode index and line number.
22       *  The starting bytecode index is inclusive.
23       *
24       * @param startPC  starting bytecode index, inclusive
25       * @param lineNum  corresponding line number
26       */
27      public jq_LineNumberBC(char startPC, char lineNum) {
28          this.startPC = startPC;
29          this.lineNum = lineNum;
30      }
31  
32      /*** Returns the start bytecode index.
33       * @return  start bytecode index
34       */
35      public char getStartPC() { return startPC; }
36      /*** Returns the line number.
37       * @return  line number
38       */
39      public char getLineNum() { return lineNum; }
40      
41      /*** Compares this jq_LineNumberBC object to the given jq_LineNumberBC object.
42       *  Comparisons are based on the start bytecode index value.
43       *
44       * @param that  object to compare against
45       * @return  -1 if this is less than given, 0 if same as given, 1 if greater than given
46       */
47      public int compareTo(jq_LineNumberBC that) {
48          if (this.startPC == that.startPC) return 0;
49          if (this.startPC < that.startPC) return -1;
50          return 1;
51      }
52      public int compareTo(java.lang.Object that) {
53          return compareTo((jq_LineNumberBC)that);
54      }
55      /*** Compares this jq_LineNumberBC object to the given jq_LineNumberBC object.
56       *  Comparisons are based on the start bytecode index value.
57       *
58       * @param that  object to compare against
59       * @return  true if objects are equal, false otherwise
60       */
61      public boolean equals(jq_LineNumberBC that) {
62          return this.startPC == that.startPC;
63      }
64      public boolean equals(Object that) {
65          return equals((jq_LineNumberBC)that);
66      }
67      
68      /* (non-Javadoc)
69       * @see java.lang.Object#hashCode()
70       */
71      public int hashCode() {
72          return startPC ^ lineNum;
73      }
74      
75      /*** Returns a string representation of this jq_LineNumberBC object.
76       * @return  string representation
77       */
78      public String toString() {
79          return "(startPC="+(int)startPC+",lineNum="+(int)lineNum+")";
80      }
81  
82  }