package commons.script;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TokenizedLines implements Iterable<List<String>>
{
class TokenizedLine
{
TokenizedLine(int no, List<String> tokens)
{
   this.lineInFile = no;
   this.tokens = tokens;
}

public int          lineInFile;
public List<String> tokens;
}

List<TokenizedLine> lines = new ArrayList<TokenizedLine>();

public void add(int no, List<String> tokens)
{
   lines.add(new TokenizedLine(no, tokens));
}

public List<String> tokens(int index)
{
   return index >= 0 && index < lines.size() ? lines.get(index).tokens : new ArrayList<String>();
}

public int indexToLineInFile(int index)
{
   return index >= 0 && index < lines.size() ? lines.get(index).lineInFile : -1;
}

public int size()
{
   return lines.size();
}

public Iterator<List<String>> iterator()
{
   final Iterator<TokenizedLine> iter = lines.iterator();
   return new Iterator<List<String>>()
   {
      public boolean hasNext()
      {
         return iter.hasNext();
      }

      public List<String> next()
      {
         return iter.next().tokens;
      }

      public void remove()
      {
      }
   };
}
}
