1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package com.unitesk.atp.text.location;
33
34 /***
35 * Text position is specified by <I>line</I> and <I>column</I>.
36 * Valid <I>lines</I> and <I>columns</I> are counted from 1.
37 *
38 * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A>
39 * @version $Id: Position.java,v 1.3 2004/11/15 07:53:05 all-x Exp $
40 */
41 public class Position
42 {
43 /***
44 * Stub constructor sets <I>line</I> and <I>column</I> in <code>(0,0)</code>.
45 * They are stub values because real lines and columns are counted from 1.
46 */
47 public Position()
48 {
49 line = 0;
50 column = 0;
51 }
52
53 /***
54 * Creates position with the specified <I>line</I> and <I>column</I>.
55 *
56 * @param line The <I>line</I> of new position.
57 * @param column The <I>column</I> of new position.
58 */
59 public Position( int line, int column )
60 {
61 setLine( line );
62 setColumn( column );
63 }
64
65 /***
66 * Returns the <I>line</I> of this position.
67 *
68 * @return The <I>line</I> of this position.
69 */
70 public int getLine()
71 {
72 return line;
73 }
74
75 /***
76 * Sets the new value of <I>line</I> of this position.
77 *
78 * @param line value to be set as <I>line</I>.
79 */
80 public void setLine( int line )
81 {
82 this.line = line;
83 }
84
85 /***
86 * Returns the <I>column</I> of this position.
87 *
88 * @return The <I>column</I> of this position.
89 */
90 public int getColumn()
91 {
92 return column;
93 }
94
95
96 /***
97 * Sets the new value of <I>column</I> of this position.
98 *
99 * @param column value to be set as <I>column</I>.
100 */
101 public void setColumn( int column )
102 {
103 this.column = column;
104 }
105
106 /***
107 * Returns the string representation of this position.
108 *
109 * @return The string representation of this position
110 * as <code>"(${line},${column})"</code>.
111 * Invalid (non-positive) value of <I>line</I> or <I>column</I>
112 * is represented as <code>'?'</code>.
113 */
114 public String toString()
115 {
116 return "("
117 + (line > 0 ? Integer.toString( line ) : "?")
118 + ","
119 + (column > 0 ? Integer.toString( column ) : "?")
120 + ")";
121 }
122
123 /***
124 * Positions are equal if lines and columns are equal.
125 *
126 * @param obj The object to compare with.
127 */
128 public boolean equals( Object obj )
129 {
130 if( !(obj instanceof Position) ) return false;
131 Position pos = (Position)obj;
132 return getLine() == pos.getLine()
133 && getColumn() == pos.getColumn();
134 }
135
136 /***
137 * @return This implementation returns line of position.
138 */
139 public int hashCode()
140 {
141 return getLine();
142 }
143
144
145
146
147 private int line;
148 private int column;
149 }