<commit_before>package core.schedulers;

import core.MRAITimer;
import core.Message;

import java.util.*;

/**
 * Implements some of the common operations of the scheduler that are the same for most scheduler
 * implementations.
 */
public abstract class AbstractScheduler implements Scheduler {

    // The priority queue is used to schedule the messages using their arrival times to
    // define the priority of the messages. Messages with lower arrival times have higher priority.
    private final PriorityQueue<Message> queue = new PriorityQueue<>();

    // priority queue to schedule timers - timers are scheduled based on their expiration time
    private final PriorityQueue<MRAITimer> timerQueue = new PriorityQueue<>(
            Comparator.comparingInt(MRAITimer::getExpirationTime));

    /**
     * Adds a new message to the scheduler. The time of the message should correspond to the time at which
     * the router sent the message. The scheduler will add to this time some delay corresponding to the
     * time between the message is sent and the message reaches the target. The scheduler will always take
     * into account the time associated with the message's link, which means that the order of the messages
     * at the receiving end will be the same as at the sending point.
     *
     * @param message message to schedule.
     */
    @Override
    public void schedule(Message message) {
        int arrivalTimeWithDelay = message.getArrivalTime() + delay();
        int lastMessageArrivalTime = message.getTraversedLink().getLastArrivalTime();

        // the message must arrive after the last message sent through the same link
        int messagesArrivalTime = Integer.max(arrivalTimeWithDelay, lastMessageArrivalTime + 1);
        message.setArrivalTime(messagesArrivalTime);<commit_msg>Ensured the order of the timers with the same expiration time is always the same<commit_after>package core.schedulers;

import core.MRAITimer;
import core.Message;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.PriorityQueue;

/**
 * Implements some of the common operations of the scheduler that are the same for most scheduler
 * implementations.
 */
public abstract class AbstractScheduler implements Scheduler {

    // The priority queue is used to schedule the messages using their arrival times to
    // define the priority of the messages. Messages with lower arrival times have higher priority.
    private final PriorityQueue<Message> queue = new PriorityQueue<>();

    // priority queue to schedule timers - timers are scheduled based on their expiration time
    private final PriorityQueue<MRAITimer> timerQueue = new PriorityQueue<>((o1, o2) -> {
        int comparison = o1.getExpirationTime() - o2.getExpirationTime();
        if (comparison == 0) {
            comparison = o1.getOwner().getId() - o2.getOwner().getId();
        }

        return comparison;
    });

    /**
     * Adds a new message to the scheduler. The time of the message should correspond to the time at which
     * the router sent the message. The scheduler will add to this time some delay corresponding to the
     * time between the message is sent and the message reaches the target. The scheduler will always take
     * into account the time associated with the message's link, which means that the order of the messages
     * at the receiving end will be the same as at the sending point.
     *
     * @param message message to schedule.
     */
    @Override
    public void schedule(Message message) {
        int arrivalTimeWithDelay = message.getArrivalTime() + delay();
        int lastMessageArrivalTime = message.getTraversedLink().getLastArrivalTime();

        // the message must arrive after the last message sent through the same link
        int messagesArrivalTime = Integer.max(arrivalTimeWithDelay, lastMessageArrivalTime + 1);
        message.setArrivalTime(messagesArrivalTime);
{'fraction_non_alphanumeric': 0.063176440976592, 'fraction_numerical': 0.0022652907123080794, 'mean_word_length': 3.485327313769752, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2390279', 'n_tokens_mistral': 994, 'n_tokens_neox': 950, 'n_words': 439}