/**
 * The Main class
 */

public class GDI2BTreeMain 
{

        static final String COMMAND_ADD = "add";
        static final String COMMAND_DEL = "del";
	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
            //new reader
            GDI2BTreeDataReader reader = new GDI2BTreeDataReader("test_03");

            //new tree
            GDI2BTree tree = new GDI2BTree();

            //set order from reader
            tree.setOrder(reader.readOrder());

            //current line
            String[] line = null;

            //read line by line
            while((line = reader.getNextLine()) != null)
            {
                if(line.length > 1){
                    //add
                    if(line[0].equals(COMMAND_ADD)){
                        for(int i=1; i< line.length; i++){
                            if(!tree.addData(line[i])){
                                System.out.println("Internal Problem on add to tree");
                            }
                        }
                    } else
                    //del
                    if(line[0].equals(COMMAND_DEL)){
                        for(int i=1; i< line.length; i++){
                            if(!tree.delData(line[i])){
                                System.out.println("Internal Problem on del from tree");
                            }
                        }
                    } else{
                        throw new GDI2BTreeFileFormatException("Unknown command!");
                    }
                } else{
                    throw new GDI2BTreeFileFormatException("Wrong command line format");
                }
            }

            //close the reader
            reader.closeGDI2BTreeDataReader();

            //print tree
            tree.printBTree();
	}
}
