Class TimeConstrained
java.lang.Object
ubc.team09.search.TimeConstrained
- Direct Known Subclasses:
AlphaBeta
This class should be extended if you want to impose a time constraint on
some process. To use it,
- use
setTimeLimit(int)to set the time limit. - use
startTimer()to start the countdown. - whenever you need to check the time limit, use
checkTimeOccasionally()orcheckTime(). Either of these methods will throw an exception if the time limit is expired. The former will only actually check the time once every ~1000 calls.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidThrows aTimeoutExceptionif the timer is expired.protected voidOnce every ~1000 calls, this function will check the time and throw aTimeoutExceptionif the timer is expired.voidsetTimeLimit(int seconds) Sets a time constraint on the process.voidsetTimeLimitMs(long milliseconds) Sets a time constraint on the process.protected voidBegins the timer.
-
Constructor Details
-
TimeConstrained
public TimeConstrained()
-
-
Method Details
-
setTimeLimit
public void setTimeLimit(int seconds) Sets a time constraint on the process. -
setTimeLimitMs
public void setTimeLimitMs(long milliseconds) Sets a time constraint on the process. -
startTimer
protected void startTimer()Begins the timer. -
checkTime
Throws aTimeoutExceptionif the timer is expired.- Throws:
TimeoutException
-
checkTimeOccasionally
Once every ~1000 calls, this function will check the time and throw aTimeoutExceptionif the timer is expired.- Throws:
TimeoutException
-