KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jfun > parsec > Pos


1 /*****************************************************************************
2  * Copyright (C) Zephyr Business Solutions Corp. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 /*
9  * Created on Dec 12, 2004
10  *
11  * Author Ben Yu
12  */

13 package jfun.parsec;
14
15 /**
16  * Pos represents a position in the source.
17  * @author Ben Yu
18  *
19  * Dec 12, 2004
20  */

21 public final class Pos implements java.io.Serializable JavaDoc{
22   private final int lno;
23   private final int cno;
24   
25   /**
26    * Create a Pos object.
27    * @param lno
28    * @param cno
29    */

30   public Pos(final int lno, final int cno) {
31     super();
32     this.lno = lno;
33     this.cno = cno;
34   }
35   
36   /**
37    * Get the column number.
38    * @return Returns the cno.
39    */

40   public int getColumnNo() {
41     return cno;
42   }
43   /**
44    * Get the line number.
45    * @return Returns the lno.
46    */

47   public int getLineNo() {
48     return lno;
49   }
50
51   public boolean equals(Object JavaDoc obj) {
52     if(obj instanceof Pos){
53       final Pos other = (Pos)obj;
54       return lno == other.lno && cno==other.cno;
55     }
56     else return false;
57   }
58
59   public int hashCode() {
60     return lno*31+cno;
61   }
62
63   public String JavaDoc toString() {
64     return "line " + lno + " column "+cno;
65   }
66   
67 }
68
Popular Tags