Repository: kestra-io/kestra
File: core/src/main/java/io/kestra/core/models/executions/Execution.java (Java)

Code before:
            .toList();
    }

    public Optional<TaskRun> findFirstByState(State.Type state) {
        if (this.taskRunList == null) {
            return Optional.empty();
        }

        return this.taskRunList
            .stream()
            .filter(t -> t.getState().getCurrent() == state)
            .findFirst();
    }

    public Optional<TaskRun> findFirstRunning() {
        if (this.taskRunList == null) {
            return Optional.empty();
        }

        return this.taskRunList
            .stream()
            .filter(t -> t.getState().isRunning())
            .findFirst();
    }

    /**
     * Using reversed().findFirst() is intended for better performance,
     * as these methods are used heavily.
     * Do not replace it with Streams.findLast() in these methods,
     * as Streams.findLast() performs worse.
     *
     * See: @see <a href="https://github.com/kestra-io/kestra/pull/14385">KESTRA#14385</a>
     */
    public Optional<TaskRun> findLastNotTerminated() {
        if (this.taskRunList == null) {
            return Optional.empty();
        }

        return this.taskRunList
            .reversed()
            .stream()
            .filter(t -> !t.getState().isTerminated() || !t.getState().isPaused())
            .findFirst();
    }


    public Optional<TaskRun> findLastByState(List<TaskRun> taskRuns, State.Type state) {
        return taskRuns
            .reversed()
            .stream()
            .filter(t -> t.getState().getCurrent() == state)

Review comment (suggestion):
```suggestion
    /*
```

This should be a developer comment not a JavaDoc.

Code after:
            .toList();
    }

    public Optional<TaskRun> findFirstByState(State.Type state) {
        if (this.taskRunList == null) {
            return Optional.empty();
        }

        return this.taskRunList
            .stream()
            .filter(t -> t.getState().getCurrent() == state)
            .findFirst();
    }

    public Optional<TaskRun> findFirstRunning() {
        if (this.taskRunList == null) {
            return Optional.empty();
        }

        return this.taskRunList
            .stream()
            .filter(t -> t.getState().isRunning())
            .findFirst();
    }

    /*
     * Using reversed().findFirst() is intended for better performance,
     * as these methods are used heavily.
     * Do not replace it with Streams.findLast() in these methods,
     * as Streams.findLast() performs worse.
     *
     * See: @see <a href="https://github.com/kestra-io/kestra/pull/14385">KESTRA#14385</a>
     */
    public Optional<TaskRun> findLastNotTerminated() {
        if (this.taskRunList == null) {
            return Optional.empty();
        }

        return this.taskRunList
            .reversed()
            .stream()
            .filter(t -> !t.getState().isTerminated() || !t.getState().isPaused())
            .findFirst();
    }


    public Optional<TaskRun> findLastByState(List<TaskRun> taskRuns, State.Type state) {
        return taskRuns
            .reversed()
            .stream()
            .filter(t -> t.getState().getCurrent() == state)