package org.simantics.graph.db; public interface TGStatusMonitor { void status(int percentage); boolean isCanceled(); public static class NullMonitor implements TGStatusMonitor { @Override public void status(int percentage) { } @Override public boolean isCanceled() { return false; } } public static final TGStatusMonitor NULL_MONITOR = new NullMonitor(); public static class Updater { private final TGStatusMonitor monitor; private final int total; private int percentage; private int worked; public Updater(TGStatusMonitor monitor, int total) { this.monitor = monitor; this.total = total; } public int worked(int work) { worked += work; return percentage = updatePercentage(monitor, percentage, worked, total); } } public static int updatePercentage(TGStatusMonitor monitor, int oldPercentage, int done, int total) { int current = (100 * done) / total; if (current > oldPercentage) { oldPercentage = current; if (monitor != null) monitor.status(oldPercentage); } return oldPercentage; } }