-
Notifications
You must be signed in to change notification settings - Fork 235
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
Configurable temporal unit in DurationRandomizer #370
Configurable temporal unit in DurationRandomizer #370
Conversation
3c09376
to
83e6412
Compare
Hi @lutovich, Thank you for opening this PR! I like the idea, but I would implement it differently. What about making the The changes to Do you agree? Kr, |
Hi @benas, Thanks for your response! The change in Thus I feel like this PR does not add much new functionality to the What do you think? Making |
Oh my bad, sorry for that.
Great, in that case, please update the PR accordingly and it will be good to merge. We would need a new constructor Do not hesitate to add your name to the contributors list as well, you deserve the credit! |
83e6412
to
3378cf1
Compare
This change makes it possible to create a DurationRandomizer that generates durations of the specified TemporalUnit. When not configured, the default unit is hours.
3378cf1
to
f50b903
Compare
@benas PR is now updated. Thank you! |
Thanks for the updates. However, I thought we agreed on passing By making the Index: easy-random-core/src/main/java/org/jeasy/random/randomizers/time/DurationRandomizer.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- easy-random-core/src/main/java/org/jeasy/random/randomizers/time/DurationRandomizer.java (revision a7ea389b71671760d63d7a9568082881d16aa9be)
+++ easy-random-core/src/main/java/org/jeasy/random/randomizers/time/DurationRandomizer.java (date 1572644643611)
@@ -40,6 +40,7 @@
private static final int MAX_AMOUNT = 100;
private final IntegerRangeRandomizer amountRandomizer;
+ private ChronoUnit chronoUnit = ChronoUnit.HOURS;
/**
* Create a new {@link DurationRandomizer}.
@@ -56,6 +57,17 @@
public DurationRandomizer(final long seed) {
amountRandomizer = new IntegerRangeRandomizer(MIN_AMOUNT, MAX_AMOUNT, seed);
}
+
+ /**
+ * Create a new {@link DurationRandomizer}.
+ *
+ * @param seed initial seed
+ * @param chronoUnit unit of the random duration
+ */
+ public DurationRandomizer(final long seed, final ChronoUnit chronoUnit) {
+ amountRandomizer = new IntegerRangeRandomizer(MIN_AMOUNT, MAX_AMOUNT, seed);
+ this.chronoUnit = chronoUnit;
+ }
/**
* Create a new {@link DurationRandomizer}.
@@ -76,10 +88,21 @@
return new DurationRandomizer(seed);
}
+ /**
+ * Create a new {@link DurationRandomizer}.
+ *
+ * @param seed initial seed
+ * @param chronoUnit unit of the random duration
+ * @return a new {@link DurationRandomizer}.
+ */
+ public static DurationRandomizer aNewDurationRandomizer(final long seed, final ChronoUnit chronoUnit) {
+ return new DurationRandomizer(seed, chronoUnit);
+ }
+
@Override
public Duration getRandomValue() {
int randomAmount = amountRandomizer.getRandomValue();
- return Duration.of(randomAmount, ChronoUnit.HOURS);
+ return Duration.of(randomAmount, this.chronoUnit);
}
}
|
@benas Method
Condition |
I did not notice that. In that case, we should definitely use The PR LGTM, I will merge it. Thank you for your contribution! |
This change makes it possible to create a
DurationRandomizer
that generates durations of the specifiedTemporalUnit
. When not configured, the default unit is hours.