import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
/**
* Progress reporting system, possibly nested.
*
* @return the children (Who will think of the children??)
*/
- public Set<Progress> getChildren() {
- return children.keySet();
+ public List<Progress> getChildren() {
+ synchronized (getLock()) {
+ return new ArrayList<Progress>(children.keySet());
+ }
}
/**
* the listener
*/
public void addProgressListener(ProgressListener l) {
- this.listeners.add(l);
+ synchronized (getLock()) {
+ this.listeners.add(l);
+ }
}
/**
* @return TRUE if it was found (and removed)
*/
public boolean removeProgressListener(ProgressListener l) {
- return this.listeners.remove(l);
+ synchronized (getLock()) {
+ return this.listeners.remove(l);
+ }
}
/**
if (weight < min || weight > max) {
throw new RuntimeException(String.format(
"Progress object %s cannot have a weight of %f, "
- + "it is outside of its parent (%s) range (%f)",
+ + "it is outside of its parent (%s) range (%d)",
progress.name, weight, name, max));
}
name, progress.parent.name));
}
+ progress.parent = this;
+
progress.addProgressListener(new ProgressListener() {
@Override
public void progress(Progress pg, String name) {
synchronized (getLock()) {
double total = relativeLocalProgress;
- for (Entry<Progress, Double> entry : children.entrySet()) {
- total += (entry.getValue() / (max - min))
- * entry.getKey().getRelativeProgress();
+ synchronized (getLock()) {
+ for (Entry<Progress, Double> entry : children
+ .entrySet()) {
+ total += (entry.getValue() / (max - min))
+ * entry.getKey().getRelativeProgress();
+ }
}
setRelativeProgress(pg, name, total);
}
});
- this.children.put(progress, weight);
+ synchronized (getLock()) {
+ this.children.put(progress, weight);
+ }
}
/**