/**************************************************************************
 * Program:   Image Guided Surgery Software Validation Toolkit
 * File:      IgstkvtMergeList.java
 * Language:  Java
 * Date:      Mar 18, 2008
 * 
 * Copyright (c) ISC  Insight Software Consortium.  All rights reserved.
 * See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
 * 
 *    This software is distributed WITHOUT ANY WARRANTY; without even
 *    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 *    PURPOSE.  See the above copyright notices for more information.      
 *************************************************************************/

package org.igstk.validation.simulator.rules;

import java.util.ArrayList;

import org.igstk.validation.generator.IgstkvtSendEvent;

/**
 * A simple strategy implementation to merge n sendEvent lists into one big one.
 * @author Kevin Gary
 *
 */
public class IgstkvtMergeList {

    /**
     * This is the main method for this class.
     * @param args
     */
    public static void main(String[] args) {

        ArrayList<IgstkvtSendEvent> l1 = new ArrayList<IgstkvtSendEvent>();
        l1.add(new IgstkvtSendEvent("test1", "testId1"));
        l1.add(new IgstkvtSendEvent("test1", "testId1"));

        ArrayList<IgstkvtSendEvent> l2 = new ArrayList<IgstkvtSendEvent>();
        l2.add(new IgstkvtSendEvent("test2", "testId2"));
        l2.add(new IgstkvtSendEvent("test2", "testId2"));

        ArrayList<ArrayList<IgstkvtSendEvent>> masterTempList = 
            new ArrayList<ArrayList<IgstkvtSendEvent>>();

        masterTempList.add(l1);
        masterTempList.add(l2);

        ArrayList<IgstkvtSendEvent> allTempList = IgstkvtMergeList.getAllList(masterTempList);
    }

    /**
     * This method is a setter for the master list.
     * @param masterList
     * @return
     */
    public static final ArrayList<IgstkvtSendEvent> getAllList(
            		ArrayList<ArrayList<IgstkvtSendEvent>> masterList) {
    	ArrayList<IgstkvtSendEvent> rval = new ArrayList<IgstkvtSendEvent>();
        
        // KG modified 1/14/10. All we are going to do is sequence, or flatten,
        // the list of lists into a single list of send events.
        for (int i = 0; masterList != null && i < masterList.size(); i++) {
        	rval.addAll(masterList.get(i)); // each element of mL is a list of send events
        }
        return rval;
    }

    private IgstkvtMergeList() {}
}
