@@ -341,13 +341,21 @@ public abstract class Task<T> {
|
|||||||
|
|
||||||
private long lastUpdateProgressTime = 0L;
|
private long lastUpdateProgressTime = 0L;
|
||||||
|
|
||||||
protected void updateProgress(long progress, long total) {
|
protected void updateProgress(long count, long total) {
|
||||||
updateProgress(1.0 * progress / total);
|
if (count < 0 || total < 0)
|
||||||
|
throw new IllegalArgumentException("Invalid count or total: count=" + count + ", total=" + total);
|
||||||
|
|
||||||
|
double progress;
|
||||||
|
if (total >= count)
|
||||||
|
progress = 1.0;
|
||||||
|
else
|
||||||
|
progress = (double) count / total;
|
||||||
|
updateProgress(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateProgress(double progress) {
|
protected void updateProgress(double progress) {
|
||||||
if (progress < 0 || progress > 1.0 || Double.isNaN(progress))
|
if (progress < 0 || progress > 1.0 || Double.isNaN(progress))
|
||||||
throw new IllegalArgumentException("Progress must be between 0 and 1.");
|
throw new IllegalArgumentException("Invalid progress: " + progress);
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (progress == 1.0 || now - lastUpdateProgressTime >= 1000L) {
|
if (progress == 1.0 || now - lastUpdateProgressTime >= 1000L) {
|
||||||
|
|||||||
Reference in New Issue
Block a user