Java Reference
In-Depth Information
if
(! working && nutBuffer.size() > 0 &&
screwBuffer.size() > 0) {
working
#
true
;
nutBuffer.remove(0);
screwBuffer.remove(0);
// the WORKDONE event will notify the completion of
// this operation
long
processingTime
#
Math.round( (1.0
!
0.5 * Math.random()) / maxRate);
this.activateEvent("WORKDONE", processingTime,
null
);
}
}
else if
(event.name.equals("WORKDONE")) {
// the current operation has been completed
// it drops the bolt in the output buffer
boltBuffer.add(event);
if
(outputEmpty && boltBuffer.size() > 2) {
// the output buffer is not empty
outputEmpty
#
false
;
activateEvent("NOTEMPTY", 0,
null
);
}
if
(nutBuffer.size() > 0 && screwBuffer.size() > 0) {
// if the input buffer is not empty the machine
// starts a new operation
working
#
true
;
nutBuffer.remove(0);
screwBuffer.remove(0);
long
processingTime
#
Math.round( (1.0
!
0.5 * Math.random()) / maxRate);
this
.activateEvent("WORKDONE", processingTime,
null
);
}
else
// one of the input buffers is empty
working
#
false
;
}
else if
(event.name.equals("UNLOADED")) {
// a bolt has been unloaded from the output buffer
boltBuffer.remove(0);
if
(boltBuffer.size() <
#
1) {
// the output buffer is empty
outputEmpty
#
true
;
activateEvent("EMPTY", 0,
null
);
}
}
}
}