/** Recursive search for child by id. */ protected ProgressStatusBase findById(String id) { if (id == null || id.isEmpty()) { return null; } if (id.equals(getId())) { return this; } for (ChildProgressStatus child : getChildProgressStatuses()) { ProgressStatusBase result = child.getProgressStatus().findById(id); if (result != null) { return result; } } return null; }
public synchronized int computeSumSteps() { int result = 0; for (ChildProgressStatus child : children) { if (child.allocatedSteps > 0) { result += child.progressStatus.computeSumSteps(); } } return getCurrentStepCount() + result; }
protected synchronized float computeCompleteSteps() { if (isComplete()) { return totalStepCount; } float realStepCount = currentStepCount; for (ChildProgressStatus child : children) { float childPortion = child.progressStatus.computeCompletePortion(); if (childPortion < 0) { return -1; } realStepCount += ((float) child.getAllocatedSteps()) * childPortion; } return realStepCount; }
public synchronized float computeCompletePortion() { if (isComplete()) { return 1; } // if (totalStepCount < 0) { // return -1; // } float realSteps = computeCompleteSteps(); if (realSteps < 0) { return -1; } if (realSteps == 0) { return 0; } if (totalStepCount < 0) { return -1; } else if (totalStepCount > 0) { return realSteps / ((float) totalStepCount); } else { return 1; } }
@Override public void complete(String message) { if (completeSilently()) { fireEvent(new ProgressStatusEventComplete(id, message)); } }
private void mirror(ProgressStatusBase source, ProgressStatus stat) { stat.setTotalStepCount(source.getTotalStepCount()); stat.setCurrentStepCount(source.getCurrentStepCount()); if (source.isComplete()) { stat.complete(); } for (ProgressStatusBase.ChildProgressStatus chld : source.getChildProgressStatuses()) { ProgressStatus dst = map.get(chld.getProgressStatus().getId()); if (dst == null) { dst = stat.createChild(chld.getProgressStatus().getName(), chld.getAllocatedSteps()); map.put(chld.getProgressStatus().getId(), dst); } mirror(chld.getProgressStatus(), dst); } }
public synchronized ProgressStatus createChild(String name, int allocatedSteps, int totalStepCount) { if (allocatedSteps < 0) { allocatedSteps = 0; } allocateStapsForChildProcess(allocatedSteps); ProgressStatusBase result = doCreateChild(name, totalStepCount); children.add(new ChildProgressStatus(allocatedSteps, result)); fireEvent(new ProgressStatusEventCreateChild(id, name, result.getId(), allocatedSteps, totalStepCount)); return result; }
ProgressStatusBase mirr = child.getProgressStatus(); if (!unknown) { int tsc = mirr.getTotalStepCount(); if (tsc < 0) { unknown = true; newCurrentStepCount += mirr.getCurrentStepCount(); super.fireEvent(event);
/** Ignores allocated steps. It's mirroring implementation. */ @Override public synchronized ProgressStatus createChild(String name, int allocatedSteps, int totalStepCount) { ProgressStatusBase result = doCreateChild(name, totalStepCount); children.add(new ChildProgressStatus(allocatedSteps, result)); fireEvent(new ProgressStatusEventCreateChild(id, name, result.getId(), 0, totalStepCount)); return result; }
@Override public void complete() { complete(null); }
/** Complete this {@code ProgressStatus} and all sub-ProgressStatuses * but does not fire event to parent statuses. */ protected synchronized boolean completeSilently() { if (completed) { return false; } if (totalStepCount >= 0) { currentStepCount = totalStepCount; } completed = true; for (ChildProgressStatus child : children) { child.getProgressStatus().completeSilently(); } return true; }
@Override public String toString() { StringBuilder result = new StringBuilder(); if (name == null) { result.append("NoName "); } else { result.append(name).append(' '); } float realSteps = computeCompleteSteps(); if (realSteps < 0) { result.append(currentStepCount).append(" / ").append('?'); } else { result.append(Math.round(realSteps)).append(" / "); result.append(totalStepCount < 0 ? "?" : String.valueOf(totalStepCount)); } return result.toString(); }
public synchronized ProgressStatus createChild(String name, int allocatedSteps, int totalStepCount) { if (allocatedSteps < 0) { allocatedSteps = 0; } allocateStapsForChildProcess(allocatedSteps); ProgressStatusBase result = doCreateChild(name, totalStepCount); children.add(new ChildProgressStatus(allocatedSteps, result)); fireEvent(new ProgressStatusEventCreateChild(id, name, result.getId(), allocatedSteps, totalStepCount)); return result; }
ProgressStatusBase mirr = child.getProgressStatus(); if (!unknown) { int tsc = mirr.getTotalStepCount(); if (tsc < 0) { unknown = true; newCurrentStepCount += mirr.getCurrentStepCount(); super.fireEvent(event);
public synchronized float computeCompletePortion() { if (isComplete()) { return 1; } // if (totalStepCount < 0) { // return -1; // } float realSteps = computeCompleteSteps(); if (realSteps < 0) { return -1; } if (realSteps == 0) { return 0; } if (totalStepCount < 0) { return -1; } else if (totalStepCount > 0) { return realSteps / ((float) totalStepCount); } else { return 1; } }
@Override public void complete(String message) { if (completeSilently()) { fireEvent(new ProgressStatusEventComplete(id, message)); } }
/** Ignores allocated steps. It's mirroring implementation. */ @Override public synchronized ProgressStatus createChild(String name, int allocatedSteps, int totalStepCount) { ProgressStatusBase result = doCreateChild(name, totalStepCount); children.add(new ChildProgressStatus(allocatedSteps, result)); fireEvent(new ProgressStatusEventCreateChild(id, name, result.getId(), 0, totalStepCount)); return result; }
@Override public void complete() { complete(null); }
/** Complete this {@code ProgressStatus} and all sub-ProgressStatuses * but does not fire event to parent statuses. */ protected synchronized boolean completeSilently() { if (completed) { return false; } if (totalStepCount >= 0) { currentStepCount = totalStepCount; } completed = true; for (ChildProgressStatus child : children) { child.getProgressStatus().completeSilently(); } return true; }