<commit_before>/**
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 *
 */

package com.microsoft.azure;

/**
 * The base implementation of TaskGroup interface.
 *
 * @param <T> the result type of the tasks in the group
 * @param <U> type representing task in the group
 */
public abstract class TaskGroupBase<T, U extends TaskItem<T>>
    implements TaskGroup<T, U> {
    private DAGraph<U, DAGNode<U>> dag;

    /**
     * Creates TaskGroupBase.
     *
     * @param rootTaskItemId the id of the root task in this task group
     * @param rootTaskItem the root task
     */
    public TaskGroupBase(String rootTaskItemId, U rootTaskItem) {
        this.dag = new DAGraph<>(new DAGNode<>(rootTaskItemId, rootTaskItem));
    }

    @Override
    public DAGraph<U, DAGNode<U>> dag() {
        return dag;
    }

    @Override
    public boolean isRoot() {
        return !dag.hasParent();
    }

    @Override
    public void merge(TaskGroup<T, U> parentTaskGroup) {
        dag.merge(parentTaskGroup.dag());
    }

    @Override
    public void execute() throws Exception {
        if (isRoot()) {
            dag.prepare();
            DAGNode<U> nextNode = dag.getNext();
            while (nextNode != null) {
                if (dag.isRootNode(nextNode)) {
                    executeRootTask(nextNode.data());
                } else {
                    nextNode.data().execute();
                }
                dag.reportedCompleted(nextNode);
                nextNode = dag.getNext();
            }
        }
    }

    @Override
    public T taskResult(String taskId) {
        return dag.getNodeData(taskId).result();
    }

    /**
     * executes the root task in this group.
     * <p>
     * this method will be invoked when all the task dependencies of the root task are finished
     * executing, at this point root task can be executed by consuming the result of tasks it
     * depends on.
     *
     * @param task the root task in this group
     * @throws Exception the exception
     */
    public abstract void executeRootTask(U task) throws Exception;
}
<commit_msg>Fixing the bug of trying to create created resources during update, adding better way to name gen resource names<commit_after>/**
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 *
 */

package com.microsoft.azure;

/**
 * The base implementation of TaskGroup interface.
 *
 * @param <T> the result type of the tasks in the group
 * @param <U> type representing task in the group
 */
public abstract class TaskGroupBase<T, U extends TaskItem<T>>
    implements TaskGroup<T, U> {
    private DAGraph<U, DAGNode<U>> dag;

    /**
     * Creates TaskGroupBase.
     *
     * @param rootTaskItemId the id of the root task in this task group
     * @param rootTaskItem the root task
     */
    public TaskGroupBase(String rootTaskItemId, U rootTaskItem) {
        this.dag = new DAGraph<>(new DAGNode<>(rootTaskItemId, rootTaskItem));
    }

    @Override
    public DAGraph<U, DAGNode<U>> dag() {
        return dag;
    }

    @Override
    public boolean isRoot() {
        return !dag.hasParent();
    }

    @Override
    public void merge(TaskGroup<T, U> parentTaskGroup) {
        dag.merge(parentTaskGroup.dag());
    }

    @Override
    public void execute() throws Exception {
        if (isRoot()) {
            dag.prepare();
            DAGNode<U> nextNode = dag.getNext();
            while (nextNode != null) {
                if (dag.isRootNode(nextNode)) {
                    executeRootTask(nextNode.data());
                    dag.reportedCompleted(nextNode);
                } else {
                    // TaskGroupBase::execute will be called both in update and create
                    // scenarios, so run the task only if it not not executed already.
                    if (nextNode.data().result() == null) {
                        nextNode.data().execute();
                        dag.reportedCompleted(nextNode);
                    }
                }
                nextNode = dag.getNext();
            }
        }
    }

    @Override
    public T taskResult(String taskId) {
        return dag.getNodeData(taskId).result();
    }

    /**
     * executes the root task in this group.
     * <p>
     * this method will be invoked when all the task dependencies of the root task are finished
     * executing, at this point root task can be executed by consuming the result of tasks it
     * depends on.
     *
     * @param task the root task in this group
     * @throws Exception the exception
     */
    public abstract void executeRootTask(U task) throws Exception;
}

{'fraction_non_alphanumeric': 0.09341342170671085, 'fraction_numerical': 0.0, 'mean_word_length': 2.117495158166559, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '6080610', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1285, 'n_words': 449}