1 package de.fhdw.wtf.common.token;
2
3 import java.io.Serializable;
4
5
6
7
8 public final class Position implements Serializable {
9
10
11
12
13 static final long serialVersionUID = 238623487L;
14
15
16
17
18 private final int lineNumber;
19
20
21
22
23 private final int position;
24
25
26
27
28
29 private final int columnNumber;
30
31
32
33
34 private final String filePath;
35
36
37
38
39
40
41
42
43
44
45
46
47
48 private Position(final String filePath, final int lineNumber, final int columnNumber, final int position) {
49 this.lineNumber = lineNumber;
50 this.filePath = filePath;
51 this.columnNumber = columnNumber;
52 this.position = position;
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public static Position create(final String filePath,
69 final int lineNumber,
70 final int columnNumber,
71 final int position) {
72 return new Position(filePath, lineNumber, columnNumber, position);
73 }
74
75
76
77
78 public int getLineNumber() {
79 return this.lineNumber;
80 }
81
82
83
84
85
86 public int getPosition() {
87 return this.position;
88 }
89
90
91
92
93
94 public int getColumnNumber() {
95 return this.columnNumber;
96 }
97
98
99
100
101 public String getFilePath() {
102 return this.filePath;
103 }
104
105 @Override
106 public String toString() {
107 return "[FilePath:" + this.getFilePath() + ",LineNumber:" + this.getLineNumber() + ",ColumnNumber:"
108 + this.getColumnNumber() + ",Position:" + this.getPosition() + "]";
109 }
110
111 @Override
112 public boolean equals(final Object o) {
113 if (o instanceof Position) {
114 final Position p = (Position) o;
115 return this.getFilePath().equals(p.getFilePath()) && this.getLineNumber() == p.getLineNumber()
116 && this.getPosition() == p.getPosition() && this.getColumnNumber() == p.getColumnNumber();
117 }
118 return false;
119 }
120
121 @Override
122 public int hashCode() {
123 return this.getFilePath().hashCode() ^ this.getLineNumber() ^ this.getPosition() ^ this.getColumnNumber();
124 }
125
126
127
128
129 public static Position createDummyPosition() {
130 return Position.create("", -1, -1, -1);
131 }
132 }