<commit_before>package org.synyx.urlaubsverwaltung.availability.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.synyx.urlaubsverwaltung.application.domain.Application;
import org.synyx.urlaubsverwaltung.application.domain.ApplicationStatus;
import org.synyx.urlaubsverwaltung.application.service.ApplicationService;
import org.synyx.urlaubsverwaltung.person.Person;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


@Service
class VacationAbsenceProvider extends AbstractTimedAbsenceProvider {

    private final ApplicationService applicationService;

    @Autowired
    VacationAbsenceProvider(ApplicationService applicationService) {

        super(null);

        this.applicationService = applicationService;
    }

    @Override
    TimedAbsenceSpans addAbsence(TimedAbsenceSpans knownAbsences, Person person, LocalDate date) {

        Optional<TimedAbsence> vacationAbsence = checkForVacation(date, person);

        if (vacationAbsence.isPresent()) {
            List<TimedAbsence> knownAbsencesList = knownAbsences.getAbsencesList();
            knownAbsencesList.add(vacationAbsence.get());

            return new TimedAbsenceSpans(knownAbsencesList);
        }

        return knownAbsences;
    }


    @Override
    boolean isLastPriorityProvider() {

        return true;
    }


    private Optional<TimedAbsence> checkForVacation(LocalDate date, Person person) {

        List<Application> applications = applicationService.getApplicationsForACertainPeriodAndPerson(date, date,
                    person)
                .stream()
                .filter(application ->
                            application.hasStatus(ApplicationStatus.WAITING)
                            || application.hasStatus(ApplicationStatus.TEMPORARY_ALLOWED)
                            || application.hasStatus(ApplicationStatus.ALLOWED))
                .collect(Collectors.toList());

        if (applications.isEmpty()) {
            return Optional.empty();
        }

        Application application = applications.get(0);

        return Optional.of(new TimedAbsence(application.getDayLength(), TimedAbsence.Type.VACATION));
    }
}
<commit_msg>Minor cleanups for better readability<commit_after>package org.synyx.urlaubsverwaltung.availability.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.synyx.urlaubsverwaltung.application.domain.Application;
import org.synyx.urlaubsverwaltung.application.service.ApplicationService;
import org.synyx.urlaubsverwaltung.person.Person;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

import static java.util.stream.Collectors.toList;
import static org.synyx.urlaubsverwaltung.application.domain.ApplicationStatus.ALLOWED;
import static org.synyx.urlaubsverwaltung.application.domain.ApplicationStatus.TEMPORARY_ALLOWED;
import static org.synyx.urlaubsverwaltung.application.domain.ApplicationStatus.WAITING;
import static org.synyx.urlaubsverwaltung.availability.api.TimedAbsence.Type.VACATION;


@Service
class VacationAbsenceProvider extends AbstractTimedAbsenceProvider {

    private final ApplicationService applicationService;

    @Autowired
    VacationAbsenceProvider(ApplicationService applicationService) {

        super(null);

        this.applicationService = applicationService;
    }

    @Override
    TimedAbsenceSpans addAbsence(TimedAbsenceSpans knownAbsences, Person person, LocalDate date) {

        final Optional<TimedAbsence> vacationAbsence = checkForVacation(date, person);

        if (vacationAbsence.isPresent()) {
            List<TimedAbsence> knownAbsencesList = knownAbsences.getAbsencesList();
            knownAbsencesList.add(vacationAbsence.get());

            return new TimedAbsenceSpans(knownAbsencesList);
        }

        return knownAbsences;
    }


    @Override
    boolean isLastPriorityProvider() {

        return true;
    }


    private Optional<TimedAbsence> checkForVacation(LocalDate date, Person person) {

        final List<Application> applications = applicationService.getApplicationsForACertainPeriodAndPerson(date, date, person)
            .stream()
            .filter(application ->
                application.hasStatus(WAITING) || application.hasStatus(TEMPORARY_ALLOWED) || application.hasStatus(ALLOWED))
            .collect(toList());

        if (applications.isEmpty()) {
            return Optional.empty();
        }

        Application application = applications.get(0);

        return Optional.of(new TimedAbsence(application.getDayLength(), VACATION));
    }
}

{'fraction_non_alphanumeric': 0.08301727770754319, 'fraction_numerical': 0.00042140750105351877, 'mean_word_length': 3.6357421875, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '263580', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1269, 'n_words': 203}