/** * Adds specified activity at the end of activity-list. * <p>If act instanceof JobActivity, it adds underlying job also. * * @param act to be added * @throws IllegalArgumentException if activity-list already contains act. */ public void addActivity(TourActivity act) { if (tourActivities.contains(act)) throw new IllegalArgumentException("act " + act + " already in tour. cannot add act twice."); tourActivities.add(act); addJob(act); }
/** * Inserts the specified activity add the specified insertionIndex. Shifts the element currently at that position (if any) and * any subsequent elements to the right (adds one to their indices). * <p>If specified activity instanceof JobActivity, it adds job to jobList. * <p>If insertionIndex > tourActivitiies.size(), it just adds the specified act at the end. * * @param insertionIndex index where activity needs to be inserted * @param act activity to be inserted * @throws IndexOutOfBoundsException if insertionIndex < 0; */ public void addActivity(int insertionIndex, TourActivity act) { assert insertionIndex >= 0 : "insertionIndex < 0, this cannot be"; /* * if 1 --> between start and act(0) --> act(0) * if 2 && 2 <= acts.size --> between act(0) and act(1) --> act(1) * if 2 && 2 > acts.size --> at actEnd * ... * */ if (insertionIndex < tourActivities.size()) { tourActivities.add(insertionIndex, act); } else if (insertionIndex >= tourActivities.size()) { tourActivities.add(act); } addJob(act); }
private TourActivities(TourActivities tour2copy) { for (TourActivity tourAct : tour2copy.getActivities()) { TourActivity newAct = tourAct.duplicate(); this.tourActivities.add(newAct); addJob(newAct); } }
/** * Adds specified activity at the end of activity-list. * <p>If act instanceof JobActivity, it adds underlying job also. * * @param act to be added * @throws IllegalArgumentException if activity-list already contains act. */ public void addActivity(TourActivity act) { if (tourActivities.contains(act)) throw new IllegalArgumentException("act " + act + " already in tour. cannot add act twice."); tourActivities.add(act); addJob(act); }
/** * Inserts the specified activity add the specified insertionIndex. Shifts the element currently at that position (if any) and * any subsequent elements to the right (adds one to their indices). * <p>If specified activity instanceof JobActivity, it adds job to jobList. * <p>If insertionIndex > tourActivitiies.size(), it just adds the specified act at the end. * * @param insertionIndex index where activity needs to be inserted * @param act activity to be inserted * @throws IndexOutOfBoundsException if insertionIndex < 0; */ public void addActivity(int insertionIndex, TourActivity act) { assert insertionIndex >= 0 : "insertionIndex < 0, this cannot be"; /* * if 1 --> between start and act(0) --> act(0) * if 2 && 2 <= acts.size --> between act(0) and act(1) --> act(1) * if 2 && 2 > acts.size --> at actEnd * ... * */ if (insertionIndex < tourActivities.size()) { tourActivities.add(insertionIndex, act); } else if (insertionIndex >= tourActivities.size()) { tourActivities.add(act); } addJob(act); }
private TourActivities(TourActivities tour2copy) { for (TourActivity tourAct : tour2copy.getActivities()) { TourActivity newAct = tourAct.duplicate(); this.tourActivities.add(newAct); addJob(newAct); } }