Interface ProgressUpdater

All Superinterfaces:
Context
All Known Implementing Classes:
DefaultContext

public interface ProgressUpdater extends Context

The context allowing to inform the user about the percents of some long-working method.

Author:
Daniel Alievsky
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    updateProgress(double readyPart, boolean force)
    Informs the user that readyPart*100 percents of calculations are done.

    Methods inherited from interface net.algart.contexts.Context

    as, is
  • Method Details

    • updateProgress

      void updateProgress(double readyPart, boolean force)
      Informs the user that readyPart*100 percents of calculations are done.

      The force argument determines whether this information must be shown to the user with a guarantee. If this argument is false, this method may do nothing to save processing time if it's called very often. Usual implementation of this method contains a time check (System.currentTimeMillis()) and, if !force, does nothing if the previous call (for the same context) was performed several tens of milliseconds ago. Please avoid too frequent calls of this method with force=true: millions of such calls may require long time.

      For example, if the main work of some method is a long loop, this method can be called in the following manner:

           for (int k = 0; k < n; k++) {
               . . . // some long calculations
               pu.updateProgress((k + 1.0) / n, k == n - 1);
               // when k==n-1, we always show the last progress state (100%)
           }
        
       
      Parameters:
      readyPart - the part of calculations that is already done (from 0.0 to 1.0).
      force - whether this information must be shown always (true) or may be lost (false).