Skip to content

Commit 5a79403

Browse files
authored
Rename manager factories and add methods with builder functions (#13)
1 parent 0376467 commit 5a79403

4 files changed

Lines changed: 39 additions & 14 deletions

File tree

cloud-processors-confirmation/src/main/java/org/incendo/cloud/processors/confirmation/ConfirmationManager.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.time.Instant;
2828
import java.util.Objects;
2929
import java.util.Optional;
30+
import java.util.function.Function;
3031
import org.apiguardian.api.API;
3132
import org.checkerframework.checker.nullness.qual.NonNull;
3233
import org.incendo.cloud.Command;
@@ -60,10 +61,24 @@ public final class ConfirmationManager<C> implements Command.Builder.Applicable<
6061
* @param configuration configuration for the confirmation manager
6162
* @return the created manager
6263
*/
63-
public static <C> @NonNull ConfirmationManager<C> of(final @NonNull ConfirmationConfiguration<C> configuration) {
64+
public static <C> @NonNull ConfirmationManager<C> confirmationManager(final @NonNull ConfirmationConfiguration<C> configuration) {
6465
return new ConfirmationManager<>(Objects.requireNonNull(configuration, "configuration"));
6566
}
6667

68+
/**
69+
* Creates a new confirmation manager using the given {@code configuration}.
70+
*
71+
* @param <C> command sender type
72+
* @param configuration configuration for the confirmation manager
73+
* @return the created manager
74+
*/
75+
public static <C> @NonNull ConfirmationManager<C> confirmationManager(
76+
final @NonNull Function<ImmutableConfirmationConfiguration.@NonNull CacheBuildStage<C>,
77+
ImmutableConfirmationConfiguration.@NonNull BuildFinal<C>> configuration
78+
) {
79+
return confirmationManager(configuration.apply(ConfirmationConfiguration.builder()).build());
80+
}
81+
6782
private final CloudCache<C, ConfirmationContext<C>> cache;
6883
private final ConfirmationConfiguration<C> configuration;
6984

cloud-processors-confirmation/src/test/java/org/incendo/cloud/processors/confirmation/ConfirmationManagerTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ class ConfirmationManagerTest {
6363
@BeforeEach
6464
void setup() {
6565
this.commandManager = new TestCommandManager();
66-
this.confirmationManager = ConfirmationManager.of(
67-
ConfirmationConfiguration.<TestCommandSender>builder()
66+
this.confirmationManager = ConfirmationManager.confirmationManager(
67+
configBuilder -> configBuilder
6868
.cache(SimpleCache.of())
6969
.noPendingCommandNotifier(this.noPendingCommandNotifier)
7070
.confirmationRequiredNotifier(this.confirmationRequiredNotifier)
71-
.build()
7271
);
7372
this.commandManager.registerCommandPostProcessor(this.confirmationManager.createPostprocessor());
7473
}

cloud-processors-cooldown/src/main/java/org/incendo/cloud/processors/cooldown/CooldownManager.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import io.leangen.geantyref.TypeToken;
2727
import java.util.Objects;
28+
import java.util.function.Function;
2829
import org.apiguardian.api.API;
2930
import org.checkerframework.checker.nullness.qual.NonNull;
3031
import org.incendo.cloud.execution.postprocessor.CommandPostprocessor;
@@ -49,16 +50,30 @@ public final class CooldownManager<C> {
4950
);
5051

5152
/**
52-
* Creates a new confirmation manager using the given {@code configuration}.
53+
* Creates a new cooldown manager using the given {@code configuration}.
5354
*
5455
* @param <C> command sender type
55-
* @param configuration configuration for the confirmation manager
56+
* @param configuration configuration for the cooldown manager
5657
* @return the created manager
5758
*/
58-
public static <C> @NonNull CooldownManager<C> of(final @NonNull CooldownConfiguration<C> configuration) {
59+
public static <C> @NonNull CooldownManager<C> cooldownManager(final @NonNull CooldownConfiguration<C> configuration) {
5960
return new CooldownManager<>(Objects.requireNonNull(configuration, "configuration"));
6061
}
6162

63+
/**
64+
* Creates a new cooldown manager using the given {@code configuration}.
65+
*
66+
* @param <C> command sender type
67+
* @param configuration configuration for the cooldown manager
68+
* @return the created manager
69+
*/
70+
public static <C> @NonNull CooldownManager<C> cooldownManager(
71+
final @NonNull Function<ImmutableCooldownConfiguration.RepositoryBuildStage<C>,
72+
ImmutableCooldownConfiguration.BuildFinal<C>> configuration
73+
) {
74+
return cooldownManager(configuration.apply(CooldownConfiguration.builder()).build());
75+
}
76+
6277
private final CooldownRepository<C> repository;
6378
private final CooldownConfiguration<C> configuration;
6479

cloud-processors-cooldown/src/test/java/org/incendo/cloud/processors/confirmation/CooldownManagerTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.incendo.cloud.processors.confirmation.util.TestCommandManager;
3434
import org.incendo.cloud.processors.confirmation.util.TestCommandSender;
3535
import org.incendo.cloud.processors.cooldown.Cooldown;
36-
import org.incendo.cloud.processors.cooldown.CooldownConfiguration;
3736
import org.incendo.cloud.processors.cooldown.CooldownGroup;
3837
import org.incendo.cloud.processors.cooldown.CooldownInstance;
3938
import org.incendo.cloud.processors.cooldown.CooldownManager;
@@ -76,14 +75,11 @@ class CooldownManagerTest {
7675
@BeforeEach
7776
void setup() {
7877
this.commandManager = new TestCommandManager();
79-
this.cooldownManager = CooldownManager.of(
80-
CooldownConfiguration.<TestCommandSender>builder()
81-
.repository(CooldownRepository.forMap(new HashMap<>()))
78+
this.cooldownManager = CooldownManager.cooldownManager(configBuilder ->
79+
configBuilder.repository(CooldownRepository.forMap(new HashMap<>()))
8280
.addActiveCooldownListener(this.notifier)
8381
.clock(this.clock)
84-
.addCreationListener(this.listener)
85-
.build()
86-
);
82+
.addCreationListener(this.listener));
8783
this.commandManager.registerCommandPostProcessor(this.cooldownManager.createPostprocessor());
8884
}
8985

0 commit comments

Comments
 (0)