

/*
    THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT: CHANGES WILL BE OVERWRITTEN.
    File generated by traciObject.xslt.
*/

/*   
    Copyright (C) 2013 ApPeAL Group, Politecnico di Torino

    This file is part of TraCI4J.

    TraCI4J is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    TraCI4J is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with TraCI4J.  If not, see <http://www.gnu.org/licenses/>.
*/


package it.polito.appeal.traci;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**

	Representation of a class of vehicles in the SUMO environment.
	@see <a href="http://sumo.sourceforge.net/doc/current/docs/userdoc/Definition_of_Vehicles,_Vehicle_Types,_and_Routes.html#Vehicle_Types">SUMO documentation</a>
	@author Enrico Gueli &lt;enrico.gueli@polito.it&gt;
	
*/
public class VehicleType 
extends TraciObject<VehicleType.Variable>
implements StepAdvanceListener
{

	/**
	 * Enumerates all the read queries. Each value can be used as an argument
	 * for {@link TraciObject#getReadQuery(Enum)}.
	 * 
	 * @author Enrico Gueli &lt;enrico.gueli@polito.it&gt;
	 */	
	public static enum Variable {
		
		/** 
		 * Query "ReadGlobalTravelTime"
		 * @see {@link #queryReadGlobalTravelTime}
		 */
		LENGTH,
		
		/** 
		 * Query "ReadAccel"
		 * @see {@link #queryReadAccel}
		 */
		ACCEL,
		
		/** 
		 * Query "ReadDecel"
		 * @see {@link #queryReadDecel}
		 */
		DECEL,
		
		/** 
		 * Query "ReadMaxSpeed"
		 * @see {@link #queryReadMaxSpeed}
		 */
		MAXSPEED,
		
		/** 
		 * Query "ReadMinGap"
		 * @see {@link #queryReadMinGap}
		 */
		MINGAP,
		
	}
	
	
	private final ChangeAccelQuery csqvar_ChangeAccel;
	
	private final ChangeDecelQuery csqvar_ChangeDecel;
	
	private final ChangeMaxSpeedQuery csqvar_ChangeMaxSpeed;
	
	private final ChangeMinGapQuery csqvar_ChangeMinGap;
	VehicleType (
		DataInputStream dis,
		DataOutputStream dos, 
		String id
		
	) {
		super(id, Variable.class);

		/*
		 * initialization of read queries
		 */
		
		addReadQuery(Variable.LENGTH, 
				new ReadObjectVarQuery.DoubleQ (dis, dos, 
				it.polito.appeal.traci.protocol.Constants.CMD_GET_VEHICLETYPE_VARIABLE, 
				id, 
				it.polito.appeal.traci.protocol.Constants.VAR_LENGTH
				
				));
		
		addReadQuery(Variable.ACCEL, 
				new ReadObjectVarQuery.DoubleQ (dis, dos, 
				it.polito.appeal.traci.protocol.Constants.CMD_GET_VEHICLETYPE_VARIABLE, 
				id, 
				it.polito.appeal.traci.protocol.Constants.VAR_ACCEL
				
				));
		
		addReadQuery(Variable.DECEL, 
				new ReadObjectVarQuery.DoubleQ (dis, dos, 
				it.polito.appeal.traci.protocol.Constants.CMD_GET_VEHICLETYPE_VARIABLE, 
				id, 
				it.polito.appeal.traci.protocol.Constants.VAR_DECEL
				
				));
		
		addReadQuery(Variable.MAXSPEED, 
				new ReadObjectVarQuery.DoubleQ (dis, dos, 
				it.polito.appeal.traci.protocol.Constants.CMD_GET_VEHICLETYPE_VARIABLE, 
				id, 
				it.polito.appeal.traci.protocol.Constants.VAR_MAXSPEED
				
				));
		
		addReadQuery(Variable.MINGAP, 
				new ReadObjectVarQuery.DoubleQ (dis, dos, 
				it.polito.appeal.traci.protocol.Constants.CMD_GET_VEHICLETYPE_VARIABLE, 
				id, 
				it.polito.appeal.traci.protocol.Constants.VAR_MINGAP
				
				));
		

		/*
		 * initialization of change state queries
		 */
		
		csqvar_ChangeAccel = new ChangeAccelQuery(dis, dos, id
		)
		{
			@Override
			void pickResponses(java.util.Iterator<it.polito.appeal.traci.protocol.ResponseContainer> responseIterator)
					throws TraCIException {
				super.pickResponses(responseIterator);
				
				queryReadAccel().setObsolete();
				
			}
		};
		
		csqvar_ChangeDecel = new ChangeDecelQuery(dis, dos, id
		)
		{
			@Override
			void pickResponses(java.util.Iterator<it.polito.appeal.traci.protocol.ResponseContainer> responseIterator)
					throws TraCIException {
				super.pickResponses(responseIterator);
				
				queryReadDecel().setObsolete();
				
			}
		};
		
		csqvar_ChangeMaxSpeed = new ChangeMaxSpeedQuery(dis, dos, id
		)
		{
			@Override
			void pickResponses(java.util.Iterator<it.polito.appeal.traci.protocol.ResponseContainer> responseIterator)
					throws TraCIException {
				super.pickResponses(responseIterator);
				
				queryReadMaxSpeed().setObsolete();
				
			}
		};
		
		csqvar_ChangeMinGap = new ChangeMinGapQuery(dis, dos, id
		)
		{
			@Override
			void pickResponses(java.util.Iterator<it.polito.appeal.traci.protocol.ResponseContainer> responseIterator)
					throws TraCIException {
				super.pickResponses(responseIterator);
				
				queryReadMinGap().setObsolete();
				
			}
		};
		
	
	}
	
	
	
	@Override
	public void nextStep(double step) {
		
		getReadQuery(Variable.MAXSPEED).setObsolete();
		
		getReadQuery(Variable.MINGAP).setObsolete();
		
	}
	
	
	
	
	
	/**
	 * @return the instance of {@link ReadObjectVarQuery} relative to this query.
	 */
	public ReadObjectVarQuery<Double> queryReadGlobalTravelTime() {
		return (ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.LENGTH);
	}
	
	
	/**
	 * Executes an instance of {@link ReadObjectVarQuery} relative to this query,
	 * and returns the corresponding value.
	 */
	public Double getLength() throws IOException {
		return ((ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.LENGTH)).get();
	}
	
	/**
	 * @return the instance of {@link ReadObjectVarQuery} relative to this query.
	 */
	public ReadObjectVarQuery<Double> queryReadAccel() {
		return (ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.ACCEL);
	}
	
	
	/**
	 * Executes an instance of {@link ReadObjectVarQuery} relative to this query,
	 * and returns the corresponding value.
	 */
	public Double getAccel() throws IOException {
		return ((ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.ACCEL)).get();
	}
	
	/**
	 * @return the instance of {@link ReadObjectVarQuery} relative to this query.
	 */
	public ReadObjectVarQuery<Double> queryReadDecel() {
		return (ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.DECEL);
	}
	
	
	/**
	 * Executes an instance of {@link ReadObjectVarQuery} relative to this query,
	 * and returns the corresponding value.
	 */
	public Double getDecel() throws IOException {
		return ((ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.DECEL)).get();
	}
	
	/**
	 * @return the instance of {@link ReadObjectVarQuery} relative to this query.
	 */
	public ReadObjectVarQuery<Double> queryReadMaxSpeed() {
		return (ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.MAXSPEED);
	}
	
	
	/**
	 * Executes an instance of {@link ReadObjectVarQuery} relative to this query,
	 * and returns the corresponding value.
	 */
	public Double getMaxspeed() throws IOException {
		return ((ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.MAXSPEED)).get();
	}
	
	/**
	 * @return the instance of {@link ReadObjectVarQuery} relative to this query.
	 */
	public ReadObjectVarQuery<Double> queryReadMinGap() {
		return (ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.MINGAP);
	}
	
	
	/**
	 * Executes an instance of {@link ReadObjectVarQuery} relative to this query,
	 * and returns the corresponding value.
	 */
	public Double getMingap() throws IOException {
		return ((ReadObjectVarQuery.DoubleQ) getReadQuery(Variable.MINGAP)).get();
	}
	
	/**
	 * @return the instance of {@link ChangeAccelQuery} relative to this query.
	 */
	public ChangeAccelQuery queryChangeAccel() {
		return csqvar_ChangeAccel;
	}
	
	
	/**
	 * @return the instance of {@link ChangeDecelQuery} relative to this query.
	 */
	public ChangeDecelQuery queryChangeDecel() {
		return csqvar_ChangeDecel;
	}
	
	
	/**
	 * @return the instance of {@link ChangeMaxSpeedQuery} relative to this query.
	 */
	public ChangeMaxSpeedQuery queryChangeMaxSpeed() {
		return csqvar_ChangeMaxSpeed;
	}
	
	
	/**
	 * @return the instance of {@link ChangeMinGapQuery} relative to this query.
	 */
	public ChangeMinGapQuery queryChangeMinGap() {
		return csqvar_ChangeMinGap;
	}
	
	
}

