-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLocator.java
More file actions
140 lines (125 loc) · 3.74 KB
/
Locator.java
File metadata and controls
140 lines (125 loc) · 3.74 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright (c) 2019-2024 Ronald Brill.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.htmlunit.cssparser.parser;
import java.io.Serializable;
import org.htmlunit.cssparser.util.ParserUtils;
/**
* For associating a CSS event with a document location.
*
* @author Ronald Brill
*/
public class Locator implements Serializable {
private String uri_;
private int lineNumber_;
private int columnNumber_;
/**
* Creates new LocatorImpl.
* @param uri the uri
* @param line the lineNumber
* @param column the columnNumber
*/
public Locator(final String uri, final int line, final int column) {
uri_ = uri;
lineNumber_ = line;
columnNumber_ = column;
}
/**
* <p>getUri.</p>
*
* @return the uri
*/
public String getUri() {
return uri_;
}
/**
* Set the uri to a new value.
* @param uri the new uri
*/
public void setUri(final String uri) {
uri_ = uri;
}
/**
* Return the column number where the current document event ends.
* Note that this is the column number of the first
* character after the text associated with the document
* event. The first column in a line is position 1.
* @return The column number, or -1 if none is available.
* @see #getLineNumber
*/
public int getColumnNumber() {
return columnNumber_;
}
/**
* Set the columnNumber to a new value.
* @param column the new columnNumber
*/
public void setColumnNumber(final int column) {
columnNumber_ = column;
}
/**
* Return the line number where the current document event ends.
* Note that this is the line position of the first character
* after the text associated with the document event.
* @return The line number, or -1 if none is available.
* @see #getColumnNumber
*/
public int getLineNumber() {
return lineNumber_;
}
/**
* Set the lineNumber to a new value.
* @param line the new lineNumber
*/
public void setLineNumber(final int line) {
lineNumber_ = line;
}
/**
* Clears all fields (for object pooling).
*/
public void clear() {
uri_ = null;
lineNumber_ = 0;
columnNumber_ = 0;
}
/** {@inheritDoc} */
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Locator)) {
return false;
}
final Locator l = (Locator) obj;
return (getColumnNumber() == l.getColumnNumber())
&& (getLineNumber() == l.getLineNumber())
&& ParserUtils.equals(getUri(), l.getUri());
}
@Override
public int hashCode() {
int hash = ParserUtils.HASH_SEED;
hash = ParserUtils.hashCode(hash, columnNumber_);
hash = ParserUtils.hashCode(hash, lineNumber_);
hash = ParserUtils.hashCode(hash, uri_);
return hash;
}
/** {@inheritDoc} */
@Override
public String toString() {
return new StringBuilder().append(getUri()).append(" (")
.append(getLineNumber()).append(':')
.append(getColumnNumber()).append(')').toString();
}
}