I need to connect different Task
with a double linked list and different Dependencies
which affect a calculation for which I need the values of both Task
:
public class Task {
private List<Dependency> parents = new ArrayList<Dependency>();
private List<Dependency> children = new ArrayList<Dependency>();
//Uses the parents values and calls `calculateForwards` of the children
public void calculateForwards() { .. }
//Uses the children values and calls `calculateBackwards` of the children
public void calculateBackwards() { .. }
}
public interface Dependency {
Task getTask();
void setForwards(Task t);
void setBackwards(Task t);
Dependency createCopy(Task t);
}
public class EA implements Dependency {
private Task task;
//............
@Override
public void setForwards(Task t) {
if (t.getEarlyStart() < task.getEarlyFinish())
t.setEarlyStart(task.getEarlyFinish());
t.setEarlyFinish(t.getEarlyStart() + t.getDuration());
}
@Override
public void setBackwards(Task t) {
if (t.getLatestFinish() > task.getLatestStart())
t.setLatestFinish(task.getLatestStart());
t.setLatestStart(t.getLatestFinish() - t.getDuration());
}
//............
}
For now dependencies are created with the Task
it points to and added to the children list. Then a copy of the dependencie is created that points to the original task and added to the parent list of the child:
public void addChild(Dependency r) {
children.add(r);
r.getTask().addParent(r.createCopy(this));
}
private void addParent(Dependency r) {
parents.add(r);
}
As you can see this data structure does the job, but very ugly in my eyes. How can I solve this more elegantly?