// Copyright 2008-2010 by Mary McGlohon
// Carnegie Mellon University
// mmcgloho@cs.cmu.edu

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

// Iterator for going through a file line by line in cascade format
// and returning cascades
public class CascadeIterator {
    private BufferedReader br;
    private String next;
    private boolean useAuthor;
    
    CascadeIterator(String filename, boolean useAuthor) {
	this.useAuthor = useAuthor;
        try {
	    br = new BufferedReader(new FileReader(filename));
	    next = br.readLine();
	}
	catch(IOException e) {
	    e.printStackTrace();
	}
    }

    int getNextSize() {
	String[] parts = next.split(" ");
	return parts.length/2;
    }

    boolean hasNext() {
	return (next!=null);
    }

    Cascade next() {
	Cascade casc = new Cascade(next, useAuthor);
	try{
	    next = br.readLine();
	}
	catch(IOException e) {
	    e.printStackTrace();
	}
	return casc;
    }
    
    public void close() {
        try {
            br.close();
        } catch(IOException e) {
            e.printStackTrace();
        }
        
    }

}