fr.vergne.progress.impl.BinaryProgress Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of progress-core Show documentation
Show all versions of progress-core Show documentation
Implementation of the progress management facilities.
The newest version!
package fr.vergne.progress.impl;
import java.util.Collection;
import java.util.HashSet;
import fr.vergne.progress.Progress;
/**
* A {@link BinaryProgress} is a {@link Progress} which can be only in 2 states:
* finished or not. More precisely, its value can be 0 (nothing done) or 1
* (finished). The only way to change it is either to {@link #restart()} or
* {@link #finish()} it.
*
* @author Matthieu Vergne
*
*/
public class BinaryProgress implements Progress {
private byte current = 0;
private final Collection> listeners = new HashSet>();
@Override
public Byte getCurrentValue() {
return current;
}
@Override
public Byte getMaxValue() {
return 1;
}
@Override
public boolean isFinished() {
return current == 1;
}
@Override
public void addProgressListener(ProgressListener listener) {
listeners.add(listener);
}
@Override
public void removeProgressListener(ProgressListener listener) {
listeners.remove(listener);
}
/**
* Restart this {@link BinaryProgress} by setting the current value to 0.
*/
public void restart() {
current = 0;
for (ProgressListener listener : listeners) {
listener.currentUpdate(current);
}
}
/**
* Finish this {@link BinaryProgress} by setting the current value to 1.
*/
public void finish() {
current = 1;
for (ProgressListener listener : listeners) {
listener.currentUpdate(current);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy