<commit_before>/*
 * ################################################################
 *
 * ProActive Parallel Suite(TM): The Java(TM) library for
 *    Parallel, Distributed, Multi-Core Computing for
 *    Enterprise Grids & Clouds
 *
 * Copyright (C) 1997-2010 INRIA/University of 
 *              Nice-Sophia Antipolis/ActiveEon
 * Contact: <EMAIL> or <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 3 of
 * the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * If needed, contact us to obtain a release under GPL Version 2 
 * or a different license than the GPL.
 *
 *  Initial developer(s):               The ActiveEon Team
 *                        http://www.activeeon.com/
 *  Contributor(s):
 *
 * ################################################################
 * $$ACTIVEEON_INITIAL_DEV$$
 */
package org.ow2.proactive.scheduler.common.job.factories;

import java.util.ArrayList;
import java.util.EmptyStackException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

import org.objectweb.proactive.annotation.PublicAPI;
import org.ow2.proactive.scheduler.common.job.TaskFlowJob;
import org.ow2.proactive.scheduler.common.task.Task;
import org.ow2.proactive.scheduler.common.task.TaskId;
import org.ow2.proactive.scheduler.common.task.flow.FlowActionType;
import org.ow2.proactive.scheduler.common.task.flow.FlowBlock;


/**
 * Static checking utility for TaskFlow Jobs
 * <p>
 * Checks a TaskFlow is correct against a set of well defined rules,
 * and attempts to hint at the problem when detected.
 * 
 *  
 * @author The ProActive Team
 * @since ProActive Scheduling 2.2
 * 
 */
@PublicAPI
public class FlowChecker {

    /**
     * Dummy pair class containing two Task
     */
    public static class Block {
        public TaskTree start = null;
        public TaskTree end = null;

        public Block(TaskTree a, TaskTree b) {
            this.start = a;
            this.end = b;
        }
    }

    /**
     * Dummy double linked Task tree structure
     * natural Tasks only have bottom-up links
     */
    public static class TaskTree {
        // top-down dependencies
        public List<TaskTree> children = new ArrayList<TaskTree>();
        // bottom-up dependencies
        public List<TaskTree> parents = new ArrayList<TaskTree>();
        // enclosed Task
        public Task element = null;

        // if / else top-down links
        public List<TaskTree> targets = new ArrayList<TaskTree>();
        // if / else bottom-up links
        public TaskTree targetOf = null;
        // join top-down target
        public TaskTree targetJoin = null;
        // join bottom-up links
        public List<TaskTree> joins = new ArrayList<TaskTree>();
        // join top-down link
        public TaskTree joinedBy = null;

        public boolean joinTrigger = false;

        public TaskTree(Task e) {
            this.element = e;
        }

        @Override
        public String toString() {
            return element.getName();
        }
    }

    /**
     * Job to check
     */
    private TaskFlowJob job;

    /**
     * task blocks in the job
     */
    private List<Block> blocks;

    /**
     *  the tasks of the job in a double-linked tree structure
     *  only roots are exposed in the list
     */
    private List<TaskTree> roots;

    /**
     * the tasks of the job in a double-linked tree structure      
     */
    private List<TaskTree> tasksFlat;

    /**
     * Constructor
     * 
     * @param job the job to check
     * @throws FlowError 
     */
    private FlowChecker(TaskFlowJob job, List<Block> blocks) throws FlowError {
        this.job = job;
        if (blocks != null) {
            this.blocks = blocks;
        } else {
            this.blocks = new ArrayList<Block>();
        }
        blocks.clear();
        createTaskTree(job);
    }

    /**
     * Checks if the provided Job is valid and can be scheduled.
     * <p>
     * A call to this method should have no side-effect on the provided job,
     * nor the tasks contained.
     * 
     * @param job the job to validate
     * @return a FlowError if the Job is not valid, or null if it is valid.
     */
    public static FlowError validate(TaskFlowJob job) {
        return validate(job, null);
    }<commit_msg>fix SCHEDULING-820<commit_after>/*
 * ################################################################
 *
 * ProActive Parallel Suite(TM): The Java(TM) library for
 *    Parallel, Distributed, Multi-Core Computing for
 *    Enterprise Grids & Clouds
 *
 * Copyright (C) 1997-2010 INRIA/University of 
 *              Nice-Sophia Antipolis/ActiveEon
 * Contact: <EMAIL> or <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 3 of
 * the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * If needed, contact us to obtain a release under GPL Version 2 
 * or a different license than the GPL.
 *
 *  Initial developer(s):               The ActiveEon Team
 *                        http://www.activeeon.com/
 *  Contributor(s):
 *
 * ################################################################
 * $$ACTIVEEON_INITIAL_DEV$$
 */
package org.ow2.proactive.scheduler.common.job.factories;

import java.util.ArrayList;
import java.util.EmptyStackException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

import org.objectweb.proactive.annotation.PublicAPI;
import org.ow2.proactive.scheduler.common.job.TaskFlowJob;
import org.ow2.proactive.scheduler.common.task.Task;
import org.ow2.proactive.scheduler.common.task.TaskId;
import org.ow2.proactive.scheduler.common.task.flow.FlowActionType;
import org.ow2.proactive.scheduler.common.task.flow.FlowBlock;


/**
 * Static checking utility for TaskFlow Jobs
 * <p>
 * Checks a TaskFlow is correct against a set of well defined rules,
 * and attempts to hint at the problem when detected.
 * 
 *  
 * @author The ProActive Team
 * @since ProActive Scheduling 2.2
 * 
 */
@PublicAPI
public class FlowChecker {

    /**
     * Dummy pair class containing two Task
     */
    public static class Block {
        public TaskTree start = null;
        public TaskTree end = null;

        public Block(TaskTree a, TaskTree b) {
            this.start = a;
            this.end = b;
        }
    }

    /**
     * Dummy double linked Task tree structure
     * natural Tasks only have bottom-up links
     */
    public static class TaskTree {
        // top-down dependencies
        public List<TaskTree> children = new ArrayList<TaskTree>();
        // bottom-up dependencies
        public List<TaskTree> parents = new ArrayList<TaskTree>();
        // enclosed Task
        public Task element = null;

        // if / else top-down links
        public List<TaskTree> targets = new ArrayList<TaskTree>();
        // if / else bottom-up links
        public TaskTree targetOf = null;
        // join top-down target
        public TaskTree targetJoin = null;
        // join bottom-up links
        public List<TaskTree> joins = new ArrayList<TaskTree>();
        // join top-down link
        public TaskTree joinedBy = null;

        public boolean joinTrigger = false;

        public TaskTree(Task e) {
            this.element = e;
        }

        @Override
        public String toString() {
            return element.getName();
        }
    }

    /**
     * Job to check
     */
    private TaskFlowJob job;

    /**
     * task blocks in the job
     */
    private List<Block> blocks;

    /**
     *  the tasks of the job in a double-linked tree structure
     *  only roots are exposed in the list
     */
    private List<TaskTree> roots;

    /**
     * the tasks of the job in a double-linked tree structure      
     */
    private List<TaskTree> tasksFlat;

    /**
     * Constructor
     * 
     * @param job the job to check
     * @throws FlowError 
     */
    private FlowChecker(TaskFlowJob job, List<Block> blocks) throws FlowError {
        this.job = job;
        if (blocks != null) {
            this.blocks = blocks;
        } else {
            this.blocks = new ArrayList<Block>();
        }
        this.blocks.clear();
        createTaskTree(job);
    }

    /**
     * Checks if the provided Job is valid and can be scheduled.
     * <p>
     * A call to this method should have no side-effect on the provided job,
     * nor the tasks contained.
     * 
     * @param job the job to validate
     * @return a FlowError if the Job is not valid, or null if it is valid.
     */
    public static FlowError validate(TaskFlowJob job) {
        return validate(job, null);
    }
{'fraction_non_alphanumeric': 0.11173974540311174, 'fraction_numerical': 0.0067690442513639116, 'mean_word_length': 2.43000693000693, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1569564', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2665, 'n_words': 965}