mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-23 06:06:11 +00:00
added a first test for dynamic route update
This commit is contained in:
@@ -29,7 +29,7 @@ public class Patch<T> {
|
||||
private List<Delta<T>> deltas = new LinkedList<Delta<T>>();
|
||||
|
||||
/**
|
||||
* Apply this patch to the given target
|
||||
* Apply this patch to the given target, producing a new list as result
|
||||
* @return the patched text
|
||||
* @throws PatchFailedException if can't apply patch
|
||||
*/
|
||||
@@ -43,6 +43,21 @@ public class Patch<T> {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this patch to the given target in-place, updating the <code>target</code> list
|
||||
* @return the patched text
|
||||
* @throws PatchFailedException if can't apply patch
|
||||
*/
|
||||
public List<T> applyToInPlace(List<T> target) throws PatchFailedException {
|
||||
List<T> result = target;
|
||||
ListIterator<Delta<T>> it = getDeltas().listIterator(deltas.size());
|
||||
while (it.hasPrevious()) {
|
||||
Delta<T> delta = it.previous();
|
||||
delta.applyTo(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the text to original. Opposite to applyTo() method.
|
||||
* @param target the given target
|
||||
@@ -74,4 +89,20 @@ public class Patch<T> {
|
||||
Collections.sort(deltas, new DeltaComparator<T>());
|
||||
return deltas;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append('[');
|
||||
boolean first = true;
|
||||
for (Delta<T> delta : getDeltas()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append(", ");
|
||||
}
|
||||
result.append(delta);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user