3535
3636/**
3737 * Keeps track of progress associated with an execution of progressable code.
38- * {@Link Task}s should <b>not</b> be updated by the code itself; it should be
38+ * {@link Task}s should <b>not</b> be updated by the code itself; it should be
3939 * update via {@link Progress#update()}.
4040 *
4141 * @author Gabriel Selzer
@@ -48,7 +48,7 @@ public class Task {
4848 private final Task parent ;
4949
5050 /** Subtasks created by this task */
51- private Set <Task > subTasks = new HashSet <>();
51+ private final Set <Task > subTasks = new HashSet <>();
5252
5353 /** Designates task completion */
5454 private boolean completed = false ;
@@ -60,34 +60,40 @@ public class Task {
6060 private long numSubTasks = 0 ;
6161
6262 /** Progress in current stage */
63- private AtomicLong current = new AtomicLong (0 );
63+ private final AtomicLong current = new AtomicLong (0 );
6464
6565 /** Maximum of current stage */
66- private AtomicLong max = new AtomicLong (1 );
66+ private final AtomicLong max = new AtomicLong (1 );
6767
6868 /** Number of within-task stages completed */
69- private AtomicLong stagesCompleted = new AtomicLong (0 );
69+ private final AtomicLong stagesCompleted = new AtomicLong (0 );
7070
7171 /** Number of subtasks completed */
72- private AtomicLong subTasksCompleted = new AtomicLong (0 );
72+ private final AtomicLong subTasksCompleted = new AtomicLong (0 );
7373
7474 /**
75- * True iff a call to {@link Task#defineTotalProgress(int, int)} has been made
75+ * True iff a call to {@link Task#defineTotalProgress(long, long)} has been
76+ * made
7677 */
7778 private boolean tasksDefined = false ;
7879
7980 /** True iff {@link Task#max} has been defined for the current stage */
8081 private boolean updateDefined = false ;
8182
83+ /** String identifying the task */
84+ private final String description ;
85+
8286 /** Computation status as defined by the task */
8387 private String status = "Executing..." ;
8488
85- public Task () {
89+ public Task (final String description ) {
8690 this .parent = null ;
91+ this .description = description ;
8792 }
8893
89- public Task (final Task parent ) {
94+ public Task (final Task parent , final String description ) {
9095 this .parent = parent ;
96+ this .description = description ;
9197 }
9298
9399 /**
@@ -111,8 +117,8 @@ public void complete() {
111117 *
112118 * @return the subtask.
113119 */
114- public synchronized Task createSubtask () {
115- final Task sub = new Task (this );
120+ public synchronized Task createSubtask (String description ) {
121+ final Task sub = new Task (this , description );
116122 subTasks .add (sub );
117123 return sub ;
118124 }
@@ -124,11 +130,11 @@ public synchronized Task createSubtask() {
124130 * {@link Task#progress()} are called, as otherwise total progress cannot be
125131 * defined.
126132 * <p>
127- * Under the hood, this method calls {@link #defineTotalProgress(int, int )}
133+ * Under the hood, this method calls {@link #defineTotalProgress(long, long )}
128134 *
129135 * @param totalStages the number of computation stages within the task
130136 */
131- public void defineTotalProgress (final int totalStages ) {
137+ public void defineTotalProgress (final long totalStages ) {
132138 defineTotalProgress (totalStages , 0 );
133139 }
134140
@@ -144,8 +150,8 @@ public void defineTotalProgress(final int totalStages) {
144150 * within the task. This <b>is not</b> the same as the number of
145151 * subtasks used (as one subtask may run multiple times).
146152 */
147- public void defineTotalProgress (final int totalStages ,
148- final int totalSubTasks )
153+ public void defineTotalProgress (final long totalStages ,
154+ final long totalSubTasks )
149155 {
150156 this .numStages = totalStages ;
151157 this .numSubTasks = totalSubTasks ;
@@ -164,8 +170,8 @@ public boolean isComplete() {
164170 /**
165171 * Calculates and returns the progress of the associated progressible
166172 * {@link Object}. If the total progress is defined using
167- * {@link Task#defineTotalProgress(int, int )}, then this method will return a
168- * {@code double} within the range [0, 1]. If the progress is <b>not</b>
173+ * {@link Task#defineTotalProgress(long, long )}, then this method will return
174+ * a {@code double} within the range [0, 1]. If the progress is <b>not</b>
169175 * defined, then this task will return {@code 0} until {@link #complete()} is
170176 * called; after that call this method will return {@code 1.}.
171177 *
@@ -180,15 +186,6 @@ public double progress() {
180186 return totalCompletion / (numStages + numSubTasks );
181187 }
182188
183- /**
184- * Returns {@code true} iff progress has been defined
185- *
186- * @return {@code true} iff progress has been defined
187- */
188- public boolean progressDefined () {
189- return tasksDefined ;
190- }
191-
192189 /**
193190 * Iff {@code task} was a task generated by this {@link Task}, then we update
194191 * progress based on its completion.
@@ -206,8 +203,6 @@ private void resetStage() {
206203 current .set (0 );
207204 stagesCompleted .incrementAndGet ();
208205 this .updateDefined = false ;
209- if (stagesCompleted .longValue () == numStages && subTasksCompleted
210- .longValue () == numSubTasks ) completed = true ;
211206 }
212207
213208 /**
@@ -241,6 +236,15 @@ public String status() {
241236 return status ;
242237 }
243238
239+ /**
240+ * The id of the progressible {@link Object}
241+ *
242+ * @return the id
243+ */
244+ public String description () {
245+ return description ;
246+ }
247+
244248 /**
245249 * Used by a progressible {@link Object}, through {@link Progress} to
246250 * increment progress
0 commit comments