import java.util.ArrayList;

/**
 * This class stores all the information of an English
 * file as an array. The array index corresponds to
 * the line-count number in the English file 
 * (assuming first line of English file is zero). 
 */
public class LineList extends  ArrayList<Line> {
	
/**
 *
 */
	public void addLOOP(
		int lineNum, 
		int reps)//repetitions
	{
		Line	line = new Line();
		line._lineType = LineEnum.LOOP;
		Throw.If( lineNum != size(),
			"line number must equal current size of array");
		line._ints = new int[2];
		line._ints[0] = reps;//reps = loop repetitions
		line._ints[1] = 0;//timesVisited
		add(line);		
		
    }
/**
 *
 */
	public void addNEXT(
		int loopNum)
	{
		Line	line = new Line();
		line._lineType = LineEnum.NEXT;
		line._ints = new int[1];
		line._ints[0] = loopNum;
		add(line);		
		
    }
/**
 *
 */
	public void addSWAP(
		int bit1, 
		int bit2, 
		Controls controls)
	{
		Line	line = new Line();
		line._lineType = LineEnum.SWAP;
		line._ints = new int[2];
		line._ints[0] = bit1;
		line._ints[1] = bit2;
		line._controls = new Controls(controls);
		add(line);
	}
/**
 *
 */
	public void addPHAS(
		double angleDeg, 
		int targetBitPosition, 
		Controls controls)
	{
		Line	line = new Line();
		line._lineType = LineEnum.PHAS;
		line._ints = new int[1];
		line._ints[0] = targetBitPosition;
		line._doubles = new double[1];
		line._doubles[0] = angleDeg;
		line._controls = new Controls(controls);
		add(line);
	}
/**
 *
 */
	public void addP_PH(
		int projectionBit, 
		double angleDeg,
		int targetBitPosition, 
		Controls controls)
	{
		Line	line = new Line();
		if(projectionBit==0){			
			line._lineType = LineEnum.P0PH;			
		}else if(projectionBit==1){			
			line._lineType = LineEnum.P1PH;			
		}else{
			Throw.If(true, "unsupported phase shift gate");	
		}
		line._ints = new int[1];
		line._ints[0] = targetBitPosition;
		line._doubles = new double[1];
		line._doubles[0] = angleDeg;
		line._controls = new Controls(controls);
		add(line);
	}
/**
 *
 */
	public void addSIG(
		int direction,//1=X, 2=Y, 3=Z
		int targetBitPosition, 
		Controls controls)
	{
		Line	line = new Line();
		switch(direction){
			case 1:
				line._lineType = LineEnum.SIGX;
				break;
			case 2:
				line._lineType = LineEnum.SIGY;
				break;
			case 3:
				line._lineType = LineEnum.SIGZ;
				break;
			default:
				Throw.If(true, "unsupported SIG gate");				
		}
		line._ints = new int[1];
		line._ints[0] = targetBitPosition;
		line._controls = new Controls(controls);
		add(line);
	}
/**
 *
 */
	public void addHAD2(
		int targetBitPosition, 
		Controls controls)
	{
		Line	line = new Line();
		line._lineType = LineEnum.HAD2;
		line._ints = new int[1];
		line._ints[0] = targetBitPosition;
		line._controls = new Controls(controls);
		add(line);

	}
/**
 *
 */
	public void addROT(
		int direction,//1=X, 2=Y, 3=Z
		double angleDeg,
		int targetBitPosition, 
		Controls controls)
	{
		Line	line = new Line();
		switch(direction){
			case 1:
				line._lineType = LineEnum.ROTX;
				break;
			case 2:
				line._lineType = LineEnum.ROTY;
				break;
			case 3:
				line._lineType = LineEnum.ROTZ;
				break;
			default:
				Throw.If(true, "unsupported ROT gate");				
		}
		line._doubles = new double[1];
		line._doubles[0] = angleDeg;
		line._ints = new int[1];
		line._ints[0] = targetBitPosition;
		line._controls = new Controls(controls);
		add(line);
	}
/**
 *
 */
	public void addROTN(
		double angleX_deg,
		double angleY_deg,
		double angleZ_deg,
		int targetBitPosition, 
		Controls controls)
	{
		Line	line = new Line();
		line._lineType = LineEnum.ROTN;
		line._doubles = new double[3];
		line._doubles[0] = angleX_deg;
		line._doubles[1] = angleY_deg;
		line._doubles[2] = angleZ_deg;		
		line._ints = new int[1];
		line._ints[0] = targetBitPosition;
		line._controls = new Controls(controls);
		add(line);
	}

}
