mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
simplify TourActivities.removeActivity() by handling non-job activities separately
This commit is contained in:
parent
4ac181165c
commit
dd122b54e6
1 changed files with 15 additions and 16 deletions
|
|
@ -154,36 +154,35 @@ public class TourActivities {
|
||||||
* @return true if activity has been removed, false otherwise
|
* @return true if activity has been removed, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean removeActivity(TourActivity activity) {
|
public boolean removeActivity(TourActivity activity) {
|
||||||
Job job = null;
|
if (!(activity instanceof JobActivity)) {
|
||||||
if (activity instanceof JobActivity) {
|
//assumes that an activity can be added only once to tourActivities
|
||||||
job = ((JobActivity) activity).getJob();
|
return tourActivities.remove(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Job job = ((JobActivity) activity).getJob();
|
||||||
boolean jobIsAlsoAssociateToOtherActs = false;
|
boolean jobIsAlsoAssociateToOtherActs = false;
|
||||||
boolean actRemoved = false;
|
boolean actRemoved = false;
|
||||||
List<TourActivity> acts = new ArrayList<>(tourActivities);
|
for (TourActivity act : new ArrayList<>(tourActivities)) {
|
||||||
for (TourActivity act : acts) {
|
|
||||||
if (act == activity) {
|
if (act == activity) {
|
||||||
tourActivities.remove(act);
|
tourActivities.remove(act);
|
||||||
if (job == null || jobIsAlsoAssociateToOtherActs) {
|
if (jobIsAlsoAssociateToOtherActs) {
|
||||||
// this is not a job activity OR other activities also refer to job --> do not remove job
|
// other activities also refer to job --> do not remove job
|
||||||
// thus no need to iterate any further
|
// thus no need to iterate any further
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
actRemoved = true;
|
actRemoved = true;
|
||||||
} else {
|
} else {
|
||||||
if (job != null && act instanceof JobActivity) {
|
if (act instanceof JobActivity && ((JobActivity) act).getJob().equals(job)) {
|
||||||
if (((JobActivity) act).getJob().equals(job)) {
|
if (actRemoved) {
|
||||||
if (actRemoved) {
|
// other activities also refer to job --> do not remove job
|
||||||
// other activities also refer to job --> do not remove job
|
// thus no need to iterate any further
|
||||||
// thus no need to iterate any further
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
jobIsAlsoAssociateToOtherActs = true;
|
|
||||||
}
|
}
|
||||||
|
jobIsAlsoAssociateToOtherActs = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!jobIsAlsoAssociateToOtherActs && actRemoved) {
|
if (actRemoved) {
|
||||||
jobs.remove(job);
|
jobs.remove(job);
|
||||||
}
|
}
|
||||||
return actRemoved;
|
return actRemoved;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue