Package instantbach.service.text

Source Code of instantbach.service.text.LoadProgressionGraph

package instantbach.service.text;

import instantbach.data.Graph;
import instantbach.service.Service;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
// Exceptions
import instantbach.service.exception.BadRulesException;

/**
* <p>Title: Load Progression Graph</p>
*
* <p>Description: Used to load a progression graph from an external text file</p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author John Valentino II
* @version 1.0
*/
public class LoadProgressionGraph {

    /** Reference to the parent controller */
    private Service service;

    /**
     * Creates the object for creating the progression graph
     * @param service Service
     * @todo Scrap this class and load the progression as part of an external rules file
     */
    public LoadProgressionGraph(Service service) {
        this.service = service;
    }

    /**
     * Creates the progression grpah from the given file
     * @param file String
     * @return Graph
     * @throws BadRulesException
     */
    public Graph createProgressionGraph(String file) throws BadRulesException{
        Graph graph = new Graph();

        try {
            BufferedReader in = new BufferedReader(new FileReader(file));

            String line = "";
            while ((line = in.readLine()) != null) {
                StringTokenizer t = new StringTokenizer(line," ");
                graph.addEdge(t.nextToken(),t.nextToken(),1);
            }

            in.close();
        } catch (Exception io) {
            io.printStackTrace();
            throw new BadRulesException(io.getMessage());
        }

        return graph;
    }
}
TOP

Related Classes of instantbach.service.text.LoadProgressionGraph

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.