MovementAvailability (@NotNull DocumentReference reference, @NotNull Set<? extends ActionChangeRange> rangesToMove) { LinkedList<ActionChangeRange> stack = getStack(reference); ActionChangeRange[] affected = getAffectedRanges(stack, rangesToMove); if (affected == null) { return MovementAvailability.ALREADY_MOVED; } Set<ActionChangeRange> copiesToMove = new HashSet<>(); for (int i = 0; i < affected.length; i++) { ActionChangeRange copy = affected[i].createIndependentCopy(true); if (rangesToMove.contains(affected[i])) { copiesToMove.add(copy); } affected[i] = copy; } return moveToEnd(affected, copiesToMove) ? MovementAvailability.CAN_MOVE : MovementAvailability.CANNOT_MOVE; }