flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cd...@apache.org
Subject [flex-utilities] branch feature/flash-downloader updated: - Make the progressbar only update if it is worth updating.
Date Mon, 11 Nov 2019 14:45:16 GMT
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/flash-downloader
in repository https://gitbox.apache.org/repos/asf/flex-utilities.git


The following commit(s) were added to refs/heads/feature/flash-downloader by this push:
     new b54ae4d  - Make the progressbar only update if it is worth updating.
b54ae4d is described below

commit b54ae4d5a0fc946f8efe23e822e1e067d64d9588
Author: Christofer Dutz <christofer.dutz@c-ware.de>
AuthorDate: Mon Nov 11 15:45:04 2019 +0100

    - Make the progressbar only update if it is worth updating.
---
 .../utilities/converter/retrievers/utils/ProgressBar.java | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/flex-maven-tools/flex-sdk-converter/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/utils/ProgressBar.java
b/flex-maven-tools/flex-sdk-converter/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/utils/ProgressBar.java
index c15d26b..1a1b775 100644
--- a/flex-maven-tools/flex-sdk-converter/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/utils/ProgressBar.java
+++ b/flex-maven-tools/flex-sdk-converter/retrievers/base/src/main/java/org/apache/flex/utilities/converter/retrievers/utils/ProgressBar.java
@@ -24,9 +24,11 @@ import org.apache.commons.lang3.StringUtils;
 public class ProgressBar {
 
     protected long total;
+    protected int curValue;
 
     public ProgressBar(long total) {
         this.total = total;
+        this.curValue = 0;
         drawOutput(0l);
     }
 
@@ -37,11 +39,14 @@ public class ProgressBar {
     protected void drawOutput(long current) {
         final int transferredPercent = (int) Math.round(
                 ((double) current / (double) total) * (double) 100);
-        final int segmentsTransferred = transferredPercent / 2;
-        final int segmentsRest = 50 - segmentsTransferred;
-        System.out.print("\r" + String.format(" %3d", transferredPercent) + "% [" +
-                StringUtils.repeat("=", segmentsTransferred) +
-                ((segmentsRest > 0) ? ">" + StringUtils.repeat(" ", segmentsRest -
1) : "") + "] ");
+        if(transferredPercent != curValue) {
+            curValue = transferredPercent;
+            final int segmentsTransferred = transferredPercent / 2;
+            final int segmentsRest = 50 - segmentsTransferred;
+            System.out.print("\r" + String.format(" %3d", transferredPercent) + "% [" +
+                    StringUtils.repeat("=", segmentsTransferred) +
+                    ((segmentsRest > 0) ? ">" + StringUtils.repeat(" ", segmentsRest
- 1) : "") + "] ");
+        }
     }
 
 }


Mime
View raw message