net.algart.contexts.ProgressUpdater Maven / Gradle / Ivy
Show all versions of algart Show documentation
/*
* The MIT License (MIT)
*
* Copyright (c) 2007-2024 Daniel Alievsky, AlgART Laboratory (http://algart.net)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.algart.contexts;
/**
* The context allowing to inform the user about the percents of some long-working method.
*
* @author Daniel Alievsky
*/
public interface ProgressUpdater extends Context {
/**
* 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.{@link #updateProgress updateProgress}((k + 1.0) / n, k == n - 1);
* // when k==n-1, we always show the last progress state (100%)
* }
*
*
*
* @param readyPart the part of calculations that is already done (from 0.0 to 1.0).
* @param force whether this information must be shown always (true
)
* or may be lost (false
).
*/
void updateProgress(double readyPart, boolean force);
}