/**
* The name of this {@link Progress} step.
*
- * @return the name
+ * @return the name, can be NULL
*/
public String getName() {
return name;
relativeLocalProgress = ((double) progress) / (max - min);
- setRelativeProgress(this, name, relativeLocalProgress
- + childrenProgress);
+ setRelativeProgress(this, name,
+ relativeLocalProgress + childrenProgress);
}
}
return relativeProgress;
}
+ /**
+ * Set the total progress value (including the optional children
+ * {@link Progress}), on a 0 to 1 scale.
+ * <p>
+ * Will generate a changed event from this very {@link Progress}.
+ *
+ * @param relativeProgress
+ * the progress to set
+ */
+ public void setRelativeProgress(double relativeProgress) {
+ setRelativeProgress(this, name, relativeProgress);
+ }
+
/**
* Set the total progress value (including the optional children
* {@link Progress}), on a 0 to 1 scale.
*
* @param pg
- * the {@link Progress} to report as the progression emitter
+ * the {@link Progress} to report as the progression emitter (can
+ * be NULL, will then be considered the same as <tt>this</tt>)
* @param name
* the current name (if it is NULL, the first non-null name in
* the hierarchy will overwrite it) of the {@link Progress} who
/**
* Return the list of direct children of this {@link Progress}.
+ * <p>
+ * Can return an empty list, but never NULL.
*
* @return the children (Who will think of the children??)
*/
}
}
+ /**
+ * The weight of this children if it is actually a child of this.
+ *
+ * @param child
+ * the child to get the weight of
+ *
+ * @return NULL if this is not a child of this
+ */
+ public Double getWeight(Progress child) {
+ synchronized (lock) {
+ return children.get(child);
+ }
+ }
+
/**
* Notify the listeners that this {@link Progress} changed value.
*
if (progress.parent != null) {
throw new RuntimeException(String.format(
"Progress object %s cannot be added to %s, "
- + "as it already has a parent (%s)", progress.name,
- name, progress.parent.name));
+ + "as it already has a parent (%s)",
+ progress.name, name, progress.parent.name));
}
ProgressListener progressListener = new ProgressListener() {
}
}
- /**
- * Set the given value for the given key on this {@link Progress} and it's
- * children.
- *
- * @param key
- * the key
- * @param value
- * the value
- */
- public void put(String key, String value) {
- map.put(key, value);
- }
-
/**
* Set the given value for the given key on this {@link Progress} and it's
* children.
}
/**
- * Return the value associated with this key if any, NULL if not.
+ * Return the value associated with this key as a {@link String} if any,
+ * NULL if not.
* <p>
* If the value is not NULL but not a {@link String}, it will be converted
* via {@link Object#toString()}.
*
* @return the value or NULL
*/
- public String get(String key) {
+ public String getString(Object key) {
Object value = map.get(key);
if (value == null) {
return null;
public Object get(Object key) {
return map.get(key);
}
+
+ @Override
+ public String toString() {
+ return "[Progress]" //
+ + (name == null || name.isEmpty() ? "" : " " + name) //
+ + ": " + getProgress() + " / " + getMax() //
+ + (children.isEmpty() ? ""
+ : " (with " + children.size() + " children)") //
+ ;
+ }
}