/*
 *  Copyright (C) 2010 reuillon
 *
 *  This program 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.openmole.core.implementation.plan;

import java.util.Collection;
import java.util.Iterator;

import org.openmole.core.model.plan.IExploredPlan;
import org.openmole.core.model.plan.IFactorValues;

public class ExploredPlan implements IExploredPlan {

    Collection<IFactorValues> values;

    public ExploredPlan(Collection<IFactorValues> values) {
        super();
        this.values = values;
    }

    @Override
    public Iterator<IFactorValues> iterator() {
        return values.iterator();
    }
    
}

/*
 *  Copyright (C) 2010 reuillon
 *
 *  This program 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.openmole.core.implementation.plan;

import java.util.Collection;
import java.util.Iterator;

import org.openmole.core.model.plan.IExploredPlan;
import org.openmole.core.model.plan.IFactorValues;

public class ExploredPlan implements IExploredPlan {

    Collection<IFactorValues> values;

    public ExploredPlan(Collection<IFactorValues> values) {
        super();
        this.values = values;
    }

    @Override
    public Iterator<IFactorValues> iterator() {
        return values.iterator();
    }

    public String toCSV() {
        StringBuffer sb = new StringBuffer();
        StringBuffer sbn = new StringBuffer();
        int num = 0;
        while (this.iterator().hasNext()) {
            IFactorValues ifv = this.iterator().next();
            Iterator<String> it = ifv.getNames().iterator();
            while (it.hasNext()) {
                if (num == 0) { // first line for factor names
                    sbn.append(it.next()).append(",");
                    sbn.deleteCharAt(sb.length() - 1).append("\n=");
                }
                sb.append(it.next()).append(",");
                sb.deleteCharAt(sb.length() - 1).append("\n=");

            }

        }
        sbn.append(sb.toString());

        return sbn.toString();

    }
    
}

add toCSV method to export design values in a csv format suitable for some export