package model;

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

/**
 * @version Narch 22th 2020
 * @author Fernanda
 * Class Heads
 */
public class Heads {
	//0 indicates lecture, 1 add, 2 delete
	//0, 1, 2 heads
	private Element first;
	private Element last;
	
	public final static String PATH = ".\\docs\\in_turing.txt";
	
	private char c;
	
	
	public Heads(Element first, Element last, char c) {
		this.first = null;
		this.last = null;
		this.c = c;
	}

	public void addElement(String letter) {
		Element n= new Element(letter);
		if(first== null) {
			first= n;
		}else{
			n.setNext(first);
			first.setLast(n);
			first= n;
		}
		
	}

	public void deleteElement(String letter) {
		Element temp = null;
		if(first!=null) {
			temp= first;
			last= null;
		}
		while(temp!= null) {
			if(temp.getLetter()== letter) {
				if(last== null) {
					first= first.getNext();
					temp.setNext(null);
					temp= first;
				}else {
					last.setNext(temp.getNext());
					temp.setNext(null);
					temp= last.getNext();
				}
			}else {
				last= temp;
				temp= temp.getNext();
			}
		}
	}

	public void readElement() {

	}
	
	public void chargeData() throws NumberFormatException, IOException {
        BufferedReader bf = new BufferedReader(new FileReader(PATH));
        String line = bf.readLine();
        Element element;
        while ((line = bf.readLine()) != null) {
            String[] data = line.split("");
            
            element = new Element(data[0]);
        }
}
}
