ProcessStatus { public static ProcessStatus aggregateUnsustainable(ProcessStatus... statuses) { assertStatusesNotNull(statuses); List<ProcessStatus> usable = new ArrayList<ProcessStatus>(statuses.length); for (ProcessStatus status : statuses) { if (status.getState() != ProcessState.ERROR && status.getState() != ProcessState.CANCELLED) { usable.add(status); } } if (statuses.length > 0 && usable.size() == 0) { return new ProcessStatus(ProcessState.ERROR, 1f, statuses[0].message); } return aggregate(usable.toArray(new ProcessStatus[usable.size()])); } ProcessStatus(ProcessState state);  ProcessStatus(ProcessState state, float progress);  ProcessStatus(ProcessState state, float progress, String message); static ProcessStatus aggregate(ProcessStatus... statuses); ProcessState getState(); boolean isDone(); String getMessage(); float getProgress(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static ProcessStatus aggregateUnsustainable(ProcessStatus... statuses); final static ProcessStatus UNKNOWN; final static ProcessStatus SCHEDULED; }
@Test public void testAggregateUnsustainable() { assertEquals(ProcessStatus.UNKNOWN, ProcessStatus.aggregateUnsustainable()); assertEquals(new ProcessStatus(ProcessState.RUNNING, 0.4f, "Hello!"), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.RUNNING, 0.4f, "Hello!"))); assertEquals(new ProcessStatus(ProcessState.UNKNOWN, 0.0f, "Starting"), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.UNKNOWN, 0.0f, "Starting"), new ProcessStatus(ProcessState.UNKNOWN, 0.0f, ""), new ProcessStatus(ProcessState.UNKNOWN, 0.0f, ""))); assertEquals(new ProcessStatus(ProcessState.SCHEDULED, 0.0f, "Waiting"), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.SCHEDULED, 0.0f, "Waiting"), new ProcessStatus(ProcessState.UNKNOWN, 0.0f, ""), new ProcessStatus(ProcessState.UNKNOWN, 0.0f, ""))); assertEquals(new ProcessStatus(ProcessState.RUNNING, 0.3f, ""), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.RUNNING, 0.2f, ""), new ProcessStatus(ProcessState.RUNNING, 0.4f, ""), new ProcessStatus(ProcessState.RUNNING, 0.3f, ""))); assertEquals(new ProcessStatus(ProcessState.RUNNING, 0.8f, "Wait"), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.RUNNING, 0.4f, "Wait"), new ProcessStatus(ProcessState.COMPLETED, 1.0f, ""), new ProcessStatus(ProcessState.COMPLETED, 1.0f, ""))); assertEquals(new ProcessStatus(ProcessState.COMPLETED, 1.0f, "This was hard"), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.COMPLETED, 1.0f, ""), new ProcessStatus(ProcessState.COMPLETED, 1.0f, "This was hard"), new ProcessStatus(ProcessState.COMPLETED, 1.0f, ""))); assertEquals(new ProcessStatus(ProcessState.COMPLETED, 1.0f, ""), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.COMPLETED, 1.0f, ""), new ProcessStatus(ProcessState.ERROR, 0.4f, "I/O problem"), new ProcessStatus(ProcessState.COMPLETED, 1.0f, ""))); assertEquals(new ProcessStatus(ProcessState.RUNNING, (0.2f + 0.6f) / 2f, ""), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.RUNNING, 0.2f, ""), new ProcessStatus(ProcessState.RUNNING, 0.6f, ""), new ProcessStatus(ProcessState.CANCELLED, 0.1f, "Go away"))); assertEquals(new ProcessStatus(ProcessState.RUNNING, 0.2f, ""), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.RUNNING, 0.2f, ""), new ProcessStatus(ProcessState.ERROR, 0.6f, ""), new ProcessStatus(ProcessState.CANCELLED, 0.1f, "Go away"))); assertEquals(new ProcessStatus(ProcessState.ERROR, 1f, "bad error"), ProcessStatus.aggregateUnsustainable(new ProcessStatus(ProcessState.ERROR, 0.6f, "bad error"), new ProcessStatus(ProcessState.CANCELLED, 0.1f, "Go away"))); }