| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.search.solr.internal.job; |
| 21 |
|
|
| 22 |
|
import org.apache.commons.lang3.tuple.ImmutablePair; |
| 23 |
|
import org.apache.commons.lang3.tuple.Pair; |
| 24 |
|
import org.xwiki.model.reference.DocumentReference; |
| 25 |
|
import org.xwiki.model.reference.EntityReference; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
@param |
| 31 |
|
@version |
| 32 |
|
@since |
| 33 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (49) |
Complexity: 13 |
Complexity Density: 0.43 |
|
| 34 |
|
public class DiffDocumentIterator<T> extends AbstractDocumentIterator<DiffDocumentIterator.Action> |
| 35 |
|
{ |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 39 |
|
public enum Action |
| 40 |
|
{ |
| 41 |
|
|
| 42 |
|
SKIP, |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
ADD, |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
DELETE, |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
UPDATE |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
private final DocumentIterator<T> previous; |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
private final DocumentIterator<T> next; |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
private final DocumentReferenceComparator documentReferenceComparator = new DocumentReferenceComparator(); |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
@link |
| 71 |
|
|
| 72 |
|
private Pair<DocumentReference, T> previousEntry; |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
@link |
| 76 |
|
|
| 77 |
|
private Pair<DocumentReference, T> nextEntry; |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
@link@link |
| 81 |
|
|
| 82 |
|
private int diff; |
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@param |
| 88 |
|
@param |
| 89 |
|
|
| 90 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 91 |
7 |
public DiffDocumentIterator(DocumentIterator<T> previous, DocumentIterator<T> next)... |
| 92 |
|
{ |
| 93 |
7 |
this.previous = previous; |
| 94 |
7 |
this.next = next; |
| 95 |
|
} |
| 96 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 97 |
4 |
@Override... |
| 98 |
|
public void setRootReference(EntityReference rootReference) |
| 99 |
|
{ |
| 100 |
4 |
previous.setRootReference(rootReference); |
| 101 |
4 |
next.setRootReference(rootReference); |
| 102 |
|
} |
| 103 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 104 |
492 |
@Override... |
| 105 |
|
public boolean hasNext() |
| 106 |
|
{ |
| 107 |
492 |
return previous.hasNext() || next.hasNext(); |
| 108 |
|
} |
| 109 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 9 |
Complexity Density: 0.38 |
|
| 110 |
487 |
@Override... |
| 111 |
|
public Pair<DocumentReference, Action> next() |
| 112 |
|
{ |
| 113 |
487 |
DocumentReference documentReference; |
| 114 |
487 |
Action action; |
| 115 |
487 |
if (next.hasNext() && previous.hasNext()) { |
| 116 |
4 |
if (diff >= 0) { |
| 117 |
3 |
nextEntry = next.next(); |
| 118 |
|
} |
| 119 |
4 |
if (diff <= 0) { |
| 120 |
3 |
previousEntry = previous.next(); |
| 121 |
|
} |
| 122 |
4 |
diff = documentReferenceComparator.compare(previousEntry.getKey(), nextEntry.getKey()); |
| 123 |
4 |
if (diff == 0) { |
| 124 |
2 |
documentReference = nextEntry.getKey(); |
| 125 |
|
|
| 126 |
2 |
if (nextEntry.getValue().equals(previousEntry.getValue())) { |
| 127 |
1 |
action = Action.SKIP; |
| 128 |
|
} else { |
| 129 |
1 |
action = Action.UPDATE; |
| 130 |
|
} |
| 131 |
2 |
} else if (diff > 0) { |
| 132 |
1 |
documentReference = nextEntry.getKey(); |
| 133 |
1 |
action = Action.ADD; |
| 134 |
|
} else { |
| 135 |
1 |
documentReference = previousEntry.getKey(); |
| 136 |
1 |
action = Action.DELETE; |
| 137 |
|
} |
| 138 |
483 |
} else if (next.hasNext()) { |
| 139 |
481 |
documentReference = next.next().getKey(); |
| 140 |
481 |
action = Action.ADD; |
| 141 |
|
} else { |
| 142 |
2 |
documentReference = previous.next().getKey(); |
| 143 |
2 |
action = Action.DELETE; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
487 |
return new ImmutablePair<DocumentReference, Action>(documentReference, action); |
| 147 |
|
} |
| 148 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 149 |
4 |
@Override... |
| 150 |
|
public long size() |
| 151 |
|
{ |
| 152 |
4 |
return Math.max(previous.size(), next.size()); |
| 153 |
|
} |
| 154 |
|
} |