<commit_before>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
 * Contact: <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; either version
 * 2 of the License, or any later version.
 *
 * 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
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 */
package org.objectweb.proactive.extensions.scheduler.job;

import java.util.HashMap;

import org.objectweb.proactive.api.PAFuture;
import org.objectweb.proactive.extensions.scheduler.common.job.JobId;
import org.objectweb.proactive.extensions.scheduler.common.job.JobResult;
import org.objectweb.proactive.extensions.scheduler.common.task.TaskResult;


/**
 * Class representing a job result. A job result is a map of task result. The
 * key of the map is the name of the task on which to get the result. To
 * identify the job result, it provides the id of the job in the scheduler and
 * the job name.
 *
 * @author The ProActive Team
 * @version 3.9, Jul 5, 2007
 * @since ProActive 3.9
 */
public class JobResultImpl implements JobResult {
    private JobId id = null;
    private HashMap<String, TaskResult> allResults = null;
    private HashMap<String, TaskResult> preciousResults = null;
    private HashMap<String, TaskResult> exceptionResults = null;

    /**
     * ProActive empty constructor
     */
    public JobResultImpl() {
    }

    /**
     * Instantiate a new JobResult with a jobId and a result
     *
     * @param id
     *            the jobId associated with this result
     */
    public JobResultImpl(JobId id) {
        this.id = id;
        allResults = new HashMap<String, TaskResult>();
        preciousResults = new HashMap<String, TaskResult>(1);
        exceptionResults = new HashMap<String, TaskResult>(0);
    }

    /**
     * To get the id
     *
     * @return the id
     */
    public JobId getId() {
        return id;
    }

    /**
     * To get the name of the job that has generate this result.
     *
     * @return the name
     */
    public String getName() {
        return getId().getReadableName();
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#addTaskResult(java.lang.String, org.objectweb.proactive.extensions.scheduler.common.task.TaskResult, boolean)
     */
    public void addTaskResult(String taskName, TaskResult taskResult, boolean isPrecious) {
        //allResults
        allResults.put(taskName, taskResult);

        //preciousResult
        if (isPrecious)
            preciousResults.put(taskName, taskResult);

        //exceptionResults
        if (!PAFuture.isAwaited(taskResult) && taskResult.hadException()) {
            exceptionResults.put(taskName, taskResult);
        }
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#getAllResults()
     */
    public HashMap<String, TaskResult> getAllResults() {
        return allResults;
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#getExceptionResults()
     */
    public HashMap<String, TaskResult> getExceptionResults() {
        return exceptionResults;
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#getPreciousResults()
     */
    public HashMap<String, TaskResult> getPreciousResults() {
        return preciousResults;
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#hadException()
     */
    public boolean hadException() {
        return exceptionResults != null;
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#removeResult(java.lang.String)
     */
    public void removeResult(String task) {
        allResults.remove(task);
        exceptionResults.remove(task);
        preciousResults.remove(task);
    }

    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        if (allResults.size() == 0) {
            return "No result available in this job !";
        }

        StringBuilder toReturn = new StringBuilder("\n");

        for (TaskResult res : allResults.values()) {
            try {
                toReturn.append("\t" + res.value() + "\n");
            } catch (Throwable e) {
                toReturn.append("\t" + res.getException().getMessage() + "\n");
            }
        }<commit_msg>Fixed bug in jobResultImpl : Exception results HM empty means that job has no exceptions<commit_after>/*
 * ################################################################
 *
 * ProActive: The Java(TM) library for Parallel, Distributed,
 *            Concurrent computing with Security and Mobility
 *
 * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
 * Contact: <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; either version
 * 2 of the License, or any later version.
 *
 * 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
 *
 *  Initial developer(s):               The ProActive Team
 *                        http://proactive.inria.fr/team_members.htm
 *  Contributor(s):
 *
 * ################################################################
 */
package org.objectweb.proactive.extensions.scheduler.job;

import java.util.HashMap;

import org.objectweb.proactive.api.PAFuture;
import org.objectweb.proactive.extensions.scheduler.common.job.JobId;
import org.objectweb.proactive.extensions.scheduler.common.job.JobResult;
import org.objectweb.proactive.extensions.scheduler.common.task.TaskResult;


/**
 * Class representing a job result. A job result is a map of task result. The
 * key of the map is the name of the task on which to get the result. To
 * identify the job result, it provides the id of the job in the scheduler and
 * the job name.
 *
 * @author The ProActive Team
 * @version 3.9, Jul 5, 2007
 * @since ProActive 3.9
 */
public class JobResultImpl implements JobResult {
    private JobId id = null;
    private HashMap<String, TaskResult> allResults = null;
    private HashMap<String, TaskResult> preciousResults = null;
    private HashMap<String, TaskResult> exceptionResults = null;

    /**
     * ProActive empty constructor
     */
    public JobResultImpl() {
    }

    /**
     * Instantiate a new JobResult with a jobId and a result
     *
     * @param id
     *            the jobId associated with this result
     */
    public JobResultImpl(JobId id) {
        this.id = id;
        allResults = new HashMap<String, TaskResult>();
        preciousResults = new HashMap<String, TaskResult>(1);
        exceptionResults = new HashMap<String, TaskResult>(0);
    }

    /**
     * To get the id
     *
     * @return the id
     */
    public JobId getId() {
        return id;
    }

    /**
     * To get the name of the job that has generate this result.
     *
     * @return the name
     */
    public String getName() {
        return getId().getReadableName();
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#addTaskResult(java.lang.String, org.objectweb.proactive.extensions.scheduler.common.task.TaskResult, boolean)
     */
    public void addTaskResult(String taskName, TaskResult taskResult, boolean isPrecious) {
        //allResults
        allResults.put(taskName, taskResult);

        //preciousResult
        if (isPrecious)
            preciousResults.put(taskName, taskResult);

        //exceptionResults
        if (!PAFuture.isAwaited(taskResult) && taskResult.hadException()) {
            exceptionResults.put(taskName, taskResult);
        }
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#getAllResults()
     */
    public HashMap<String, TaskResult> getAllResults() {
        return allResults;
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#getExceptionResults()
     */
    public HashMap<String, TaskResult> getExceptionResults() {
        return exceptionResults;
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#getPreciousResults()
     */
    public HashMap<String, TaskResult> getPreciousResults() {
        return preciousResults;
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#hadException()
     */
    public boolean hadException() {
        return exceptionResults.size() != 0;
    }

    /**
     * @see org.objectweb.proactive.extensions.scheduler.common.job.JobResult#removeResult(java.lang.String)
     */
    public void removeResult(String task) {
        allResults.remove(task);
        exceptionResults.remove(task);
        preciousResults.remove(task);
    }

    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        if (allResults.size() == 0) {
            return "No result available in this job !";
        }

        StringBuilder toReturn = new StringBuilder("\n");

        for (TaskResult res : allResults.values()) {
            try {
                toReturn.append("\t" + res.value() + "\n");
            } catch (Throwable e) {
                toReturn.append("\t" + res.getException().getMessage() + "\n");
            }
        }
{'fraction_non_alphanumeric': 0.12337358419919499, 'fraction_numerical': 0.006646073200411869, 'mean_word_length': 2.7382785164450665, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '379804', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2874, 'n_words': 835}