/*
 * The contents of this file are subject to the terms 
 * of the Common Development and Distribution License 
 * (the License).  You may not use this file except in
 * compliance with the License.
 * 
 * You can obtain a copy of the license at 
 * https://glassfish.dev.java.net/public/CDDLv1.0.html or
 * glassfish/bootstrap/legal/CDDLv1.0.txt.
 * See the License for the specific language governing 
 * permissions and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL 
 * Header Notice in each file and include the License file 
 * at glassfish/bootstrap/legal/CDDLv1.0.txt.  
 * If applicable, add the following below the CDDL Header, 
 * with the fields enclosed by brackets [] replaced by
 * you own identifying information: 
 * "Portions Copyrighted [year] [name of copyright owner]"
 * 
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 */

package com.sun.enterprise.tools.verifier;


import java.util.Vector;
import java.util.logging.LogRecord;

/**
 * This class is responsible for collecting the result and error data
 *
 * @author Sudipto Ghosh
 */

public class ResultManager {

    public void add(Result result) {
        Result r = result;
        addToResult(r);
    }

    public void log(LogRecord logRecord) {
        error.add(logRecord);
    }

    public int getFailedCount() {
        return (failedResults == null) ? 0 : failedResults.size();
    }

    public int getWarningCount() {
        return (warningResults == null) ? 0 : warningResults.size();
    }

    public int getErrorCount() {
        return (error == null) ? 0 : error.size();
    }

    public Vector getFailedResults() {
        return failedResults;
    }

    public Vector getOkayResults() {
        return okayResults;
    }

    public Vector getWarningResults() {
        return warningResults;
    }

    public Vector getNaResults() {
        return naResults;
    }

    public Vector getError() {
        return error;
    }

    /**
     * add the result object to specific Vector based on the status.
     *
     * @param r
     */
    private void addToResult(Result r) {
        if (r.getStatus() == Result.FAILED) {
            failedResults.add(r);
        } else if (r.getStatus() == Result.PASSED) {
            okayResults.add(r);
        } else if (r.getStatus() == Result.WARNING) {
            warningResults.add(r);
        } else if ((r.getStatus() == Result.NOT_APPLICABLE) ||
                (r.getStatus() == Result.NOT_RUN) ||
                (r.getStatus() == Result.NOT_IMPLEMENTED)) {
            naResults.add(r);
        }
    }

    private Vector<Result> failedResults = new Vector<Result>();
    private Vector<Result> okayResults = new Vector<Result>();
    private Vector<Result> warningResults = new Vector<Result>();
    private Vector<Result> naResults = new Vector<Result>();
    private Vector<LogRecord> error = new Vector<LogRecord>();
}
