<commit_before>package TaskSchedulingSimulator;

import java.util.Comparator;
import java.util.ArrayList;

/**
 *
 * @author nikola
 */
public class InstanceOfPeriodicTask {
    
    private int id;
    private int taskPeriod;         // period
    private int phi;                // phase
    private int rActivationTime;    // activation time
    private int dAbsoluteDeadline;  // absolute deadline
    private int cExecutionTime;     // execution time
    private int missedDeadline;
    //collects time when any part of instance started beeing executed
    private ArrayList<Integer> startOfExecutionTime;
    //collects time when any part of instance stopped beeing executed
    private ArrayList<Integer> endOfExecutionTime;

    /**
     * constructor
     *
     * @param pId
     * @param taskPeriod
     * @param phi
     * @param rActivationTime
     * @param dAbsoluteDeadline
     * @param cExecutionTime
     */
    public InstanceOfPeriodicTask(int pId, int taskPeriod, int phi,
            int rActivationTime, int dAbsoluteDeadline, int cExecutionTime) {
        this.id = pId;
        this.cExecutionTime = cExecutionTime;
        this.dAbsoluteDeadline = dAbsoluteDeadline;
        this.phi = phi;
        this.rActivationTime = rActivationTime;
        this.taskPeriod = taskPeriod;
        this.missedDeadline = -1;
        this.startOfExecutionTime = new ArrayList<>();
        this.endOfExecutionTime = new ArrayList<>();
    }

    public boolean checkIfStillBeingExecuted(){
        return this.startOfExecutionTime.size() == this.endOfExecutionTime.size() + 1;
    }
    
    public void removeRedundantTimesFromLists() {
        if (startOfExecutionTime.size() > 1 && startOfExecutionTime.size() == endOfExecutionTime.size()) {
            //for each start time except first
            for (int i = 1; i < startOfExecutionTime.size(); i++) {
                //check if is equal to previous end time of execution
                //which means at that time was no interruption
                //so these times are redundant in list
                if (startOfExecutionTime.get(i) == endOfExecutionTime.get(i - 1)) {
                    //remove redundant times
                    startOfExecutionTime.remove(i);
                    endOfExecutionTime.remove(i-1);
                }
            }
        }
    }

    //adds time to the end of list
    public void addStartTimeOfExecution(int time) {
        this.startOfExecutionTime.add(time);
    }

    //adds time to the end of list
    public void addEndTimeOfExecution(int time) {
        this.endOfExecutionTime.add(time);
    }

    public void setMissedDeadline(int missedDeadline) {
        this.missedDeadline = missedDeadline;
    }

    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the taskPeriod
     */
    public int getTaskPeriod() {
        return taskPeriod;
    }

    /**
     * @param taskPeriod the taskPeriod to set
     */
    public void setTaskPeriod(int taskPeriod) {
        this.taskPeriod = taskPeriod;
    }

    /**
     * @return the phi
     */
    public int getPhi() {
        return phi;
    }

    /**
     * @param phi the phi to set
     */
    public void setPhi(int phi) {
        this.phi = phi;
    }

    /**
     * @return the rActivationTime
     */
    public int getrActivationTime() {
        return rActivationTime;
    }

    /**
     * @param rActivationTime the rActivationTime to set
     */
    public void setrActivationTime(int rActivationTime) {
        this.rActivationTime = rActivationTime;
    }

    /**
     * @return the dAbsoluteDeadline
     */
    public int getdAbsoluteDeadline() {
        return dAbsoluteDeadline;
    }

    /**
     * @param dAbsoluteDeadline the dAbsoluteDeadline to set
     */
    public void setdAbsoluteDeadline(int dAbsoluteDeadline) {
        this.dAbsoluteDeadline = dAbsoluteDeadline;
    }

    /**
     * @return the cExecutionTime
     */
    public int getcExecutionTime() {
        return cExecutionTime;
    }

    /**
     * @param cExecutionTime the cExecutionTime to set
     */
    public void setcExecutionTime(int cExecutionTime) {
        this.cExecutionTime = cExecutionTime;
    }
    
    public static class Comparators {

        /**
         * Used for Rate Monotonic algorithm. This comparator compares two 
         * InstanceOfPeriodicTask objects using their taskPeriod property.
         */
        public static Comparator<InstanceOfPeriodicTask> TASK_PERIOD
                = new Comparator<InstanceOfPeriodicTask>() {
                    @Override
                    public int compare(InstanceOfPeriodicTask o1, InstanceOfPeriodicTask o2) {
                        return o1.getTaskPeriod() - o2.getTaskPeriod();
                    }
                };
        
        /**
         * Used for Earliest Deadline First algorithm. This comparator compares
         * two InstanceOfPeriodicTask objects using their dAbsoluteDeadline property.
         */
        public static Comparator<InstanceOfPeriodicTask> ABSOLUTE_DEADLINE
                = new Comparator<InstanceOfPeriodicTask>() {
                    @Override
                    public int compare(InstanceOfPeriodicTask o1, InstanceOfPeriodicTask o2) {
                        return o1.getdAbsoluteDeadline() - o2.getdAbsoluteDeadline();
                    }
                };
        
        /**
         * Used for Deadline Monotonic algorithm.
         */
        public static Comparator<InstanceOfPeriodicTask> RELATIVE_DEADLINE
                = new Comparator<InstanceOfPeriodicTask>() {
                    @Override
                    public int compare(InstanceOfPeriodicTask o1, InstanceOfPeriodicTask o2) {
                        return (o1.getdAbsoluteDeadline() - o1.getrActivationTime())
                        - (o2.getdAbsoluteDeadline() - o2.getrActivationTime());
                    }
                };
        
        /* We can add other comparators here */
    }

    @Override
    public String toString() {
        StringBuilder sbResult = new StringBuilder();
        
        //first line is task id
        sbResult.append(this.getId());
        sbResult.append(System.lineSeparator());
        
        //second line is activation time
        sbResult.append(this.getrActivationTime());
        sbResult.append(System.lineSeparator());
        
        //third line is absolute deadline
        sbResult.append(this.getdAbsoluteDeadline());
        sbResult.append(System.lineSeparator());
        
        //fourth line contains all the activation times.
        //if startOfExecutionTime is empty add -1 instead
        if (this.startOfExecutionTime.isEmpty()) {
            sbResult.append("-1");
        } else {
            for (Integer i : this.startOfExecutionTime) {
                sbResult.append(i);
                sbResult.append(" ");
            }
        }
        sbResult.append(System.lineSeparator());
    
        //fifth line contains all the activation times.
        //if endOfExecutionTime is empty add -1 instead
        if (this.endOfExecutionTime.isEmpty()) {
            sbResult.append("-1");
        } else {
            for (Integer i : this.endOfExecutionTime) {
                sbResult.append(i);
                sbResult.append(" ");
            }
        }
        sbResult.append(System.lineSeparator());
        
        //sixth line is -1 if the instance finished successfully.
        //if the instance missed its deadline it contains the deadline it missed
        sbResult.append(this.missedDeadline);
        sbResult.append(System.lineSeparator());
        
        return sbResult.toString();
    }
}
<commit_msg>Fix #6 - changed == to equal when comparing two Integers in removeRedundantTimesFromLists<commit_after>package TaskSchedulingSimulator;

import java.util.Comparator;
import java.util.ArrayList;

/**
 *
 * @author nikola
 */
public class InstanceOfPeriodicTask {
    
    private int id;
    private int taskPeriod;         // period
    private int phi;                // phase
    private int rActivationTime;    // activation time
    private int dAbsoluteDeadline;  // absolute deadline
    private int cExecutionTime;     // execution time
    private int missedDeadline;
    //collects time when any part of instance started beeing executed
    private ArrayList<Integer> startOfExecutionTime;
    //collects time when any part of instance stopped beeing executed
    private ArrayList<Integer> endOfExecutionTime;

    /**
     * constructor
     *
     * @param pId
     * @param taskPeriod
     * @param phi
     * @param rActivationTime
     * @param dAbsoluteDeadline
     * @param cExecutionTime
     */
    public InstanceOfPeriodicTask(int pId, int taskPeriod, int phi,
            int rActivationTime, int dAbsoluteDeadline, int cExecutionTime) {
        this.id = pId;
        this.cExecutionTime = cExecutionTime;
        this.dAbsoluteDeadline = dAbsoluteDeadline;
        this.phi = phi;
        this.rActivationTime = rActivationTime;
        this.taskPeriod = taskPeriod;
        this.missedDeadline = -1;
        this.startOfExecutionTime = new ArrayList<>();
        this.endOfExecutionTime = new ArrayList<>();
    }

    public boolean checkIfStillBeingExecuted(){
        return this.startOfExecutionTime.size() == this.endOfExecutionTime.size() + 1;
    }
    
    public void removeRedundantTimesFromLists() {
        if (startOfExecutionTime.size() > 1 && startOfExecutionTime.size() == endOfExecutionTime.size()) {
            //for each start time except first
            for (int i = 1; i < startOfExecutionTime.size(); i++) {
                //check if is equal to previous end time of execution
                //which means at that time was no interruption
                //so these times are redundant in list
                if (startOfExecutionTime.get(i).equals(endOfExecutionTime.get(i - 1))) {
                    //remove redundant times
                    startOfExecutionTime.remove(i);
                    endOfExecutionTime.remove(i-1);
                }
            }
        }
    }

    //adds time to the end of list
    public void addStartTimeOfExecution(int time) {
        this.startOfExecutionTime.add(time);
    }

    //adds time to the end of list
    public void addEndTimeOfExecution(int time) {
        this.endOfExecutionTime.add(time);
    }

    public void setMissedDeadline(int missedDeadline) {
        this.missedDeadline = missedDeadline;
    }

    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the taskPeriod
     */
    public int getTaskPeriod() {
        return taskPeriod;
    }

    /**
     * @param taskPeriod the taskPeriod to set
     */
    public void setTaskPeriod(int taskPeriod) {
        this.taskPeriod = taskPeriod;
    }

    /**
     * @return the phi
     */
    public int getPhi() {
        return phi;
    }

    /**
     * @param phi the phi to set
     */
    public void setPhi(int phi) {
        this.phi = phi;
    }

    /**
     * @return the rActivationTime
     */
    public int getrActivationTime() {
        return rActivationTime;
    }

    /**
     * @param rActivationTime the rActivationTime to set
     */
    public void setrActivationTime(int rActivationTime) {
        this.rActivationTime = rActivationTime;
    }

    /**
     * @return the dAbsoluteDeadline
     */
    public int getdAbsoluteDeadline() {
        return dAbsoluteDeadline;
    }

    /**
     * @param dAbsoluteDeadline the dAbsoluteDeadline to set
     */
    public void setdAbsoluteDeadline(int dAbsoluteDeadline) {
        this.dAbsoluteDeadline = dAbsoluteDeadline;
    }

    /**
     * @return the cExecutionTime
     */
    public int getcExecutionTime() {
        return cExecutionTime;
    }

    /**
     * @param cExecutionTime the cExecutionTime to set
     */
    public void setcExecutionTime(int cExecutionTime) {
        this.cExecutionTime = cExecutionTime;
    }
    
    public static class Comparators {

        /**
         * Used for Rate Monotonic algorithm. This comparator compares two 
         * InstanceOfPeriodicTask objects using their taskPeriod property.
         */
        public static Comparator<InstanceOfPeriodicTask> TASK_PERIOD
                = new Comparator<InstanceOfPeriodicTask>() {
                    @Override
                    public int compare(InstanceOfPeriodicTask o1, InstanceOfPeriodicTask o2) {
                        return o1.getTaskPeriod() - o2.getTaskPeriod();
                    }
                };
        
        /**
         * Used for Earliest Deadline First algorithm. This comparator compares
         * two InstanceOfPeriodicTask objects using their dAbsoluteDeadline property.
         */
        public static Comparator<InstanceOfPeriodicTask> ABSOLUTE_DEADLINE
                = new Comparator<InstanceOfPeriodicTask>() {
                    @Override
                    public int compare(InstanceOfPeriodicTask o1, InstanceOfPeriodicTask o2) {
                        return o1.getdAbsoluteDeadline() - o2.getdAbsoluteDeadline();
                    }
                };
        
        /**
         * Used for Deadline Monotonic algorithm.
         */
        public static Comparator<InstanceOfPeriodicTask> RELATIVE_DEADLINE
                = new Comparator<InstanceOfPeriodicTask>() {
                    @Override
                    public int compare(InstanceOfPeriodicTask o1, InstanceOfPeriodicTask o2) {
                        return (o1.getdAbsoluteDeadline() - o1.getrActivationTime())
                        - (o2.getdAbsoluteDeadline() - o2.getrActivationTime());
                    }
                };
        
        /* We can add other comparators here */
    }

    @Override
    public String toString() {
        StringBuilder sbResult = new StringBuilder();
        
        //first line is task id
        sbResult.append(this.getId());
        sbResult.append(System.lineSeparator());
        
        //second line is activation time
        sbResult.append(this.getrActivationTime());
        sbResult.append(System.lineSeparator());
        
        //third line is absolute deadline
        sbResult.append(this.getdAbsoluteDeadline());
        sbResult.append(System.lineSeparator());
        
        //fourth line contains all the activation times.
        //if startOfExecutionTime is empty add -1 instead
        if (this.startOfExecutionTime.isEmpty()) {
            sbResult.append("-1");
        } else {
            for (Integer i : this.startOfExecutionTime) {
                sbResult.append(i);
                sbResult.append(" ");
            }
        }
        sbResult.append(System.lineSeparator());
    
        //fifth line contains all the activation times.
        //if endOfExecutionTime is empty add -1 instead
        if (this.endOfExecutionTime.isEmpty()) {
            sbResult.append("-1");
        } else {
            for (Integer i : this.endOfExecutionTime) {
                sbResult.append(i);
                sbResult.append(" ");
            }
        }
        sbResult.append(System.lineSeparator());
        
        //sixth line is -1 if the instance finished successfully.
        //if the instance missed its deadline it contains the deadline it missed
        sbResult.append(this.missedDeadline);
        sbResult.append(System.lineSeparator());
        
        return sbResult.toString();
    }
}

{'fraction_non_alphanumeric': 0.08381966266914641, 'fraction_numerical': 0.003270698390303341, 'mean_word_length': 1.8979743542092549, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '1367957', 'n_tokens_mistral': 4176, 'n_tokens_neox': 4067, 'n_words': 1039}