<commit_before>package edu.northwestern.bioinformatics.studycalendar.domain;

import edu.northwestern.bioinformatics.studycalendar.domain.delta.Add;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Amendment;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Revision;
import edu.northwestern.bioinformatics.studycalendar.domain.scheduledactivitystate.Conditional;
import edu.northwestern.bioinformatics.studycalendar.domain.scheduledactivitystate.Scheduled;
import edu.northwestern.bioinformatics.studycalendar.domain.scheduledactivitystate.ScheduledActivityState;
import edu.northwestern.bioinformatics.studycalendar.service.DeltaService;
import edu.northwestern.bioinformatics.studycalendar.service.TemplateSkeletonCreator;
import edu.northwestern.bioinformatics.studycalendar.service.TestingTemplateService;
import edu.northwestern.bioinformatics.studycalendar.service.delta.MemoryOnlyMutatorFactory;
import edu.nwu.bioinformatics.commons.DateUtils;
import gov.nih.nci.cabig.ctms.domain.DomainObject;
import gov.nih.nci.cabig.ctms.domain.GridIdentifiable;
import gov.nih.nci.cabig.ctms.lang.DateTools;
import gov.nih.nci.security.authorization.domainobjects.ProtectionGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Calendar;
import java.util.Date;

/**
 * @author <NAME>
 */
public class Fixtures {
    private static final Logger log = LoggerFactory.getLogger(Fixtures.class);
    private static final DeltaService deltaService = new DeltaService();
    public static final ActivityType DEFAULT_ACTIVITY_TYPE = ActivityType.LAB_TEST;
    public static final Source DEFAULT_ACTIVITY_SOURCE = createNamedInstance("Fixtures Source", Source.class);

    static {
        deltaService.setMutatorFactory(new MemoryOnlyMutatorFactory());
        deltaService.setTemplateService(new TestingTemplateService());
    }

    public static <T extends DomainObject> T setId(Integer id, T target) {
        target.setId(id);
        return target;
    }

    public static void assignIds(Study study) {
        study.getPlannedCalendar().setId(1);
        study.getPlannedCalendar().setGridId("GRID-1");
        int epochId = 10, studySegmentId = 100, periodId = 1000, plannedActivityId = 10000;
        for (Epoch epoch : study.getPlannedCalendar().getEpochs()) {
            epoch.setId(++epochId);
            epoch.setGridId("GRID-" + epochId);
            for (StudySegment studySegment : epoch.getStudySegments()) {
                studySegment.setId(++studySegmentId);
                studySegment.setGridId("GRID-" + studySegmentId);
                for (Period period : studySegment.getPeriods()) {
                    period.setId(++periodId);
                    period.setGridId("GRID-" + periodId);
                    for (PlannedActivity event : period.getPlannedActivities()) {
                        event.setId(++plannedActivityId);
                        event.setGridId("GRID-" + plannedActivityId);
                    }
                }
            }
        }
    }

    public static <T extends GridIdentifiable> T setGridId(String gridId, T target) {
        target.setGridId(gridId);
        return target;
    }

    public static Period createPeriod(int startDay, int dayCount, int repetitions) {
        return createPeriod(null, startDay, dayCount, repetitions);
    }

    public static Period createPeriod(String name, int startDay, int dayCount, int repetitions) {
        return createPeriod(name, startDay, Duration.Unit.day, dayCount, repetitions);
    }

    public static Period createPeriod(String name, int startDay, Duration.Unit dUnit, int dQuantity, int repetitions) {
        Period p = new Period();
        p.setName(name);
        p.setStartDay(startDay);
        p.getDuration().setUnit(dUnit);
        p.getDuration().setQuantity(dQuantity);
        p.setRepetitions(repetitions);<commit_msg>Tweak assignIds so that you can use it for multiple studies in the same test<commit_after>package edu.northwestern.bioinformatics.studycalendar.domain;

import edu.northwestern.bioinformatics.studycalendar.domain.delta.Add;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Amendment;
import edu.northwestern.bioinformatics.studycalendar.domain.delta.Revision;
import edu.northwestern.bioinformatics.studycalendar.domain.scheduledactivitystate.Conditional;
import edu.northwestern.bioinformatics.studycalendar.domain.scheduledactivitystate.Scheduled;
import edu.northwestern.bioinformatics.studycalendar.domain.scheduledactivitystate.ScheduledActivityState;
import edu.northwestern.bioinformatics.studycalendar.service.DeltaService;
import edu.northwestern.bioinformatics.studycalendar.service.TemplateSkeletonCreator;
import edu.northwestern.bioinformatics.studycalendar.service.TestingTemplateService;
import edu.northwestern.bioinformatics.studycalendar.service.delta.MemoryOnlyMutatorFactory;
import edu.nwu.bioinformatics.commons.DateUtils;
import gov.nih.nci.cabig.ctms.domain.DomainObject;
import gov.nih.nci.cabig.ctms.domain.GridIdentifiable;
import gov.nih.nci.cabig.ctms.lang.DateTools;
import gov.nih.nci.security.authorization.domainobjects.ProtectionGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Calendar;
import java.util.Date;

/**
 * @author <NAME>
 */
public class Fixtures {
    private static final Logger log = LoggerFactory.getLogger(Fixtures.class);
    private static final DeltaService deltaService = new DeltaService();
    public static final ActivityType DEFAULT_ACTIVITY_TYPE = ActivityType.LAB_TEST;
    public static final Source DEFAULT_ACTIVITY_SOURCE = createNamedInstance("Fixtures Source", Source.class);

    static {
        deltaService.setMutatorFactory(new MemoryOnlyMutatorFactory());
        deltaService.setTemplateService(new TestingTemplateService());
    }

    public static <T extends DomainObject> T setId(Integer id, T target) {
        target.setId(id);
        return target;
    }

    public static void assignIds(Study study) {
        assignIds(study, 0);
    }

    public static void assignIds(Study study, int start) {
        setIds(start, study);
        assignIds(study.getPlannedCalendar(), start + 1);
    }

    @SuppressWarnings({ "RawUseOfParameterizedType", "unchecked" })
    public static <T extends PlanTreeNode> T assignIds(T node, int start) {
        int i = start;
        setIds(i, node);
        if (node instanceof PlanTreeInnerNode) {
            for (PlanTreeNode child : ((PlanTreeInnerNode<?, ? extends PlanTreeNode, ?>) node).getChildren()) {
                i++;
                assignIds(child, i * 50);
            }
        }
        return node;
    }

    public static <T extends GridIdentifiable & DomainObject> T setIds(int base, T target) {
        target.setId(base);
        target.setGridId("GRID-" + base);
        return target;
    }

    public static <T extends GridIdentifiable> T setGridId(String gridId, T target) {
        target.setGridId(gridId);
        return target;
    }

    public static Period createPeriod(int startDay, int dayCount, int repetitions) {
        return createPeriod(null, startDay, dayCount, repetitions);
    }

    public static Period createPeriod(String name, int startDay, int dayCount, int repetitions) {
        return createPeriod(name, startDay, Duration.Unit.day, dayCount, repetitions);
    }

    public static Period createPeriod(String name, int startDay, Duration.Unit dUnit, int dQuantity, int repetitions) {
        Period p = new Period();
        p.setName(name);
        p.setStartDay(startDay);
        p.getDuration().setUnit(dUnit);
        p.getDuration().setQuantity(dQuantity);
        p.setRepetitions(repetitions);
{'fraction_non_alphanumeric': 0.09459109730848861, 'fraction_numerical': 0.003105590062111801, 'mean_word_length': 3.7651048088779286, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '1796571', 'n_tokens_mistral': 2297, 'n_tokens_neox': 2117, 'n_words': 439}