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:
Duncan Jones 2014-05-10 05:58:17 +00:00
parent 10641f9ae7
commit a2c356d7a6
2 changed files with 9 additions and 9 deletions

View File

@ -21,6 +21,8 @@
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.Validate;
/** /**
* <p> * <p>
* An utility class providing functionality related to the {@code * An utility class providing functionality related to the {@code
@ -141,12 +143,10 @@ public static void handleCauseUnchecked(final ExecutionException ex) {
* checked exception * checked exception
*/ */
static Throwable checkedException(final Throwable ex) { static Throwable checkedException(final Throwable ex) {
if (ex != null && !(ex instanceof RuntimeException) Validate.isTrue(ex != null && !(ex instanceof RuntimeException)
&& !(ex instanceof Error)) { && !(ex instanceof Error), "Not a checked exception: " + ex);
return ex;
} else { return ex;
throw new IllegalArgumentException("Not a checked exception: " + ex);
}
} }
/** /**

View File

@ -21,6 +21,8 @@
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.Validate;
/** /**
* <p> * <p>
* A specialized <em>semaphore</em> implementation that provides a number of * A specialized <em>semaphore</em> implementation that provides a number of
@ -201,9 +203,7 @@ public TimedSemaphore(final long timePeriod, final TimeUnit timeUnit, final int
*/ */
public TimedSemaphore(final ScheduledExecutorService service, final long timePeriod, public TimedSemaphore(final ScheduledExecutorService service, final long timePeriod,
final TimeUnit timeUnit, final int limit) { final TimeUnit timeUnit, final int limit) {
if (timePeriod <= 0) { Validate.inclusiveBetween(1, Long.MAX_VALUE, timePeriod, "Time period must be greater than 0!");
throw new IllegalArgumentException("Time period must be greater 0!");
}
period = timePeriod; period = timePeriod;
unit = timeUnit; unit = timeUnit;