<commit_before>package edu.northwestern.bioinformatics.studycalendar.service.delta;

import edu.northwestern.bioinformatics.studycalendar.domain.PlanTreeNode;
import edu.northwestern.bioinformatics.studycalendar.domain.PlanTreeInnerNode;
import edu.northwestern.bioinformatics.studycalendar.domain.Arm;
import edu.northwestern.bioinformatics.studycalendar.domain.Period;
import edu.northwestern.bioinformatics.studycalendar.domain.PlannedEvent;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Change;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.ChangeAction;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Add;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Remove;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Reorder;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.PropertyChange;
import edu.northwestern.bioinformatics.studycalendar.dao.DaoFinder;
import edu.northwestern.bioinformatics.studycalendar.dao.PeriodDao;
import edu.northwestern.bioinformatics.studycalendar.dao.PlannedEventDao;
import edu.northwestern.bioinformatics.studycalendar.service.ParticipantService;
import edu.northwestern.bioinformatics.studycalendar.service.TemplateService;
import edu.northwestern.bioinformatics.studycalendar.service.ScheduleService;
import gov.nih.nci.cabig.ctms.dao.DomainObjectDao;
import org.springframework.beans.factory.annotation.Required;

/**
 * @author <NAME>
 */
public class MutatorFactory {
    private DaoFinder daoFinder;
    private ParticipantService participantService;
    private TemplateService templateService;
    private ScheduleService scheduleService;

    @SuppressWarnings({ "unchecked" })
    public <T extends PlanTreeNode<?>, D extends Change> Mutator createMutator(T target, D change) {
        if (change.getAction() == ChangeAction.ADD) {
            return createAddMutator(target, (Add) change);
        } else if (change.getAction() == ChangeAction.REMOVE) {
            return createRemoveMutator(target, (Remove) change);
        } else if (change.getAction() == ChangeAction.REORDER) {
            return createReorderMutator(target, (Reorder) change);
        } else if (change.getAction() == ChangeAction.CHANGE_PROPERTY) {
            return createPropertyMutator(target, (PropertyChange) change);
        }
        throw new UnsupportedOperationException("Could not construct mutator for " + change);
    }

    private <T extends PlanTreeNode<?>> Mutator createAddMutator(T target, Add add) {
        DomainObjectDao<? extends PlanTreeNode<?>> dao = findChildDao(target);
        if (target instanceof Arm) {
            return new AddPeriodMutator(add, (PeriodDao) dao, participantService);
        } else if (target instanceof Period) {
            return new AddPlannedEventMutator(add, (PlannedEventDao) dao,
                participantService, templateService);
        } else if (add.getIndex() == null) {
            return new CollectionAddMutator(add, dao);
        } else {
            return new ListAddMutator(add, dao);
        }
    }

    private <T extends PlanTreeNode<?>> Mutator createRemoveMutator(T target, Remove remove) {
        DomainObjectDao<? extends PlanTreeNode<?>> dao = findChildDao(target);
        if (target instanceof Arm) {
            return new RemovePeriodMutator(remove, (PeriodDao) dao, templateService);
        } else if (target instanceof Period) {
            return new RemovePlannedEventMutator(remove, (PlannedEventDao) dao);
        } else {
            return new RemoveMutator(remove, dao);
        }
    }

    private <T extends PlanTreeNode<?>> Mutator createReorderMutator(T target, Reorder reorder) {
        return new ReorderMutator(reorder);
    }

    private <T extends PlanTreeNode<?>> Mutator createPropertyMutator(T target, PropertyChange change) {
        if (target instanceof Period) {
            if ("startDay".equals(change.getPropertyName())) {
                return new ChangePeriodStartDayMutator(change, templateService, scheduleService);
            } else if ("repetitions".equals(change.getPropertyName())) {
                return new ChangePeriodRepetitionsMutator(change, templateService, participantService);
            } else if ("duration.quantity".equals(change.getPropertyName())) {
                return new ChangePeriodDurationQuantityMutator(change, templateService, scheduleService);
            } else if ("duration.unit".equals(change.getPropertyName())) {
                return new ChangePeriodDurationUnitMutator(change, templateService, scheduleService);
            }
            // fall through
        }
        // TODO
        // if (target instanceof PlannedEvent) {
        //
        // } 

        // default
        return new SimplePropertyChangeMutator(change);
    }

    private <T extends PlanTreeNode<?>> DomainObjectDao<? extends PlanTreeNode<?>> findChildDao(T target) {
        PlanTreeInnerNode inner = (PlanTreeInnerNode) target;
        return (DomainObjectDao<? extends PlanTreeNode<?>>) findDao(inner.childClass());
    }
<commit_msg>Remove unused properties and suppress some warnings<commit_after>package edu.northwestern.bioinformatics.studycalendar.service.delta;

import edu.northwestern.bioinformatics.studycalendar.domain.PlanTreeNode;
import edu.northwestern.bioinformatics.studycalendar.domain.PlanTreeInnerNode;
import edu.northwestern.bioinformatics.studycalendar.domain.Arm;
import edu.northwestern.bioinformatics.studycalendar.domain.Period;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Change;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.ChangeAction;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Add;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Remove;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Reorder;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.PropertyChange;
import edu.northwestern.bioinformatics.studycalendar.dao.DaoFinder;
import edu.northwestern.bioinformatics.studycalendar.dao.PeriodDao;
import edu.northwestern.bioinformatics.studycalendar.dao.PlannedEventDao;
import edu.northwestern.bioinformatics.studycalendar.service.ParticipantService;
import edu.northwestern.bioinformatics.studycalendar.service.TemplateService;
import edu.northwestern.bioinformatics.studycalendar.service.ScheduleService;
import gov.nih.nci.cabig.ctms.dao.DomainObjectDao;
import org.springframework.beans.factory.annotation.Required;

/**
 * @author <NAME>
 */
public class MutatorFactory {
    private DaoFinder daoFinder;
    private ParticipantService participantService;
    private TemplateService templateService;
    private ScheduleService scheduleService;

    @SuppressWarnings({ "unchecked" })
    public <T extends PlanTreeNode<?>, D extends Change> Mutator createMutator(T target, D change) {
        if (change.getAction() == ChangeAction.ADD) {
            return createAddMutator(target, (Add) change);
        } else if (change.getAction() == ChangeAction.REMOVE) {
            return createRemoveMutator(target, (Remove) change);
        } else if (change.getAction() == ChangeAction.REORDER) {
            return createReorderMutator((Reorder) change);
        } else if (change.getAction() == ChangeAction.CHANGE_PROPERTY) {
            return createPropertyMutator(target, (PropertyChange) change);
        }
        throw new UnsupportedOperationException("Could not construct mutator for " + change);
    }

    private <T extends PlanTreeNode<?>> Mutator createAddMutator(T target, Add add) {
        DomainObjectDao<? extends PlanTreeNode<?>> dao = findChildDao(target);
        if (target instanceof Arm) {
            return new AddPeriodMutator(add, (PeriodDao) dao, participantService);
        } else if (target instanceof Period) {
            return new AddPlannedEventMutator(add, (PlannedEventDao) dao,
                participantService, templateService);
        } else if (add.getIndex() == null) {
            return new CollectionAddMutator(add, dao);
        } else {
            return new ListAddMutator(add, dao);
        }
    }

    private <T extends PlanTreeNode<?>> Mutator createRemoveMutator(T target, Remove remove) {
        DomainObjectDao<? extends PlanTreeNode<?>> dao = findChildDao(target);
        if (target instanceof Arm) {
            return new RemovePeriodMutator(remove, (PeriodDao) dao, templateService);
        } else if (target instanceof Period) {
            return new RemovePlannedEventMutator(remove, (PlannedEventDao) dao);
        } else {
            return new RemoveMutator(remove, dao);
        }
    }

    private Mutator createReorderMutator(Reorder reorder) {
        return new ReorderMutator(reorder);
    }

    private <T extends PlanTreeNode<?>> Mutator createPropertyMutator(T target, PropertyChange change) {
        if (target instanceof Period) {
            if ("startDay".equals(change.getPropertyName())) {
                return new ChangePeriodStartDayMutator(change, templateService, scheduleService);
            } else if ("repetitions".equals(change.getPropertyName())) {
                return new ChangePeriodRepetitionsMutator(change, templateService, participantService);
            } else if ("duration.quantity".equals(change.getPropertyName())) {
                return new ChangePeriodDurationQuantityMutator(change, templateService, scheduleService);
            } else if ("duration.unit".equals(change.getPropertyName())) {
                return new ChangePeriodDurationUnitMutator(change, templateService, scheduleService);
            }
            // fall through
        }
        // TODO
        // if (target instanceof PlannedEvent) {
        //
        // } 

        // default
        return new SimplePropertyChangeMutator(change);
    }

    @SuppressWarnings({ "RawUseOfParameterizedType", "unchecked" })
    private <T extends PlanTreeNode<?>> DomainObjectDao<? extends PlanTreeNode<?>> findChildDao(T target) {
        PlanTreeInnerNode inner = (PlanTreeInnerNode) target;
        return (DomainObjectDao<? extends PlanTreeNode<?>>) findDao(inner.childClass());
    }

{'fraction_non_alphanumeric': 0.0956342991386061, 'fraction_numerical': 0.0, 'mean_word_length': 3.7300925925925927, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '2774985', 'n_tokens_mistral': 2786, 'n_tokens_neox': 2671, 'n_words': 567}