PageEventList.java
5.45 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
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.PageModification
* com.day.cq.wcm.api.PageModification$ModificationType
* com.day.text.Text
*/
package com.day.cq.wcm.msm.impl;
import com.day.cq.wcm.api.PageModification;
import com.day.cq.wcm.msm.impl.BlueprintEvent;
import com.day.text.Text;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
class PageEventList {
private final ArrayList<List<PageModificationList>> entries = new ArrayList();
PageEventList() {
}
public void addEvent(BlueprintEvent blueprintEvent) {
List targetScope = null;
PageModificationList map = new PageModificationList(blueprintEvent.getModifications(null));
Iterator<List<PageModificationList>> scopes = this.entries.iterator();
while (targetScope == null && scopes.hasNext()) {
targetScope = scopes.next();
Iterator itr = targetScope.iterator();
while (itr.hasNext() && targetScope != null) {
PageModificationList other = (PageModificationList)itr.next();
if (!map.overlaps(other)) continue;
targetScope = null;
}
}
if (targetScope == null) {
targetScope = new ArrayList<PageModificationList>();
this.entries.add(targetScope);
}
targetScope.add((PageModificationList)new PageModificationList(blueprintEvent.getModifications(null)));
}
public Iterator<List<PageModificationList>> getNonOverlapping() {
return this.entries.iterator();
}
static class PageModificationList
implements Iterable<PageModification> {
private final TreeMap<String, List<PageModification>> branchToEntry;
private final TreeSet<String> rootIndex;
PageModificationList(Iterator<PageModification> modifications) {
this.branchToEntry = new TreeMap(new Comparator<String>(){
@Override
public int compare(String o1, String o2) {
return Text.compareHandles((String)o1, (String)o2);
}
});
this.rootIndex = new TreeSet();
while (modifications.hasNext()) {
this.add(modifications.next());
}
}
public void add(PageModification pageModification) {
String path = pageModification.getPath();
List<PageModification> values = this.branchToEntry.get(path);
if (values == null) {
values = new ArrayList<PageModification>();
this.branchToEntry.put(path, values);
if (this.rootIndex.isEmpty()) {
this.rootIndex.add(path);
} else {
String lower;
String higher = this.rootIndex.higher(path);
if (higher != null) {
if (!Text.isDescendant((String)path, (String)higher)) {
this.rootIndex.add(path);
} else {
this.rootIndex.remove(higher);
}
}
if ((lower = this.rootIndex.lower(path)) != null) {
if (Text.isDescendant((String)lower, (String)path)) {
this.rootIndex.remove(path);
} else {
this.rootIndex.add(path);
}
}
}
}
values.add(pageModification);
}
@Override
public Iterator<PageModification> iterator() {
final Iterator<List<PageModification>> values = this.branchToEntry.values().iterator();
return new Iterator<PageModification>(){
private PageModification next;
private Iterator<PageModification> list;
@Override
public boolean hasNext() {
if (this.next == null) {
if ((this.list == null || !this.list.hasNext()) && values.hasNext()) {
this.list = ((List)values.next()).iterator();
}
if (this.list != null && this.list.hasNext()) {
this.next = this.list.next();
}
}
return this.next != null;
}
@Override
public PageModification next() {
PageModification ret = this.next;
this.next = null;
return ret;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not implemented");
}
};
}
boolean overlaps(PageModificationList other) {
for (String root : other.getRoots()) {
for (String myRoots : this.getRoots()) {
if (!Text.isDescendantOrEqual((String)root, (String)myRoots) && !Text.isDescendantOrEqual((String)myRoots, (String)root)) continue;
return true;
}
}
return false;
}
SortedSet<String> getRoots() {
return this.rootIndex;
}
}
}