class AtTime 
{
	public static Table execute(String timeVal, Table tab)
	{
		/* convert the time value (as 'String') entered by user to an 'int' value */
		int time = UserInterface.getMaxTime() ;
		try
		{
			time = Integer.parseInt(timeVal);
		}
		catch (NumberFormatException e)
		{
			System.out.print("Error: The data value '" + timeVal + "'");
			System.out.print(" entered is not a time value\n");
			System.out.print("All time values must be of an INTEGER type when"); 
			System.out.print(" performing 'query AT time' operation\n");
			System.out.println("ASSUMPTION MADE: Using system max time'"+time+"' value for AT operator");
			//System.exit(0); /* terminate application */
		}
		
		int index = 0;
		Object rmvRow; /* rows that are removed */

		while ( index<tab.getNoRowSet() ) /* go through all rows */
		{
			Row r = (Row) tab.getRow(index); /* get next row */
			int st = r.getRow_st();
			int et = r.getRow_et();
			
			if ( time>=st && time<=et ) { /* keep the row */
			  index++;
			  // PJM but also restrict [st,et] to time
			  r.setRow_st(time);
			  r.setRow_et(time);
			}
			else
				rmvRow = tab.removeRow(index); /* remove the row */
		}

		return tab;
	}

}
