public final D getDiffById(final int snapshotId) { if (snapshotId == Snapshot.CURRENT_STATE_ID || diffs == null) { return null; } final int i = diffs.binarySearch(snapshotId); if (i >= 0) { // exact match return diffs.get(i); } else { // Exact match not found means that there were no changes between // given snapshot and the next state so that the diff for the given // snapshot was not recorded. Thus, return the next state. final int j = -i - 1; return j < diffs.size() ? diffs.get(j) : null; } }
/** @return this list as a unmodifiable {@link List}. */ public final DiffList<D> asList() { return diffs != null ? DiffList.unmodifiableList(diffs) : DiffList.emptyList(); }
return; int snapshotIndex = diffs.binarySearch(snapshot); if (prior != Snapshot.NO_SNAPSHOT_ID) { // there is still snapshot before diffs.get(snapshotIndex).setSnapshotId(prior); } else { // there is no snapshot before removed = diffs.remove(0); if (diffs.isEmpty()) { diffs = null; final AbstractINodeDiff<N, A, D> previous = diffs.get(snapshotIndex - 1); if (previous.getSnapshotId() != prior) { diffs.get(snapshotIndex).setSnapshotId(prior); } else { removed = diffs.remove(snapshotIndex); if (previous.snapshotINode == null) { previous.snapshotINode = removed.snapshotINode;
public BlockInfo[] findEarlierSnapshotBlocks(int snapshotId) { assert snapshotId != Snapshot.NO_SNAPSHOT_ID : "Wrong snapshot id"; if (snapshotId == Snapshot.CURRENT_STATE_ID) { return null; } DiffList<FileDiff> diffs = this.asList(); int i = diffs.binarySearch(snapshotId); BlockInfo[] blocks = null; for(i = i >= 0 ? i : -i-2; i >= 0; i--) { blocks = diffs.get(i).getBlocks(); if(blocks != null) { break; } } return blocks; }
@Override public int size() { return diffs.size(); }
public final int getDiffIndexById(final int snapshotId) { int diffIndex = diffs.binarySearch(snapshotId); diffIndex = diffIndex < 0 ? (-diffIndex - 1) : diffIndex; return diffIndex; }
@Override public List<T> getMinListForRange(int startIndex, int endIndex, INodeDirectory dir) { return diffs.getMinListForRange(startIndex, endIndex, dir); } };
@Override public Iterator<T> iterator() { return diffs.iterator(); }
@Override public boolean isEmpty() { return diffs.isEmpty(); }
@Override public T get(int i) { return diffs.get(i); }
/** Append the diff at the end of the list. */ private D addLast(D diff) { createDiffsIfNeeded(); final D last = getLast(); diffs.addLast(diff); if (last != null) { last.setPosterior(diff); } return diff; }
/** Replace the given child in the created/deleted list, if there is any. */ public boolean replaceCreatedChild(final INode oldChild, final INode newChild) { final DiffList<DirectoryDiff> diffList = asList(); for(int i = diffList.size() - 1; i >= 0; i--) { final ChildrenDiff diff = diffList.get(i).diff; if (diff.replaceCreated(oldChild, newChild)) { return true; } } return false; }
final int i = diffs.binarySearch(anchorId); if (exclusive) { // must be the one before if (i == -1 || i == 0) { } else { int priorIndex = i > 0 ? i - 1 : -i - 2; return diffs.get(priorIndex).getSnapshotId(); return diffs.get(i).getSnapshotId(); } else if (i < -1) { return diffs.get(-i - 2).getSnapshotId(); } else { // i == -1 return Snapshot.NO_SNAPSHOT_ID;
final int[] changedBetweenSnapshots(Snapshot from, Snapshot to) { if (diffs == null) { return null; } Snapshot earlier = from; Snapshot later = to; if (Snapshot.ID_COMPARATOR.compare(from, to) > 0) { earlier = to; later = from; } final int size = diffs.size(); int earlierDiffIndex = getDiffIndexById(earlier.getId()); int laterDiffIndex = later == null ? size : getDiffIndexById(later.getId()); if (earlierDiffIndex == size) { // if the earlierSnapshot is after the latest SnapshotDiff stored in // diffs, no modification happened after the earlierSnapshot return null; } if (laterDiffIndex == -1 || laterDiffIndex == 0) { // if the laterSnapshot is the earliest SnapshotDiff stored in diffs, or // before it, no modification happened before the laterSnapshot return null; } return new int[]{earlierDiffIndex, laterDiffIndex}; }
@Override public int binarySearch(int i) { return diffs.binarySearch(i); }
/** * Returns the list of diffs between two indexes corresponding to two * snapshots. * @param fromIndex Index of the diff corresponding to the earlier snapshot * @param toIndex Index of the diff corresponding to the later snapshot * @param dir The Directory to which the diffList belongs * @return list of directory diffs */ List<DirectoryDiff> getDiffListBetweenSnapshots(int fromIndex, int toIndex, INodeDirectory dir) { return asList().getMinListForRange(fromIndex, toIndex, dir); } }
@Override public Iterator<D> iterator() { return diffs != null ? diffs.iterator() : Collections.emptyIterator(); }