package lab07.ex02;

public class TermFilter extends ReaderDecorator{

    private String[] line;
    private int words;


    public TermFilter(TextInterface txtInter){

        super(txtInter);
        this.line = new String[0];
        this.words = 0;
    }


    public boolean hasNext(){

        if (super.hasNext()){
            return true;     
        }

        else if (this.line != null && this.words < this.line.length){
            return true;
        } 

        else{
            return false;
        }
    }


    public String next(){

        if (line.length == words) {
            this.line = super.next().split("[ .,]+");
            this.words = 0;
        }
        
        String nextWord = line[words];
        this.words++;

        return nextWord;
    }
}

