-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathXmlPath.java
More file actions
46 lines (38 loc) · 926 Bytes
/
XmlPath.java
File metadata and controls
46 lines (38 loc) · 926 Bytes
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
package JDBCExcel;
import java.util.ArrayList;
import java.util.List;
public class XmlPath {
private List<String> pathList;
public XmlPath() {
pathList = new ArrayList<String>();
}
public void add(String tag) {
pathList.add(tag);
}
public String remove(String tag) {
int size = pathList.size();
if (size == 0 || !pathList.get(size - 1).equals(tag))
throw new IllegalArgumentException("Tag " + tag + " not found at end of path");
return pathList.remove(size - 1);
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
for (String string : pathList) {
sb.append("/");
sb.append(string);
}
return sb.toString();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof XmlPath))
return false;
XmlPath other = (XmlPath) o;
return pathList.equals(other.pathList);
}
@Override
public int hashCode() {
return pathList.hashCode();
}
}