mercredi 28 octobre 2015

Only return Object if if-condition is fulfilled, else no return is needed

In the following code a Packet (Object) should be returned wen its servingtime is 0. Else, the servingtime should be reduced by 1. The problem is that in this case nothing should be returned. Can I somehow implement this, or is this impossible ?

public Packet Serve()
    {
        if(timeServing == 0)
        {
          Packet p = queue.dequeue();
          timeServing = distrServ.getSample();
        }
        else
        {
            --timeServing;
        }
        return p;
    }

Aucun commentaire:

Enregistrer un commentaire