From cac67ebc7e930733b55a381aa72e44c41eac224a Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sun, 12 Mar 2017 19:50:03 +0100 Subject: [PATCH] Version 1.4.1: Progress fixes --- VERSION | 2 +- changelog | 7 +++++++ src/be/nikiroo/utils/Progress.java | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 88c5fb8..347f583 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4.0 +1.4.1 diff --git a/changelog b/changelog index 4a8514d..3cc63ad 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,10 @@ +Version 1.4.1 +------------- + +Progress + Better handling of min==max case + New methods .done() and .add(int step) + Version 1.4.0 ------------- diff --git a/src/be/nikiroo/utils/Progress.java b/src/be/nikiroo/utils/Progress.java index b6137f1..5ee3221 100644 --- a/src/be/nikiroo/utils/Progress.java +++ b/src/be/nikiroo/utils/Progress.java @@ -227,6 +227,18 @@ public class Progress { } } + /** + * Add some value to the current progression of this {@link Progress}. + * + * @param step + * the amount to add + */ + public void add(int step) { + synchronized (getLock()) { + setProgress(localProgress + step); + } + } + /** * Check if the action corresponding to this {@link Progress} is done (i.e., * if its progress value == its max value). @@ -237,6 +249,13 @@ public class Progress { return progress >= max; } + /** + * Mark the {@link Progress} as done by setting its value to max. + */ + public void done() { + setProgress(getMax()); + } + /** * Get the total progress value (including the optional children * {@link Progress}) on a 0.0 to 1.0 scale. @@ -244,6 +263,10 @@ public class Progress { * @return the progress */ public double getRelativeProgress() { + if (max == min) { + return 1; + } + return (((double) progress) / (max - min)); } -- 2.27.0