<commit_before>package edu.northwestern.bioinformatics.studycalendar.web.template;

import edu.northwestern.bioinformatics.studycalendar.domain.*;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Remove;

import java.util.Map;
import java.util.List;
import java.util.HashMap;

/**
 * @author <NAME>
 */
public class DeleteCommand extends EditTemplateCommand {

    ////// MODES

    @Override
    protected Mode epochMode() {
        return new DeleteEpoch();
    }

    @Override
    protected Mode studySegmentMode() {
        return new DeleteStudySegment();
    }

    private abstract class DeleteMode<T extends PlanTreeNode<? extends PlanTreeInnerNode>> extends Mode {
        public final void performEdit() {
            if (getObjectParent().getChildren().size() < 2) return;
            updateRevision(getObjectParent(), Remove.create(getObject()));
        }

        public Map<String, Object> getModel() {
            Map<String, Object> map = new HashMap<String, Object>();
            Epoch epoch = null;
            StudySegment studySegment = null;
            if (getObjectParent() instanceof Epoch) {
                epoch = (Epoch)getObjectParent();
                List<StudySegment> studySegments = epoch.getStudySegments();
                studySegments.remove(getRevisedStudySegment());
                studySegment =  studySegments.get(studySegments.size() - 1);
            } else if (getObjectParent() instanceof PlannedCalendar) {
                PlannedCalendar calendar = (PlannedCalendar)getObjectParent();
                epoch = calendar.getEpochs().get(0);
                studySegment = epoch.getStudySegments().get(0);
            }
            map.put("epoch", epoch);
            map.put("studySegment", studySegment);
            StudySegmentTemplate studySegmentTemplate = new StudySegmentTemplate(studySegment);
            map.put("template", studySegmentTemplate);
            return map;
        }


        protected abstract T getObject();
        protected abstract PlanTreeInnerNode getObjectParent();
    }

    private class DeleteEpoch extends DeleteMode<Epoch> {
        public String getRelativeViewName() {
            return "deleteEpoch";<commit_msg>when first epoch is deleted, default selected segment set to next epoch. Closes #603<commit_after>package edu.northwestern.bioinformatics.studycalendar.web.template;

import edu.northwestern.bioinformatics.studycalendar.domain.*;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Remove;

import java.util.Map;
import java.util.List;
import java.util.HashMap;

/**
 * @author <NAME>
 */
public class DeleteCommand extends EditTemplateCommand {

    ////// MODES

    @Override
    protected Mode epochMode() {
        return new DeleteEpoch();
    }

    @Override
    protected Mode studySegmentMode() {
        return new DeleteStudySegment();
    }

    private abstract class DeleteMode<T extends PlanTreeNode<? extends PlanTreeInnerNode>> extends Mode {
        public final void performEdit() {
            if (getObjectParent().getChildren().size() < 2) return;
            updateRevision(getObjectParent(), Remove.create(getObject()));
        }

        public Map<String, Object> getModel() {
            Map<String, Object> map = new HashMap<String, Object>();
            Epoch epoch = null;
            StudySegment studySegment = null;
            if (getObjectParent() instanceof Epoch) {
                epoch = (Epoch)getObjectParent();
                List<StudySegment> studySegments = epoch.getStudySegments();
                studySegments.remove(getRevisedStudySegment());
                studySegment =  studySegments.get(studySegments.size() - 1);
            } else if (getObjectParent() instanceof PlannedCalendar) {
                PlannedCalendar calendar = (PlannedCalendar)getObjectParent();
                epoch = calendar.getEpochs().get(0);
                if(epoch.getId()==getObject().getId()) {
                    epoch = calendar.getEpochs().get(1);
                }
                studySegment = epoch.getStudySegments().get(0);
            }
            map.put("epoch", epoch);
            map.put("studySegment", studySegment);
            StudySegmentTemplate studySegmentTemplate = new StudySegmentTemplate(studySegment);
            map.put("template", studySegmentTemplate);
            return map;
        }


        protected abstract T getObject();
        protected abstract PlanTreeInnerNode getObjectParent();
    }

    private class DeleteEpoch extends DeleteMode<Epoch> {
        public String getRelativeViewName() {
            return "deleteEpoch";
{'fraction_non_alphanumeric': 0.10088191008819102, 'fraction_numerical': 0.002581200258120026, 'mean_word_length': 2.5962877030162415, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3961509', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1134, 'n_words': 265}