1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.spi;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19
20
21
22
23
24
25 public class ElementPath {
26
27 ArrayList<String> partList = new ArrayList<String>();
28
29 public ElementPath() {
30 }
31
32 public ElementPath(List<String> list) {
33 partList.addAll(list);
34 }
35
36
37
38
39
40
41 public ElementPath(String pathStr) {
42 if (pathStr == null) {
43 return;
44 }
45
46 String[] partArray = pathStr.split("/");
47 if (partArray == null)
48 return;
49
50 for (String part : partArray) {
51 if (part.length() > 0) {
52 partList.add(part);
53 }
54 }
55 }
56
57 public ElementPath duplicate() {
58 ElementPath p = new ElementPath();
59 p.partList.addAll(this.partList);
60 return p;
61 }
62
63
64 @Override
65 public boolean equals(Object o) {
66 if ((o == null) || !(o instanceof ElementPath)) {
67 return false;
68 }
69
70 ElementPath r = (ElementPath) o;
71
72 if (r.size() != size()) {
73 return false;
74 }
75
76 int len = size();
77
78 for (int i = 0; i < len; i++) {
79 if (!equalityCheck(get(i), r.get(i))) {
80 return false;
81 }
82 }
83
84
85 return true;
86 }
87
88 private boolean equalityCheck(String x, String y) {
89 return x.equalsIgnoreCase(y);
90 }
91
92 public List<String> getCopyOfPartList() {
93 return new ArrayList<String>(partList);
94 }
95
96 public void push(String s) {
97 partList.add(s);
98 }
99
100 public String get(int i) {
101 return (String) partList.get(i);
102 }
103
104 public void pop() {
105 if (!partList.isEmpty()) {
106 partList.remove(partList.size() - 1);
107 }
108 }
109
110 public String peekLast() {
111 if (!partList.isEmpty()) {
112 int size = partList.size();
113 return (String) partList.get(size - 1);
114 } else {
115 return null;
116 }
117 }
118
119 public int size() {
120 return partList.size();
121 }
122
123 protected String toStableString() {
124 StringBuilder result = new StringBuilder();
125 for (String current : partList) {
126 result.append("[").append(current).append("]");
127 }
128 return result.toString();
129 }
130
131 @Override
132 public String toString() {
133 return toStableString();
134 }
135 }