checkstyle

This commit is contained in:
jendave
2011-10-26 20:05:11 +00:00
parent c8140b3c2e
commit 108609c6c1
9 changed files with 812 additions and 521 deletions

View File

@@ -1,45 +1,77 @@
package net.slightlymagic.braids.util.lambda; package net.slightlymagic.braids.util.lambda;
import net.slightlymagic.braids.util.UtilFunctions;
import static net.slightlymagic.braids.util.UtilFunctions.checkNotNull; import static net.slightlymagic.braids.util.UtilFunctions.checkNotNull;
import net.slightlymagic.braids.util.UtilFunctions;
/** /**
* This embodies a promise to invoke a certain method at a later time; the * This embodies a promise to invoke a certain method at a later time; the
* FrozenCall remembers the arguments to use and the return type. * FrozenCall remembers the arguments to use and the return type.
* *
* @param <T> the return type of apply * @param <T>
* the return type of apply
* *
* @see Thunk * @see Thunk
*/ */
public class FrozenCall<T> implements Thunk<T> { public class FrozenCall<T> implements Thunk<T> {
private Lambda<T> proc; private Lambda<T> proc;
private Object[] args; private Object[] args;
public FrozenCall(Lambda<T> proc, Object[] args) { /**
checkNotNull("proc", proc); * Instantiates a new frozen call.
checkNotNull("args", args); *
* @param proc
* the proc
* @param args
* the args
*/
public FrozenCall(final Lambda<T> proc, final Object[] args) {
checkNotNull("proc", proc);
checkNotNull("args", args);
this.proc = proc; this.proc = proc;
this.args = args; this.args = args;
} }
public T apply() { /*
return proc.apply(args); * (non-Javadoc)
} *
* @see net.slightlymagic.braids.util.lambda.Thunk#apply()
*/
/**
* @return <T>
*/
public final T apply() {
return proc.apply(args);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
/**
* @return boolean
* @param obj Object
*/
@Override
public final boolean equals(final Object obj) {
FrozenCall<T> that = UtilFunctions.checkNullOrNotInstance(this, obj);
if (that == null) {
return false;
} else if (!this.proc.equals(that.proc)) {
return false;
} else if (this.args.length != that.args.length) {
return false;
}
@Override for (int i = 0; i < args.length; i++) {
public boolean equals(Object obj) { if (this.args[i] == null && that.args[i] != null) {
FrozenCall<T> that = UtilFunctions.checkNullOrNotInstance(this, obj); return false;
if (that == null) return false; } else if (!this.args[i].equals(that.args[i])) {
else if (!this.proc.equals(that.proc)) return false; return false;
else if (this.args.length != that.args.length) return false; }
}
for (int i = 0; i < args.length; i++) { return true;
if (this.args[i] == null && that.args[i] != null) return false; }
else if (!this.args[i].equals(that.args[i])) return false;
}
return true;
}
} }

View File

@@ -1,5 +1,19 @@
package net.slightlymagic.braids.util.lambda; package net.slightlymagic.braids.util.lambda;
/**
* The Interface Lambda.
*
* @param <R>
* the generic type
*/
public interface Lambda<R> { public interface Lambda<R> {
public abstract R apply(Object[] args);
/**
* Apply.
*
* @param args
* the args
* @return the r
*/
R apply(Object[] args);
} }

View File

@@ -1,13 +1,39 @@
package net.slightlymagic.braids.util.lambda; package net.slightlymagic.braids.util.lambda;
public abstract class Lambda1<R,A1> implements Lambda<R> { /**
* The Class Lambda1.
*
* @param <R>
* the generic type
* @param <A1>
* the generic type
*/
public abstract class Lambda1<R, A1> implements Lambda<R> {
public abstract R apply(A1 arg1); /**
* Apply.
*
* @param arg1
* the arg1
* @return the r
*/
public abstract R apply(A1 arg1);
@SuppressWarnings("unchecked") /*
//TODO @Override * (non-Javadoc)
public R apply(Object[] args) { *
return apply((A1) args[0]); * @see
} * net.slightlymagic.braids.util.lambda.Lambda#apply(java.lang.Object[])
*/
// TODO @Override
/**
* @return R
* @param args Object[]
*/
@SuppressWarnings("unchecked")
public final R apply(final Object[] args) {
return apply((A1) args[0]);
}
} }

View File

@@ -1,13 +1,43 @@
package net.slightlymagic.braids.util.lambda; package net.slightlymagic.braids.util.lambda;
public abstract class Lambda2<R,A1,A2> implements Lambda<R> { /**
* The Class Lambda2.
*
* @param <R>
* the generic type
* @param <A1>
* the generic type
* @param <A2>
* the generic type
*/
public abstract class Lambda2<R, A1, A2> implements Lambda<R> {
public abstract R apply(A1 arg1, A2 arg2); /**
* Apply.
*
* @param arg1
* the arg1
* @param arg2
* the arg2
* @return the r
*/
public abstract R apply(A1 arg1, A2 arg2);
@SuppressWarnings("unchecked") /*
//TODO @Override * (non-Javadoc)
public R apply(Object[] args) { *
return apply((A1) args[0], (A2) args[1]); * @see
} * net.slightlymagic.braids.util.lambda.Lambda#apply(java.lang.Object[])
*/
// TODO @Override
/**
* @return R
* @param args Object[]
*/
@SuppressWarnings("unchecked")
public final R apply(final Object[] args) {
return apply((A1) args[0], (A2) args[1]);
}
} }

View File

@@ -1,13 +1,47 @@
package net.slightlymagic.braids.util.lambda; package net.slightlymagic.braids.util.lambda;
public abstract class Lambda3<R,A1,A2,A3> implements Lambda<R> { /**
* The Class Lambda3.
*
* @param <R>
* the generic type
* @param <A1>
* the generic type
* @param <A2>
* the generic type
* @param <A3>
* the generic type
*/
public abstract class Lambda3<R, A1, A2, A3> implements Lambda<R> {
public abstract R apply(A1 arg1, A2 arg2, A3 arg3); /**
* Apply.
*
* @param arg1
* the arg1
* @param arg2
* the arg2
* @param arg3
* the arg3
* @return the r
*/
public abstract R apply(A1 arg1, A2 arg2, A3 arg3);
@SuppressWarnings("unchecked") /*
//TODO @Override * (non-Javadoc)
public R apply(Object[] args) { *
return apply((A1) args[0], (A2) args[1], (A3) args[2]); * @see
} * net.slightlymagic.braids.util.lambda.Lambda#apply(java.lang.Object[])
*/
// TODO @Override
/**
* @return R
* @param args Object[]
*/
@SuppressWarnings("unchecked")
public final R apply(final Object[] args) {
return apply((A1) args[0], (A2) args[1], (A3) args[2]);
}
} }

View File

@@ -1,5 +1,17 @@
package net.slightlymagic.braids.util.lambda; package net.slightlymagic.braids.util.lambda;
/**
* The Interface Thunk.
*
* @param <T>
* the generic type
*/
public interface Thunk<T> { public interface Thunk<T> {
public abstract T apply();
/**
* Apply.
*
* @return the t
*/
T apply();
} }

View File

@@ -14,24 +14,28 @@ import com.esotericsoftware.minlog.Log;
*/ */
public class BaseProgressMonitor implements BraidsProgressMonitor { public class BaseProgressMonitor implements BraidsProgressMonitor {
private int numPhases; private int numPhases;
private int currentPhase; private int currentPhase;
private long totalUnitsThisPhase; private long totalUnitsThisPhase;
private long unitsCompletedSoFarThisPhase; private long unitsCompletedSoFarThisPhase;
private float minUIUpdateIntervalSec; private float minUIUpdateIntervalSec;
private long lastUIUpdateTime; private long lastUIUpdateTime;
private long phaseOneStartTime; private long phaseOneStartTime;
private long currentPhaseStartTime; private long currentPhaseStartTime;
private float currentPhaseExponent; private float currentPhaseExponent;
private long[] phaseDurationHistorySecList; private long[] phaseDurationHistorySecList;
private float[] phaseWeights; private float[] phaseWeights;
public final int SECONDS_PER_MINUTE = 60; /** The SECOND s_ pe r_ minute. */
public final int SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE; public final int SECONDS_PER_MINUTE = 60;
public final int SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
/** /** The SECOND s_ pe r_ hour. */
* Convenience for public final int SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
* BaseProgressMonitor(1, 1, 2.0f, null).
/** The SECOND s_ pe r_ day. */
public final int SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
/**
* Convenience for BaseProgressMonitor(1, 1, 2.0f, null).
* *
* @see #BaseProgressMonitor(int,long,float,float[]) * @see #BaseProgressMonitor(int,long,float,float[])
*/ */
@@ -39,84 +43,97 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
this(1, 1L, 2.0f, null); this(1, 1L, 2.0f, null);
} }
/** /**
* Convenience for * Convenience for BaseProgressMonitor(numPhases, 1, 2.0f, null).
* BaseProgressMonitor(numPhases, 1, 2.0f, null).
* *
* @param numPhases
* the num phases
* @see #BaseProgressMonitor(int,long,float,float[]) * @see #BaseProgressMonitor(int,long,float,float[])
*/ */
public BaseProgressMonitor(int numPhases) { public BaseProgressMonitor(final int numPhases) {
this(numPhases, 1L, 2.0f, null); this(numPhases, 1L, 2.0f, null);
} }
/** /**
* Convenience for * Convenience for BaseProgressMonitor(numPhases, totalUnitsFirstPhase,
* BaseProgressMonitor(numPhases, totalUnitsFirstPhase, 2.0f, null). * 2.0f, null).
* *
* @param numPhases
* the num phases
* @param totalUnitsFirstPhase
* the total units first phase
* @see #BaseProgressMonitor(int,long,float,float[]) * @see #BaseProgressMonitor(int,long,float,float[])
*/ */
public BaseProgressMonitor(int numPhases, long totalUnitsFirstPhase) { public BaseProgressMonitor(final int numPhases, final long totalUnitsFirstPhase) {
this(numPhases, totalUnitsFirstPhase, 2.0f, null); this(numPhases, totalUnitsFirstPhase, 2.0f, null);
} }
/** /**
* Convenience for * Convenience for BaseProgressMonitor(numPhases, totalUnitsFirstPhase,
* BaseProgressMonitor(numPhases, totalUnitsFirstPhase, * minUIUpdateIntervalSec, null).
* minUIUpdateIntervalSec, null). *
* * @param numPhases
* the num phases
* @param totalUnitsFirstPhase
* the total units first phase
* @param minUIUpdateIntervalSec
* the min ui update interval sec
* @see #BaseProgressMonitor(int,long,float,float[]) * @see #BaseProgressMonitor(int,long,float,float[])
*/ */
public BaseProgressMonitor(int numPhases, long totalUnitsFirstPhase, public BaseProgressMonitor(final int numPhases,
float minUIUpdateIntervalSec) final long totalUnitsFirstPhase, final float minUIUpdateIntervalSec) {
{ this(numPhases, totalUnitsFirstPhase, minUIUpdateIntervalSec, null);
this(numPhases, totalUnitsFirstPhase, minUIUpdateIntervalSec, null);
} }
/** /**
* Initializes fields and starts the timers. * Initializes fields and starts the timers.
* *
* @param numPhases the total number of phases we will monitor * @param numPhases
* the total number of phases we will monitor
* *
* @param totalUnitsFirstPhase how many units to expect in phase 1 * @param totalUnitsFirstPhase
* how many units to expect in phase 1
* *
* @param minUIUpdateIntervalSec the approximate interval at which we * @param minUIUpdateIntervalSec
* update the user interface, in seconds * the approximate interval at which we update the user
* interface, in seconds
* *
* @param phaseWeights may be null; if not null, this indicates the * @param phaseWeights
* relative weight of each phase in terms of time to complete all phases. * may be null; if not null, this indicates the relative weight
* Index 0 of this array indicates phase 1's weight, index 1 indicates * of each phase in terms of time to complete all phases. Index 0
* the weight of phase 2, and so on. If null, all phases are considered to * of this array indicates phase 1's weight, index 1 indicates
* take an equal amount of time to complete, which is equivalent to setting * the weight of phase 2, and so on. If null, all phases are
* all phase weights to 1.0f. For example, if there are two phases, and * considered to take an equal amount of time to complete, which
* the phase weights are set to {2.0f, 1.0f}, then the methods that compute * is equivalent to setting all phase weights to 1.0f. For
* the final ETA (Estimated Time of Arrival or completion) will assume that * example, if there are two phases, and the phase weights are
* phase 2 takes half as long as phase 1. In other words, the operation * set to {2.0f, 1.0f}, then the methods that compute the final
* will spend 67% of its time in phase 1, and 33% of its time in phase 2. * ETA (Estimated Time of Arrival or completion) will assume that
* phase 2 takes half as long as phase 1. In other words, the
* operation will spend 67% of its time in phase 1, and 33% of
* its time in phase 2.
*/ */
public BaseProgressMonitor(int numPhases, long totalUnitsFirstPhase, public BaseProgressMonitor(final int numPhases, final long totalUnitsFirstPhase,
float minUIUpdateIntervalSec, float[] phaseWeights) final float minUIUpdateIntervalSec, final float[] phaseWeights) {
{ this.numPhases = numPhases;
this.numPhases = numPhases; this.currentPhase = 1;
this.currentPhase = 1; this.unitsCompletedSoFarThisPhase = 0L;
this.unitsCompletedSoFarThisPhase = 0L; this.minUIUpdateIntervalSec = minUIUpdateIntervalSec;
this.minUIUpdateIntervalSec = minUIUpdateIntervalSec; this.lastUIUpdateTime = 0L;
this.lastUIUpdateTime = 0L; this.phaseOneStartTime = new Date().getTime() / 1000;
this.phaseOneStartTime = new Date().getTime()/1000; this.currentPhaseStartTime = this.phaseOneStartTime;
this.currentPhaseStartTime = this.phaseOneStartTime; this.currentPhaseExponent = 1;
this.currentPhaseExponent = 1; this.phaseDurationHistorySecList = new long[numPhases];
this.phaseDurationHistorySecList = new long[numPhases];
if (phaseWeights == null) { if (phaseWeights == null) {
this.phaseWeights = new float[numPhases]; this.phaseWeights = new float[numPhases];
for (int ix = 0; ix < numPhases; ix++) { for (int ix = 0; ix < numPhases; ix++) {
this.phaseWeights[ix] = 1.0f; this.phaseWeights[ix] = 1.0f;
} }
} } else {
else { this.phaseWeights = phaseWeights;
this.phaseWeights = phaseWeights; }
}
setTotalUnitsThisPhase(totalUnitsFirstPhase); setTotalUnitsThisPhase(totalUnitsFirstPhase);
} }
@@ -124,126 +141,163 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
* Does nothing. * Does nothing.
*/ */
public void dispose() { public void dispose() {
;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getNumPhases() * Gets the num phases.
*/ *
public int getNumPhases() { * @return the num phases
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getNumPhases()
*/
public final int getNumPhases() {
return this.numPhases; return this.numPhases;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getMinUpdateIntervalSec() * Gets the min update interval sec.
*/ *
public float getMinUpdateIntervalSec() { * @return the min update interval sec
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getMinUpdateIntervalSec()
*/
public final float getMinUpdateIntervalSec() {
return this.minUIUpdateIntervalSec; return this.minUIUpdateIntervalSec;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getCurrentPhase() * Gets the current phase.
*/ *
public int getCurrentPhase() { * @return the current phase
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getCurrentPhase()
*/
public final int getCurrentPhase() {
return this.currentPhase; return this.currentPhase;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getUnitsCompletedSoFarThisPhase() * Gets the units completed so far this phase.
*/ *
public long getUnitsCompletedSoFarThisPhase() { * @return the units completed so far this phase
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getUnitsCompletedSoFarThisPhase()
*/
public final long getUnitsCompletedSoFarThisPhase() {
return this.unitsCompletedSoFarThisPhase; return this.unitsCompletedSoFarThisPhase;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getTotalUnitsThisPhase() * Gets the total units this phase.
*/ *
public long getTotalUnitsThisPhase() { * @return the total units this phase
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getTotalUnitsThisPhase()
*/
public final long getTotalUnitsThisPhase() {
return this.totalUnitsThisPhase; return this.totalUnitsThisPhase;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getLastUIUpdateTime() * Gets the last ui update time.
*/ *
public long getLastUIUpdateTime() { * @return the last ui update time
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getLastUIUpdateTime()
*/
public final long getLastUIUpdateTime() {
return this.lastUIUpdateTime; return this.lastUIUpdateTime;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getPhaseOneStartTime() * Gets the phase one start time.
*/ *
public long getPhaseOneStartTime() { * @return the phase one start time
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getPhaseOneStartTime()
*/
public final long getPhaseOneStartTime() {
return this.phaseOneStartTime; return this.phaseOneStartTime;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getCurrentPhaseStartTime() * Gets the current phase start time.
*/ *
public long getCurrentPhaseStartTime() { * @return the current phase start time
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getCurrentPhaseStartTime()
*/
public final long getCurrentPhaseStartTime() {
return this.currentPhaseStartTime; return this.currentPhaseStartTime;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#setMinUpdateIntervalSec(float) * Sets the min update interval sec.
*/ *
public void setMinUpdateIntervalSec(float value) { * @param value
* the new min update interval sec
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#setMinUpdateIntervalSec(float)
*/
public final void setMinUpdateIntervalSec(final float value) {
this.minUIUpdateIntervalSec = value; this.minUIUpdateIntervalSec = value;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#setTotalUnitsThisPhase(long) * Sets the total units this phase.
*/ *
public void setTotalUnitsThisPhase(long value) { * @param value
* the new total units this phase
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#setTotalUnitsThisPhase(long)
*/
public void setTotalUnitsThisPhase(final long value) {
this.totalUnitsThisPhase = value; this.totalUnitsThisPhase = value;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getPercentCompleteOfThisPhaseAsString() * Gets the percent complete of this phase as string.
*/ *
public String getPercentCompleteOfThisPhaseAsString() { * @return the percent complete of this phase as string
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getPercentCompleteOfThisPhaseAsString()
*/
public final String getPercentCompleteOfThisPhaseAsString() {
Float percent = getPercentCompleteOfThisPhaseAsFloat(); Float percent = getPercentCompleteOfThisPhaseAsFloat();
if (percent != null) { if (percent != null) {
return Integer.toString((int) (float) percent); return Integer.toString((int) (float) percent);
} } else {
else {
return "??"; return "??";
} }
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getTotalPercentCompleteAsString() * Gets the total percent complete as string.
*/ *
public String getTotalPercentCompleteAsString() { * @return the total percent complete as string
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getTotalPercentCompleteAsString()
*/
public final String getTotalPercentCompleteAsString() {
Float percent = getTotalPercentCompleteAsFloat(); Float percent = getTotalPercentCompleteAsFloat();
if (percent == null) { if (percent == null) {
return "??"; return "??";
} } else {
else {
return Integer.toString((int) (float) percent); return Integer.toString((int) (float) percent);
} }
} }
/** /**
* Convenience for getRelativeETAAsString(false), meaning to compute the * Convenience for getRelativeETAAsString(false), meaning to compute the
* value for the end of the last phase. * value for the end of the last phase.
* *
* @see #getRelativeETAAsString(boolean) * @return the relative eta as string
*/ * @see #getRelativeETAAsString(boolean)
public String getRelativeETAAsString() { */
return getRelativeETAAsString(false); public final String getRelativeETAAsString() {
return getRelativeETAAsString(false);
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getRelativeETAAsString(boolean) * Gets the relative eta as string.
*/ *
public String getRelativeETAAsString(boolean thisPhaseOnly) { * @param thisPhaseOnly
* the this phase only
* @return the relative eta as string
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getRelativeETAAsString(boolean)
*/
public final String getRelativeETAAsString(final boolean thisPhaseOnly) {
Integer etaSec = getRelativeETASec(thisPhaseOnly); Integer etaSec = getRelativeETASec(thisPhaseOnly);
@@ -255,17 +309,17 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
if (etaSec > SECONDS_PER_DAY) { if (etaSec > SECONDS_PER_DAY) {
result += Integer.toString(etaSec / SECONDS_PER_DAY); result += Integer.toString(etaSec / SECONDS_PER_DAY);
result += " da, "; result += " da, ";
etaSec %= SECONDS_PER_DAY; // Shave off the portion recorded. etaSec %= SECONDS_PER_DAY; // Shave off the portion recorded.
} }
if (result.length() > 0 || etaSec > SECONDS_PER_HOUR) { if (result.length() > 0 || etaSec > SECONDS_PER_HOUR) {
result += Integer.toString(etaSec / SECONDS_PER_HOUR); result += Integer.toString(etaSec / SECONDS_PER_HOUR);
result += " hr, "; result += " hr, ";
etaSec %= SECONDS_PER_HOUR; // Shave off the portion recorded. etaSec %= SECONDS_PER_HOUR; // Shave off the portion recorded.
} }
if (result.length() > 0 || etaSec > SECONDS_PER_MINUTE) { if (result.length() > 0 || etaSec > SECONDS_PER_MINUTE) {
result += Integer.toString(etaSec / SECONDS_PER_MINUTE); result += Integer.toString(etaSec / SECONDS_PER_MINUTE);
result += " min, "; result += " min, ";
etaSec %= SECONDS_PER_MINUTE; // Shave off the portion recorded. etaSec %= SECONDS_PER_MINUTE; // Shave off the portion recorded.
} }
result += Integer.toString(etaSec); result += Integer.toString(etaSec);
@@ -275,77 +329,88 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
} }
/** /**
* Convenience for getAbsoluteETAAsLocalTimeString(false), meaning to * Convenience for getAbsoluteETAAsLocalTimeString(false), meaning to
* compute the value for the end of the last phase. * compute the value for the end of the last phase.
* *
* @see #getAbsoluteETAAsLocalTimeString(boolean) * @return the absolute eta as local time string
*/ * @see #getAbsoluteETAAsLocalTimeString(boolean)
public String getAbsoluteETAAsLocalTimeString() { */
return getAbsoluteETAAsLocalTimeString(false); public final String getAbsoluteETAAsLocalTimeString() {
return getAbsoluteETAAsLocalTimeString(false);
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getAbsoluteETAAsLocalTimeString(boolean) * Gets the absolute eta as local time string.
*/ *
public String getAbsoluteETAAsLocalTimeString(boolean thisPhaseOnly) { * @param thisPhaseOnly
* the this phase only
* @return the absolute eta as local time string
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getAbsoluteETAAsLocalTimeString(boolean)
*/
public final String getAbsoluteETAAsLocalTimeString(final boolean thisPhaseOnly) {
Long etaTime = getAbsoluteETATime(thisPhaseOnly); Long etaTime = getAbsoluteETATime(thisPhaseOnly);
if (etaTime == null) { if (etaTime == null) {
return "unknown"; return "unknown";
} }
return (new Date(etaTime*1000).toString()); return (new Date(etaTime * 1000).toString());
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#incrementUnitsCompletedThisPhase(long) * Increment units completed this phase.
*/ *
public void incrementUnitsCompletedThisPhase(long numUnits) { * @param numUnits
* the num units
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#incrementUnitsCompletedThisPhase(long)
*/
public void incrementUnitsCompletedThisPhase(final long numUnits) {
this.unitsCompletedSoFarThisPhase += numUnits; this.unitsCompletedSoFarThisPhase += numUnits;
} }
/** /**
* Subclasses must call this immediately after updating the UI, to * Subclasses must call this immediately after updating the UI, to preserve
* preserve the integrity of the shouldUpdateUI method. * the integrity of the shouldUpdateUI method.
*/ */
public void justUpdatedUI() { public final void justUpdatedUI() {
this.lastUIUpdateTime = new Date().getTime()/1000; this.lastUIUpdateTime = new Date().getTime() / 1000;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#shouldUpdateUI() * Should update ui.
*/ *
public boolean shouldUpdateUI() { * @return true, if successful
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#shouldUpdateUI()
*/
public final boolean shouldUpdateUI() {
doctorStartTimes(); doctorStartTimes();
long nowTime = (new Date().getTime()/1000); long nowTime = (new Date().getTime() / 1000);
if (nowTime - this.lastUIUpdateTime >= this.minUIUpdateIntervalSec || if (nowTime - this.lastUIUpdateTime >= this.minUIUpdateIntervalSec
(this.getUnitsCompletedSoFarThisPhase() == || (this.getUnitsCompletedSoFarThisPhase() == this.getTotalUnitsThisPhase())) {
this.getTotalUnitsThisPhase()))
{
return true; return true;
} } else {
else {
return false; return false;
} }
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#markCurrentPhaseAsComplete(long) * Mark current phase as complete.
*/ *
public void markCurrentPhaseAsComplete(long totalUnitsNextPhase) { * @param totalUnitsNextPhase
* the total units next phase
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#markCurrentPhaseAsComplete(long)
*/
public final void markCurrentPhaseAsComplete(final long totalUnitsNextPhase) {
if ((this.currentPhase > this.numPhases)) { if ((this.currentPhase > this.numPhases)) {
String message = "The phase just completed ("; String message = "The phase just completed (";
message += this.currentPhase; message += this.currentPhase;
message += ") is greater than the total number "; message += ") is greater than the total number ";
message += "of anticipated phases ("; message += "of anticipated phases (";
message += this.numPhases; message += this.numPhases;
message += "); the latter is probably incorrect."; message += "); the latter is probably incorrect.";
Log.warn(message); Log.warn(message);
} }
@@ -355,62 +420,68 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
setTotalUnitsThisPhase(totalUnitsNextPhase); setTotalUnitsThisPhase(totalUnitsNextPhase);
this.currentPhaseExponent = 1; this.currentPhaseExponent = 1;
long nowTime = (new Date().getTime()/1000); long nowTime = (new Date().getTime() / 1000);
long durationOfThisPhaseSec = nowTime - this.currentPhaseStartTime; long durationOfThisPhaseSec = nowTime - this.currentPhaseStartTime;
if (durationOfThisPhaseSec < 0) { if (durationOfThisPhaseSec < 0) {
durationOfThisPhaseSec = 0; durationOfThisPhaseSec = 0;
} }
if (0 <= currentPhase-2 && currentPhase-2 < phaseDurationHistorySecList.length) { if (0 <= currentPhase - 2 && currentPhase - 2 < phaseDurationHistorySecList.length) {
this.phaseDurationHistorySecList[currentPhase-2] = durationOfThisPhaseSec; this.phaseDurationHistorySecList[currentPhase - 2] = durationOfThisPhaseSec;
} }
this.currentPhaseStartTime = nowTime; this.currentPhaseStartTime = nowTime;
if (this.currentPhase >= this.numPhases) { if (this.currentPhase >= this.numPhases) {
String message = "Actual individual phase durations: ["; String message = "Actual individual phase durations: [";
for (int ix = 0 ; ix < phaseDurationHistorySecList.length ; ix++) { for (int ix = 0; ix < phaseDurationHistorySecList.length; ix++) {
message += phaseDurationHistorySecList[ix] + ", "; message += phaseDurationHistorySecList[ix] + ", ";
} }
Log.info(message + ']'); Log.info(message + ']');
} }
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#sendMessage(java.lang.String) * Send message.
*/ *
public void sendMessage(String message) { * @param message
; * the message
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#sendMessage(java.lang.String)
*/
public final void sendMessage(final String message) {
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#setCurrentPhaseAsExponential(float) * Sets the current phase as exponential.
*/ *
public void setCurrentPhaseAsExponential(float value) { * @param value
* the new current phase as exponential
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#setCurrentPhaseAsExponential(float)
*/
public final void setCurrentPhaseAsExponential(final float value) {
this.currentPhaseExponent = value; this.currentPhaseExponent = value;
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getCurrentPhaseExponent() * Gets the current phase exponent.
*/ *
public float getCurrentPhaseExponent() { * @return the current phase exponent
* @see net.slightlymagic.braids.util.progress_monitor.BraidsProgressMonitor#getCurrentPhaseExponent()
*/
public final float getCurrentPhaseExponent() {
return this.currentPhaseExponent; return this.currentPhaseExponent;
} }
/** /**
* Gets the percent complete of this phase as float.
*
* @return number in range [0.0, 100.0] or null. * @return number in range [0.0, 100.0] or null.
*/ */
protected Float getPercentCompleteOfThisPhaseAsFloat() { protected final Float getPercentCompleteOfThisPhaseAsFloat() {
if (this.totalUnitsThisPhase < 1 || if (this.totalUnitsThisPhase < 1 || this.unitsCompletedSoFarThisPhase > this.totalUnitsThisPhase) {
this.unitsCompletedSoFarThisPhase > this.totalUnitsThisPhase) {
return null; return null;
} } else {
else { float ratio = ((float) (this.unitsCompletedSoFarThisPhase)) / ((float) this.totalUnitsThisPhase);
float ratio = ((float) (this.unitsCompletedSoFarThisPhase)) /
((float) this.totalUnitsThisPhase);
ratio = (float) Math.pow(ratio, this.getCurrentPhaseExponent()); ratio = (float) Math.pow(ratio, this.getCurrentPhaseExponent());
@@ -418,11 +489,12 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
} }
} }
/** /**
* Returns number in range [0.0, 100.0] or null. * Returns number in range [0.0, 100.0] or null.
*
* @return the total percent complete as float
*/ */
protected Float getTotalPercentCompleteAsFloat() { protected final Float getTotalPercentCompleteAsFloat() {
long totalPoints = 0; long totalPoints = 0;
for (float weight : this.phaseWeights) { for (float weight : this.phaseWeights) {
totalPoints += weight * 100; totalPoints += weight * 100;
@@ -437,61 +509,70 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
} }
long pointsSoFar = 0; long pointsSoFar = 0;
for (int ix = 0; ix < this.currentPhase-1; ix++) { for (int ix = 0; ix < this.currentPhase - 1; ix++) {
// We get full points for (all the phases completed prior to this one. // We get full points for (all the phases completed prior to this
// one.
pointsSoFar += phaseWeights[ix] * 100; pointsSoFar += phaseWeights[ix] * 100;
} }
pointsSoFar += percentThisPhase * this.phaseWeights[this.currentPhase-1]; pointsSoFar += percentThisPhase * this.phaseWeights[this.currentPhase - 1];
if (totalPoints <= 0.0 || pointsSoFar > totalPoints) { if (totalPoints <= 0.0 || pointsSoFar > totalPoints) {
return null; return null;
} } else {
else {
return (100.0f * pointsSoFar) / totalPoints; return (100.0f * pointsSoFar) / totalPoints;
} }
} }
/** /**
* Convenience for getRelativeETASec(false), meaning to compute the value * Convenience for getRelativeETASec(false), meaning to compute the value
* for the end of the last phase. * for the end of the last phase.
* *
* @return the relative eta sec
* @see #getRelativeETASec(boolean) * @see #getRelativeETASec(boolean)
*/ */
protected Integer getRelativeETASec() { protected final Integer getRelativeETASec() {
return getRelativeETASec(false); return getRelativeETASec(false);
} }
/** /**
* @return estimated seconds until completion for either thisPhaseOnly * Gets the relative eta sec.
* or for the entire operation. May return null if unknown. *
* @param thisPhaseOnly
* the this phase only
* @return estimated seconds until completion for either thisPhaseOnly or
* for the entire operation. May return null if unknown.
*/ */
protected Integer getRelativeETASec(boolean thisPhaseOnly) { protected final Integer getRelativeETASec(final boolean thisPhaseOnly) {
Long absoluteETATime = getAbsoluteETATime(thisPhaseOnly); Long absoluteETATime = getAbsoluteETATime(thisPhaseOnly);
if (absoluteETATime == null) { if (absoluteETATime == null) {
return null; return null;
} }
return (int) (absoluteETATime - (new Date().getTime()/1000)); return (int) (absoluteETATime - (new Date().getTime() / 1000));
} }
/** /**
* Convenience for getAbsoluteETATime(false), meaning to compute the value * Convenience for getAbsoluteETATime(false), meaning to compute the value
* for the end of all phases. * for the end of all phases.
* *
* @return the absolute eta time
* @see #getAbsoluteETATime(boolean) * @see #getAbsoluteETATime(boolean)
*/ */
protected Long getAbsoluteETATime() { protected final Long getAbsoluteETATime() {
return getAbsoluteETATime(false); return getAbsoluteETATime(false);
} }
/** /**
* Gets the absolute eta time.
*
* @param thisPhaseOnly
* the this phase only
* @return the estimated time (in absolute seconds) at which thisPhaseOnly * @return the estimated time (in absolute seconds) at which thisPhaseOnly
* or the entire operation will be completed. May return null if (unknown. * or the entire operation will be completed. May return null if
* (unknown.
*/ */
protected Long getAbsoluteETATime(boolean thisPhaseOnly) { protected final Long getAbsoluteETATime(boolean thisPhaseOnly) {
doctorStartTimes(); doctorStartTimes();
// If we're in the last phase, the overall ETA is the same as the ETA // If we're in the last phase, the overall ETA is the same as the ETA
@@ -506,8 +587,7 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
if (thisPhaseOnly) { if (thisPhaseOnly) {
percentDone = getPercentCompleteOfThisPhaseAsFloat(); percentDone = getPercentCompleteOfThisPhaseAsFloat();
startTime = this.currentPhaseStartTime; startTime = this.currentPhaseStartTime;
} } else {
else {
percentDone = getTotalPercentCompleteAsFloat(); percentDone = getTotalPercentCompleteAsFloat();
startTime = this.phaseOneStartTime; startTime = this.phaseOneStartTime;
} }
@@ -518,19 +598,17 @@ public class BaseProgressMonitor implements BraidsProgressMonitor {
// Elapsed time is to percent done as total time is to total done => // Elapsed time is to percent done as total time is to total done =>
// elapsed/percentDone == totalTime/100.0 => // elapsed/percentDone == totalTime/100.0 =>
long totalTime = (long) (100.0f * ((new Date().getTime()/1000) - startTime) / percentDone); long totalTime = (long) (100.0f * ((new Date().getTime() / 1000) - startTime) / percentDone);
return totalTime + startTime; return totalTime + startTime;
} }
/** /**
* Repair the start times in case the system clock has been moved * Repair the start times in case the system clock has been moved backwards.
* backwards.
*/ */
protected void doctorStartTimes() { protected final void doctorStartTimes() {
long nowTime = (new Date().getTime()/1000); long nowTime = (new Date().getTime() / 1000);
if (this.lastUIUpdateTime > nowTime) { if (this.lastUIUpdateTime > nowTime) {
this.lastUIUpdateTime = 0; this.lastUIUpdateTime = 0;

View File

@@ -1,158 +1,194 @@
package net.slightlymagic.braids.util.progress_monitor; package net.slightlymagic.braids.util.progress_monitor;
/** /**
* Interface for a progress monitor that can have multiple phases * Interface for a progress monitor that can have multiple phases and
* and periodically update its UI. * periodically update its UI.
* *
* All times must be in seconds; absolute times are measured in seconds since * All times must be in seconds; absolute times are measured in seconds since 01
* 01 Jan 1970 00:00:00 UTC (GMT) a la (new Date().getTime()/1000). * Jan 1970 00:00:00 UTC (GMT) a la (new Date().getTime()/1000).
*/ */
public interface BraidsProgressMonitor { public interface BraidsProgressMonitor {
/** /**
* Destroy this progress monitor, making it no longer usable and/or * Destroy this progress monitor, making it no longer usable and/or visible.
* visible.
*/
public void dispose();
/**
* @return the total number of phases monitored by this object.
*/
public abstract int getNumPhases();
/**
* @return the approximate minimum interval in seconds at which the UI
* should be updated.
*/
public abstract float getMinUpdateIntervalSec();
/**
* @return the current phase number; this is never less than 1 (one).
*/
public abstract int getCurrentPhase();
/**
* @return the number of units (an intentionally vague amount) completed
* so far in the current phase.
*/
public abstract long getUnitsCompletedSoFarThisPhase();
/**
* @return the total units we expect to process in this phase
*/
public abstract long getTotalUnitsThisPhase();
/**
* @return the time in absolute seconds since the UI was last updated
*/
public abstract long getLastUIUpdateTime();
/**
* @return the time in absolute seconds at which the first phase started
*/
public abstract long getPhaseOneStartTime();
/**
* @return the time in absolute seconds at which the current phase started
*/
public abstract long getCurrentPhaseStartTime();
/**
* @param value
* the approximate time in relative seconds at which the UI
* should be updated periodically
*/
public abstract void setMinUpdateIntervalSec(float value);
/**
* @param value the total number of units expected to processed in this
* phase
*/
public abstract void setTotalUnitsThisPhase(long value);
/**
* Resulting string does not contain a percent sign.
*
* @return the percentage completion of this phase as a String with no
* percent sign.
*/
public abstract String getPercentCompleteOfThisPhaseAsString();
/**
* Resulting string does not contain a percent sign.
*
* @return the percentage completion at this point, taking into account all
* phases and phase-weights, as a String with no percent sign.
*/
public abstract String getTotalPercentCompleteAsString();
/**
* May return "unknown"
*/
public abstract String getRelativeETAAsString(boolean thisPhaseOnly);
/**
* May return "unknown"
*/
public abstract String getAbsoluteETAAsLocalTimeString(boolean thisPhaseOnly);
/**
* Note this will NOT advance the phase.
* To do that, use markCurrentPhaseAsComplete().
*/
public abstract void incrementUnitsCompletedThisPhase(long numUnits);
/**
* Returns a boolean, whether or not to display the updated information.
* This throttles the update so it doesn't refresh so fast that it is
* unreadable. Implementers should call this method from their own
* incrementUnitsCompletedThisPhase method.
*
* If we have just reached 100% for (the current phase, we return true,
* even if it would otherwise be too soon to update the UI.
*/
public abstract boolean shouldUpdateUI();
/**
* Subclasses must call this immediately after updating the UI, to
* preserve the integrity of the shouldUpdateUI method.
*/ */
public abstract void justUpdatedUI(); void dispose();
/** /**
* This is the only way to advance the phase number. * Gets the num phases.
* It automatically "starts the clock" for the next phase. *
* * @return the total number of phases monitored by this object.
* @param totalUnitsNextPhase if unknown, use zero (0), and be sure to call */
* setTotalUnitsThisPhase() soon after. int getNumPhases();
*/
public abstract void markCurrentPhaseAsComplete(long totalUnitsNextPhase);
/** /**
* Attempt to display a message to the user; not all implementations * Gets the min update interval sec.
* support this. *
* * @return the approximate minimum interval in seconds at which the UI
* If they do not, they may silently ignore this call. * should be updated.
* */
* @param message the message to display float getMinUpdateIntervalSec();
*/
public abstract void sendMessage(String message);
/**
* Gets the current phase.
*
* @return the current phase number; this is never less than 1 (one).
*/
int getCurrentPhase();
/** /**
* Mark the current phase as having an exponential rate; such phases * Gets the units completed so far this phase.
* reach their totalUnits slower and slower as they process more units. *
* * @return the number of units (an intentionally vague amount) completed so
* By default, a phase is considered to be linear, meaning this value is * far in the current phase.
* 1.0f. */
* long getUnitsCompletedSoFarThisPhase();
* @param value usually less than 1.0f; often determined empirically.
*/
public abstract void setCurrentPhaseAsExponential(float value);
/** /**
* @return the exponent for this phase * Gets the total units this phase.
*/ *
public abstract float getCurrentPhaseExponent(); * @return the total units we expect to process in this phase
*/
long getTotalUnitsThisPhase();
/**
* Gets the last ui update time.
*
* @return the time in absolute seconds since the UI was last updated
*/
long getLastUIUpdateTime();
/**
* Gets the phase one start time.
*
* @return the time in absolute seconds at which the first phase started
*/
long getPhaseOneStartTime();
/**
* Gets the current phase start time.
*
* @return the time in absolute seconds at which the current phase started
*/
long getCurrentPhaseStartTime();
/**
* Sets the min update interval sec.
*
* @param value
* the approximate time in relative seconds at which the UI
* should be updated periodically
*/
void setMinUpdateIntervalSec(float value);
/**
* Sets the total units this phase.
*
* @param value
* the total number of units expected to processed in this phase
*/
void setTotalUnitsThisPhase(long value);
/**
* Resulting string does not contain a percent sign.
*
* @return the percentage completion of this phase as a String with no
* percent sign.
*/
String getPercentCompleteOfThisPhaseAsString();
/**
* Resulting string does not contain a percent sign.
*
* @return the percentage completion at this point, taking into account all
* phases and phase-weights, as a String with no percent sign.
*/
String getTotalPercentCompleteAsString();
/**
* May return "unknown".
*
* @param thisPhaseOnly
* the this phase only
* @return the relative eta as string
*/
String getRelativeETAAsString(boolean thisPhaseOnly);
/**
* May return "unknown".
*
* @param thisPhaseOnly
* the this phase only
* @return the absolute eta as local time string
*/
String getAbsoluteETAAsLocalTimeString(boolean thisPhaseOnly);
/**
* Note this will NOT advance the phase. To do that, use
* markCurrentPhaseAsComplete().
*
* @param numUnits
* the num units
*/
void incrementUnitsCompletedThisPhase(long numUnits);
/**
* Returns a boolean, whether or not to display the updated information.
* This throttles the update so it doesn't refresh so fast that it is
* unreadable. Implementers should call this method from their own
* incrementUnitsCompletedThisPhase method.
*
* If we have just reached 100% for (the current phase, we return true, even
* if it would otherwise be too soon to update the UI.
*
* @return true, if successful
*/
boolean shouldUpdateUI();
/**
* Subclasses must call this immediately after updating the UI, to preserve
* the integrity of the shouldUpdateUI method.
*/
void justUpdatedUI();
/**
* This is the only way to advance the phase number. It automatically
* "starts the clock" for the next phase.
*
* @param totalUnitsNextPhase
* if unknown, use zero (0), and be sure to call
* setTotalUnitsThisPhase() soon after.
*/
void markCurrentPhaseAsComplete(long totalUnitsNextPhase);
/**
* Attempt to display a message to the user; not all implementations support
* this.
*
* If they do not, they may silently ignore this call.
*
* @param message
* the message to display
*/
void sendMessage(String message);
/**
* Mark the current phase as having an exponential rate; such phases reach
* their totalUnits slower and slower as they process more units.
*
* By default, a phase is considered to be linear, meaning this value is
* 1.0f.
*
* @param value
* usually less than 1.0f; often determined empirically.
*/
void setCurrentPhaseAsExponential(float value);
/**
* Gets the current phase exponent.
*
* @return the exponent for this phase
*/
float getCurrentPhaseExponent();
} }

View File

@@ -1,78 +1,107 @@
package net.slightlymagic.braids.util.progress_monitor; package net.slightlymagic.braids.util.progress_monitor;
/**
* The Class StderrProgressMonitor.
*/
public class StderrProgressMonitor extends BaseProgressMonitor { public class StderrProgressMonitor extends BaseProgressMonitor {
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#BaseProgressMonitor(int, long) * Instantiates a new stderr progress monitor.
*/ *
public StderrProgressMonitor(int numPhases, long totalUnitsFirstPhase) { * @param numPhases
this(numPhases, totalUnitsFirstPhase, 2.0f, null); * the num phases
* @param totalUnitsFirstPhase
* the total units first phase
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#BaseProgressMonitor(int,
* long)
*/
public StderrProgressMonitor(final int numPhases, final long totalUnitsFirstPhase) {
this(numPhases, totalUnitsFirstPhase, 2.0f, null);
} }
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#BaseProgressMonitor(int, long, float) * Instantiates a new stderr progress monitor.
*/ *
public StderrProgressMonitor(int numPhases, long totalUnitsFirstPhase, * @param numPhases
float minUpdateIntervalSec) * the num phases
{ * @param totalUnitsFirstPhase
this(numPhases, totalUnitsFirstPhase, minUpdateIntervalSec, null); * the total units first phase
} * @param minUpdateIntervalSec
* the min update interval sec
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#BaseProgressMonitor(int,
* long, float)
*/
public StderrProgressMonitor(final int numPhases,
final long totalUnitsFirstPhase, final float minUpdateIntervalSec) {
this(numPhases, totalUnitsFirstPhase, minUpdateIntervalSec, null);
}
/** /**
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#BaseProgressMonitor(int, long, float, float[]) * Instantiates a new stderr progress monitor.
*/ *
public StderrProgressMonitor(int numPhases, long totalUnitsFirstPhase, * @param numPhases
float minUpdateIntervalSec, float[] phaseWeights) * the num phases
* @param totalUnitsFirstPhase
* the total units first phase
* @param minUpdateIntervalSec
* the min update interval sec
* @param phaseWeights
* the phase weights
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#BaseProgressMonitor(int,
* long, float, float[])
*/
public StderrProgressMonitor(final int numPhases, final long totalUnitsFirstPhase,
final float minUpdateIntervalSec, final float[] phaseWeights)
{ {
super(numPhases, totalUnitsFirstPhase, minUpdateIntervalSec, phaseWeights); super(numPhases, totalUnitsFirstPhase, minUpdateIntervalSec, phaseWeights);
} }
/*
* (non-Javadoc)
*
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#
* incrementUnitsCompletedThisPhase(long)
*/
/**
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#BaseProgressMonitor(int)
*/
@Override @Override
/** public final void incrementUnitsCompletedThisPhase(final long numUnits) {
* @see net.slightlymagic.braids.util.progress_monitor.BaseProgressMonitor#BaseProgressMonitor(int)
*/
public void incrementUnitsCompletedThisPhase(long numUnits) {
super.incrementUnitsCompletedThisPhase(numUnits); super.incrementUnitsCompletedThisPhase(numUnits);
if (shouldUpdateUI()) { if (shouldUpdateUI()) {
if ((getNumPhases() > 1)) { if ((getNumPhases() > 1)) {
printUpdate( printUpdate("Phase " + getCurrentPhase() + ": " + getUnitsCompletedSoFarThisPhase()
"Phase " + getCurrentPhase() + ": " + + " units processed. " + "Overall: " + getTotalPercentCompleteAsString() + "% complete, "
getUnitsCompletedSoFarThisPhase() + " units processed. " + + "ETA in " + getRelativeETAAsString() + ".");
"Overall: " + getTotalPercentCompleteAsString() + "% complete, " + } else {
"ETA in " + getRelativeETAAsString() + "." printUpdate("Overall: " + getUnitsCompletedSoFarThisPhase() + " units processed " + "("
); + getTotalPercentCompleteAsString() + "%); " + "ETA in " + getRelativeETAAsString() + ".");
}
else {
printUpdate(
"Overall: " +
getUnitsCompletedSoFarThisPhase() + " units processed " +
"(" + getTotalPercentCompleteAsString() + "%); " +
"ETA in " + getRelativeETAAsString() + "."
);
} }
} }
} }
/** /**
* Displays a message to stderr, overwriting the current estimate; calls * Displays a message to stderr, overwriting the current estimate; calls
* from outside this class should provide a newline character at the * from outside this class should provide a newline character at the end of
* end of the messsage. * the messsage.
* *
* @param message the message to display * @param message
* the message to display
*/ */
public void printUpdate(String message) { public final void printUpdate(String message) {
while (message.length() < 79) { while (message.length() < 79) {
message += ' '; message += ' ';
} }
System.err.print("\r"); System.err.print("\r");
System.err.print(message); System.err.print(message);
if (message.length() > 79) { if (message.length() > 79) {
System.err.print("\n"); System.err.print("\n");
} }
justUpdatedUI(); justUpdatedUI();