Skip to content

Commit

Permalink
chore: update README and add non-null requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Citymonstret committed Jan 17, 2024
1 parent e7fa9d9 commit f3d90b1
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.incendo.cloud.processors.cache;

import com.github.benmanes.caffeine.cache.Cache;
import java.util.Objects;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -53,21 +54,25 @@ public final class CaffeineCache<K, V> implements CloudCache<K, V> {
private final Cache<K, V> cache;

private CaffeineCache(final @NonNull Cache<K, V> cache) {
this.cache = cache;
this.cache = Objects.requireNonNull(cache, "cache");
}

@Override
public void delete(final @NonNull K key) {
Objects.requireNonNull(key, "key");
this.cache.invalidate(key);
}

@Override
public void put(final @NonNull K key, final @NonNull V value) {
Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
this.cache.put(key, value);
}

@Override
public @Nullable V getIfPresent(final @NonNull K key) {
Objects.requireNonNull(key, "key");
return this.cache.getIfPresent(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ private GuavaCache(final @NonNull Cache<K, V> cache) {

@Override
public void delete(final @NonNull K key) {
Objects.requireNonNull(key, "key");
this.cache.invalidate(key);
}

@Override
public void put(final @NonNull K key, final @NonNull V value) {
Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
this.cache.put(key, value);
}

@Override
public @Nullable V getIfPresent(final @NonNull K key) {
Objects.requireNonNull(key, "key");
return this.cache.getIfPresent(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.incendo.cloud.processors.cache;

import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand Down Expand Up @@ -58,21 +59,26 @@ public final class SimpleCache<K, V> implements CloudCache<K, V> {

@Override
public void delete(final @NonNull K key) {
Objects.requireNonNull(key, "key");
this.map.remove(key);
}

@Override
public void put(final @NonNull K key, final @NonNull V value) {
Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
this.map.put(key, value);
}

@Override
public @Nullable V getIfPresent(final @NonNull K key) {
Objects.requireNonNull(key, "key");
return this.map.get(key);
}

@Override
public @Nullable V popIfPresent(final @NonNull K key) {
Objects.requireNonNull(key, "key");
return this.map.remove(key);
}
}
15 changes: 14 additions & 1 deletion cloud-processors-confirmation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ Postprocessor that adds the ability to require an extra confirmation before exec

## Installation

cloud-processors-confirmation is not yet available on Maven Central.
Snapshots are available on the Sonatype Snapshots Repository:

```xml
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

<dependency>
<groupId>org.incendo</groupId>
<artifactId>cloud-processors-confirmation</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
```

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import cloud.commandframework.context.CommandContext;
import cloud.commandframework.execution.CommandExecutionHandler;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.apiguardian.api.API;
Expand All @@ -42,7 +43,7 @@ final class ConfirmationExecutionHandler<C> implements CommandExecutionHandler.F
private final ConfirmationManager<C> confirmationManager;

ConfirmationExecutionHandler(final @NonNull ConfirmationManager<C> confirmationManager) {
this.confirmationManager = confirmationManager;
this.confirmationManager = Objects.requireNonNull(confirmationManager, "confirmationManager");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public final class ConfirmationManager<C> implements Command.Builder.Applicable<
private final ConfirmationConfiguration<C> configuration;

private ConfirmationManager(final @NonNull ConfirmationConfiguration<C> configuration) {
this.cache = configuration.cache();
this.configuration = configuration;
this.cache = Objects.requireNonNull(configuration.cache(), "cache");
this.configuration = Objects.requireNonNull(configuration, "configuration");
}

/**
Expand Down Expand Up @@ -119,6 +119,8 @@ private ConfirmationManager(final @NonNull ConfirmationConfiguration<C> configur
* @return optional containing the value if it exists and has not yet expired
*/
public @NonNull Optional<ConfirmationContext<C>> popPending(final @NonNull C sender) {
Objects.requireNonNull(sender, "sender");

final ConfirmationContext<C> context = this.cache.popIfPresent(sender);
if (context == null) {
return Optional.empty();
Expand All @@ -142,6 +144,8 @@ private ConfirmationManager(final @NonNull ConfirmationConfiguration<C> configur
* @param context confirmation context
*/
void addPending(final @NonNull C sender, final @NonNull ConfirmationContext<C> context) {
Objects.requireNonNull(sender, "sender");
Objects.requireNonNull(context, "context");
this.cache.put(sender, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import cloud.commandframework.execution.postprocessor.CommandPostprocessor;
import cloud.commandframework.services.types.ConsumerService;
import java.time.Instant;
import java.util.Objects;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;

Expand All @@ -42,7 +43,7 @@ final class ConfirmationPostprocessor<C> implements CommandPostprocessor<C> {
private final ConfirmationManager<C> confirmationManager;

ConfirmationPostprocessor(final @NonNull ConfirmationManager<C> confirmationManager) {
this.confirmationManager = confirmationManager;
this.confirmationManager = Objects.requireNonNull(confirmationManager, "confirmationManager");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import cloud.commandframework.Command;
import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.annotations.BuilderModifier;
import java.util.Objects;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.processors.confirmation.ConfirmationManager;
Expand Down Expand Up @@ -58,6 +59,7 @@ public final class ConfirmationBuilderModifier<C> implements BuilderModifier<Con
* @param annotationParser annotation parser to add the builder modifier to
*/
public static <C> void install(final @NonNull AnnotationParser<C> annotationParser) {
Objects.requireNonNull(annotationParser, "annotationParser");
annotationParser.registerBuilderModifier(Confirmation.class, of());
}

Expand Down
15 changes: 14 additions & 1 deletion cloud-processors-cooldown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ Postprocessor that adds command cooldowns.

## Installation

cloud-processors-cooldown is not yet available on Maven Central.
Snapshots are available on the Sonatype Snapshots Repository:

```xml
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

<dependency>
<groupId>org.incendo</groupId>
<artifactId>cloud-processors-cooldown</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
```

## Usage

Expand Down
15 changes: 14 additions & 1 deletion cloud-processors-requirements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,20 @@ are defined on a per-command basis.

## Installation

Cloud Requirements is not yet available on Maven Central.
Snapshots are available on the Sonatype Snapshots Repository:

```xml
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

<dependency>
<groupId>org.incendo</groupId>
<artifactId>cloud-processors-requirements</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
```

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ private RequirementApplicableFactory(final @NonNull CloudKey<Requirements<C, R>>
* @return the {@link RequirementApplicable} instance
*/
public @NonNull RequirementApplicable<C, R> create(final @NonNull Requirements<C, R> requirements) {
Objects.requireNonNull(requirements, "requirements");
return new RequirementApplicable<>(this.requirementKey, requirements);
}

Expand All @@ -108,6 +109,7 @@ private RequirementApplicableFactory(final @NonNull CloudKey<Requirements<C, R>>
* @return the {@link RequirementApplicable} instance
*/
public @NonNull RequirementApplicable<C, R> create(final @NonNull List<@NonNull R> requirements) {
Objects.requireNonNull(requirements, "requirements");
return new RequirementApplicable<>(this.requirementKey, Requirements.of(requirements));
}

Expand All @@ -120,6 +122,7 @@ private RequirementApplicableFactory(final @NonNull CloudKey<Requirements<C, R>>
@SafeVarargs
@SuppressWarnings("varargs")
public final @NonNull RequirementApplicable<C, R> create(final @NonNull R @NonNull... requirements) {
Objects.requireNonNull(requirements, "requirements");
return new RequirementApplicable<>(this.requirementKey, Requirements.of(requirements));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ final class RequirementBindingsImpl<C, R extends Requirement<C, R>> implements R
final @NonNull Class<A> annotation,
final @NonNull Function<A, R> requirement
) {
Objects.requireNonNull(annotation, "annotation");
Objects.requireNonNull(requirement, "requirement");
this.annotationParser.registerBuilderModifier(annotation, new RequirementBuilderModifier<>(requirement));
return this;
}
Expand Down

0 comments on commit f3d90b1

Please sign in to comment.