Using Validate where possible in concurrent package.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1593668 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
10641f9ae7
commit
a2c356d7a6
|
@ -21,6 +21,8 @@ import java.util.concurrent.ExecutionException;
|
|||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* An utility class providing functionality related to the {@code
|
||||
|
@ -141,12 +143,10 @@ public class ConcurrentUtils {
|
|||
* checked exception
|
||||
*/
|
||||
static Throwable checkedException(final Throwable ex) {
|
||||
if (ex != null && !(ex instanceof RuntimeException)
|
||||
&& !(ex instanceof Error)) {
|
||||
return ex;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Not a checked exception: " + ex);
|
||||
}
|
||||
Validate.isTrue(ex != null && !(ex instanceof RuntimeException)
|
||||
&& !(ex instanceof Error), "Not a checked exception: " + ex);
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A specialized <em>semaphore</em> implementation that provides a number of
|
||||
|
@ -201,9 +203,7 @@ public class TimedSemaphore {
|
|||
*/
|
||||
public TimedSemaphore(final ScheduledExecutorService service, final long timePeriod,
|
||||
final TimeUnit timeUnit, final int limit) {
|
||||
if (timePeriod <= 0) {
|
||||
throw new IllegalArgumentException("Time period must be greater 0!");
|
||||
}
|
||||
Validate.inclusiveBetween(1, Long.MAX_VALUE, timePeriod, "Time period must be greater than 0!");
|
||||
|
||||
period = timePeriod;
|
||||
unit = timeUnit;
|
||||
|
|
Loading…
Reference in New Issue