Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message indicating what is wrong with the supplied argument(s) #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/main/java/org/vibur/objectpool/ConcurrentPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ public ConcurrentPool(ConcurrentCollection<T> available, PoolObjectFactory<T> po
*/
public ConcurrentPool(ConcurrentCollection<T> available, PoolObjectFactory<T> poolObjectFactory,
int initialSize, int maxSize, boolean fair, Listener<T> listener) {
forbidIllegalArgument(initialSize < 0);
forbidIllegalArgument(maxSize < 1 || maxSize < initialSize || maxSize > MAX_ALLOWED_SIZE);
int availableSize = available.size();
forbidIllegalArgument(availableSize != 0 && availableSize != initialSize);
forbidIllegalArgument(initialSize < 0, String.format("Initial size %s should be >= 0", initialSize));
forbidIllegalArgument(maxSize < 1 || maxSize < initialSize || maxSize > MAX_ALLOWED_SIZE, String.format(
"maxSize %s should be between %s %s this is now not the case", maxSize, MAX_ALLOWED_SIZE, initialSize));
int availableSize = available.size();
forbidIllegalArgument(availableSize != 0 && availableSize != initialSize, String.format("availableSize == initialSize (%s != %s)", availableSize, initialSize));

this.available = requireNonNull(available);
this.poolObjectFactory = requireNonNull(poolObjectFactory);
Expand Down Expand Up @@ -396,7 +397,7 @@ public int maxSize() {

@Override
public int reduceCreatedBy(int reduceBy, boolean ignoreInitialSize) {
forbidIllegalArgument(reduceBy < 0);
forbidIllegalArgument(reduceBy < 0, String.format("reduceBy %s should be >= 0", reduceBy));

for (int cnt = 0; cnt < reduceBy; cnt++) {
if (!reduceByOne(ignoreInitialSize)) {
Expand All @@ -408,7 +409,7 @@ public int reduceCreatedBy(int reduceBy, boolean ignoreInitialSize) {

@Override
public int reduceCreatedTo(int reduceTo, boolean ignoreInitialSize) {
forbidIllegalArgument(reduceTo < 0);
forbidIllegalArgument(reduceTo < 0,String.format("reduceTo %s should be >= 0", reduceTo));

int cnt;
for (cnt = 0; createdTotal() > reduceTo; cnt++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public final class ArgumentValidation {

private ArgumentValidation() { }

public static void forbidIllegalArgument(boolean condition) {
public static void forbidIllegalArgument(boolean condition, String msg) {
if (condition) {
throw new IllegalArgumentException();
throw new IllegalArgumentException(msg);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public class SamplingPoolReducer implements ThreadedPoolReducer {
* {@code pool == null || unit == null}
*/
public SamplingPoolReducer(BasePool pool, long timeInterval, TimeUnit unit, int samples) {
forbidIllegalArgument(timeInterval <= 0);
forbidIllegalArgument(samples <= 0);
forbidIllegalArgument(timeInterval <= 0, String.format("timeInterval %s should be > 0", timeInterval));
forbidIllegalArgument(samples <= 0, String.format("samples %s should be > 0", samples));

this.sleepNanoTime = unit.toNanos(timeInterval) / samples;
forbidIllegalArgument(sleepNanoTime == 0);
forbidIllegalArgument(sleepNanoTime == 0, String.format("sleepNanoTime %s should be > 0", sleepNanoTime));

this.pool = requireNonNull(pool);
this.samples = samples;
Expand Down