
import de.simflex.simulator.scheduler.Event;
import de.simflex.units.DefaultMachine;
import de.simflex.units.PermanentUnit;
import de.simflex.units.TemporaryUnit;

public class MachineWithShelf extends DefaultMachine {

    public MachineWithShelf( ){
        super( );
    }

    protected void receive( ){
        if( ! occupied ){
            occupied = true;
            addTemporaryUnit( (TemporaryUnit)((PermanentUnit)incomingBuffer.removeTop( ) ).release( ));
            temporaryUnit.setStatus( this , TemporaryUnit.BE_RECEIVED );
            scheduler.setRelativeEvent( new Event( 0 , this , PermanentUnit.WORK_BEGIN ) );
            decrementAvis( );
        }
    }

    public PermanentUnit whereToGo( PermanentUnit pu ){
        if( isChild( pu ) ) return this;
        if( occupied ) return ((PermanentUnit)childs.get( 0 )).whereToGo( pu );
        else return this;
    }
}