}
}
private static void repairRequests(List<ReorderRequest> reqs) {
for (int i = 0, n = reqs.size(); i < n; i++) {
ReorderRequest req = reqs.get(i);
int from = req.getFromIndex();
int to = req.getToIndex();
for (int j = 0; j < i; j++) {
ReorderRequest prev = reqs.get(j);
int prevFrom = prev.getFromIndex();
int prevTo = prev.getToIndex();
if (prevFrom <= from && from < prevTo) {
from--;
} else if (prevTo <= from && from < prevFrom) {
from++;
}
if (prevFrom <= to && to < prevTo) {
to--;
} else if (prevTo <= to && to < prevFrom) {
to++;
}
}
if (from != req.getFromIndex() || to != req.getToIndex()) {
reqs.set(i, new ReorderRequest(req.getObject(), from, to));
}
}
for (int i = reqs.size() - 1; i >= 0; i--) {
ReorderRequest req = reqs.get(i);
if (req.getFromIndex() == req.getToIndex()) {
reqs.remove(i);
}
}
}