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.List;
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class ElementSelector extends ElementPath {
31
32 public ElementSelector() {
33 super();
34 }
35
36 public ElementSelector(List<String> list) {
37 super(list);
38 }
39
40
41
42
43
44
45
46 public ElementSelector(String p) {
47 super(p);
48 }
49
50 public boolean fullPathMatch(ElementPath path) {
51 if (path.size() != size()) {
52 return false;
53 }
54
55 int len = size();
56 for (int i = 0; i < len; i++) {
57 if (!equalityCheck(get(i), path.get(i))) {
58 return false;
59 }
60 }
61
62 return true;
63 }
64
65
66
67
68
69
70 public int getTailMatchLength(ElementPath p) {
71 if (p == null) {
72 return 0;
73 }
74
75 int lSize = this.partList.size();
76 int rSize = p.partList.size();
77
78
79 if ((lSize == 0) || (rSize == 0)) {
80 return 0;
81 }
82
83 int minLen = (lSize <= rSize) ? lSize : rSize;
84 int match = 0;
85
86
87 for (int i = 1; i <= minLen; i++) {
88 String l = this.partList.get(lSize - i);
89 String r = p.partList.get(rSize - i);
90
91 if (equalityCheck(l, r)) {
92 match++;
93 } else {
94 break;
95 }
96 }
97 return match;
98 }
99
100 public boolean isContainedIn(ElementPath p) {
101 if (p == null) {
102 return false;
103 }
104 return p.toStableString().contains(toStableString());
105 }
106
107
108
109
110
111
112 public int getPrefixMatchLength(ElementPath p) {
113 if (p == null) {
114 return 0;
115 }
116
117 int lSize = this.partList.size();
118 int rSize = p.partList.size();
119
120
121 if ((lSize == 0) || (rSize == 0)) {
122 return 0;
123 }
124
125 int minLen = (lSize <= rSize) ? lSize : rSize;
126 int match = 0;
127
128 for (int i = 0; i < minLen; i++) {
129 String l = this.partList.get(i);
130 String r = p.partList.get(i);
131
132 if (equalityCheck(l, r)) {
133 match++;
134 } else {
135 break;
136 }
137 }
138
139 return match;
140 }
141
142 private boolean equalityCheck(String x, String y) {
143 return x.equalsIgnoreCase(y);
144 }
145
146 @Override
147 public boolean equals(Object o) {
148 if ((o == null) || !(o instanceof ElementSelector)) {
149 return false;
150 }
151
152 ElementSelector r = (ElementSelector) o;
153
154 if (r.size() != size()) {
155 return false;
156 }
157
158 int len = size();
159
160 for (int i = 0; i < len; i++) {
161 if (!equalityCheck(get(i), r.get(i))) {
162 return false;
163 }
164 }
165
166
167 return true;
168 }
169
170 @Override
171 public int hashCode() {
172 int hc = 0;
173 int len = size();
174
175 for (int i = 0; i < len; i++) {
176
177
178 hc ^= get(i).toLowerCase().hashCode();
179 }
180 return hc;
181 }
182
183 }