private void sendTask() { // Did we finish all the tasks for the state change? if (tasksDue.size() == 0) { // Mark the completion of the state change onOffEvent = null; setState(newState); return; } // No we did not, lets send some more to our direct consumer final double totalConsumption = tasksDue.removeAt(0); final double limit = tasksDue.removeAt(0); currentConsumption = new ResourceConsumption( totalConsumption, limit, directConsumer, PhysicalMachine.this, this); if (!currentConsumption.registerConsumption()) { throw new IllegalStateException( "PowerStateChange was not successful because resource consumption could not be registered"); } }