Do not use ConstraintDate directly in CriticalPathCalculator
FEA: ItEr61S08TimeUnitConfigurablePlanning
This commit is contained in:
parent
dc8fce0f09
commit
6320ca75f3
2 changed files with 42 additions and 14 deletions
|
|
@ -33,6 +33,41 @@ import org.zkoss.ganttz.util.WeakReferencedListeners.IListenerNotification;
|
|||
*/
|
||||
public abstract class Constraint<T> {
|
||||
|
||||
public static <T> Constraint<T> coalesce(
|
||||
Collection<? extends Constraint<T>> constraints) {
|
||||
if (constraints.size() == 1) {
|
||||
return constraints.iterator().next();
|
||||
}
|
||||
return new CompoundConstraint<T>(constraints);
|
||||
}
|
||||
|
||||
private static class CompoundConstraint<T> extends Constraint<T> {
|
||||
private final List<Constraint<T>> constraints;
|
||||
|
||||
CompoundConstraint(Collection<? extends Constraint<T>> constraints) {
|
||||
this.constraints = new ArrayList<Constraint<T>>(constraints);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected T applyConstraintTo(T value) {
|
||||
T result = value;
|
||||
for (Constraint<T> each : constraints) {
|
||||
result = each.applyTo(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSatisfiedBy(T value) {
|
||||
for (Constraint<T> each : constraints) {
|
||||
if (!each.isSatisfiedBy(value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Constraint<T> emptyConstraint() {
|
||||
return new Constraint<T>() {
|
||||
|
||||
|
|
@ -131,7 +166,7 @@ public abstract class Constraint<T> {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected abstract T applyConstraintTo(T currentValue);
|
||||
protected abstract T applyConstraintTo(T value);
|
||||
|
||||
public abstract boolean isSatisfiedBy(T value);
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ import org.zkoss.ganttz.data.GanttDate;
|
|||
import org.zkoss.ganttz.data.IDependency;
|
||||
import org.zkoss.ganttz.data.ITaskFundamentalProperties;
|
||||
import org.zkoss.ganttz.data.constraint.Constraint;
|
||||
import org.zkoss.ganttz.data.constraint.DateConstraint;
|
||||
|
||||
/**
|
||||
* Class that calculates the critical path of a Gantt diagram graph.
|
||||
|
|
@ -142,7 +141,7 @@ public class CriticalPathCalculator<T extends ITaskFundamentalProperties> {
|
|||
Node<T> node = nodes.get(task);
|
||||
DependencyType dependencyType = getDependencyTypeEndStartByDefault(
|
||||
currentTask, task);
|
||||
DateConstraint constraint = getDateConstraint(task);
|
||||
Constraint<Date> constraint = getDateConstraint(task);
|
||||
|
||||
switch (dependencyType) {
|
||||
case START_START:
|
||||
|
|
@ -169,7 +168,7 @@ public class CriticalPathCalculator<T extends ITaskFundamentalProperties> {
|
|||
}
|
||||
|
||||
private void setEarliestStart(Node<T> node, int earliestStart,
|
||||
DateConstraint constraint) {
|
||||
Constraint<Date> constraint) {
|
||||
if (constraint != null) {
|
||||
Date date = initDate.plusDays(earliestStart)
|
||||
.toDateTimeAtStartOfDay().toDate();
|
||||
|
|
@ -180,7 +179,7 @@ public class CriticalPathCalculator<T extends ITaskFundamentalProperties> {
|
|||
node.setEarliestStart(earliestStart);
|
||||
}
|
||||
|
||||
private DateConstraint getDateConstraint(T task) {
|
||||
private Constraint<Date> getDateConstraint(T task) {
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -189,13 +188,7 @@ public class CriticalPathCalculator<T extends ITaskFundamentalProperties> {
|
|||
if (constraints == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Constraint<Date> constraint : constraints) {
|
||||
if (constraint instanceof DateConstraint) {
|
||||
return (DateConstraint) constraint;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Constraint.coalesce(constraints);
|
||||
}
|
||||
|
||||
private void backward(Node<T> currentNode, T nextTask) {
|
||||
|
|
@ -221,7 +214,7 @@ public class CriticalPathCalculator<T extends ITaskFundamentalProperties> {
|
|||
Node<T> node = nodes.get(task);
|
||||
DependencyType dependencyType = getDependencyTypeEndStartByDefault(
|
||||
task, currentTask);
|
||||
DateConstraint constraint = getDateConstraint(task);
|
||||
Constraint<Date> constraint = getDateConstraint(task);
|
||||
|
||||
switch (dependencyType) {
|
||||
case START_START:
|
||||
|
|
@ -248,7 +241,7 @@ public class CriticalPathCalculator<T extends ITaskFundamentalProperties> {
|
|||
}
|
||||
|
||||
private void setLatestFinish(Node<T> node, int latestFinish,
|
||||
DateConstraint constraint) {
|
||||
Constraint<Date> constraint) {
|
||||
if (constraint != null) {
|
||||
int duration = node.getDuration();
|
||||
Date date = initDate.plusDays(latestFinish - duration)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue