Skip to content

Commit

Permalink
Remove NotNull spam from Requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
MattSturgeon committed Jul 3, 2023
1 parent 27190a9 commit 85d1cdb
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.shedaniel.clothconfig2.api;

import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
Expand Down Expand Up @@ -30,7 +29,7 @@ public interface Requirement {
* Generates a {@link Requirement} that is true when {@code dependency}'s value is one of the provided values.
*/
@SafeVarargs
static <T> @NotNull Requirement isValue(@NotNull ValueHolder<T> dependency, @Nullable T firstValue, @Nullable T... otherValues) {
static <T> Requirement isValue(ValueHolder<T> dependency, @Nullable T firstValue, @Nullable T... otherValues) {
Set<@Nullable T> values = Stream.concat(Stream.of(firstValue), Arrays.stream(otherValues))
.collect(Collectors.toCollection(HashSet::new));

Expand All @@ -40,56 +39,56 @@ public interface Requirement {
/**
* Generates a {@link Requirement} that is true when {@code firstDependency}'s value equals {@code secondDependency}'s value.
*/
static @NotNull <T> Requirement matches(@NotNull ValueHolder<T> firstDependency, @NotNull ValueHolder<T> secondDependency) {
static <T> Requirement matches(ValueHolder<T> firstDependency, ValueHolder<T> secondDependency) {
return () -> Objects.equals(firstDependency.getValue(), secondDependency.getValue());
}

/**
* Generates a {@link Requirement} that is true when {@code dependency}'s value is true.
*/
static @NotNull Requirement isTrue(@NotNull ValueHolder<Boolean> dependency) {
static Requirement isTrue(ValueHolder<Boolean> dependency) {
return () -> Boolean.TRUE.equals(dependency.getValue());
}

/**
* Generates a {@link Requirement} that is true when {@code dependency}'s value is false.
*/
static @NotNull Requirement isFalse(@NotNull ValueHolder<Boolean> dependency) {
static Requirement isFalse(ValueHolder<Boolean> dependency) {
return () -> Boolean.FALSE.equals(dependency.getValue());
}

/**
* Generates a {@link Requirement} that is true when the given {@code requirement} is false.
*/
static Requirement not(@NotNull Requirement requirement) {
static Requirement not(Requirement requirement) {
return () -> !requirement.check();
}

/**
* Generates a {@link Requirement} that is true when all the given requirements are true.
*/
static @NotNull Requirement all(@NotNull Requirement... requirements) {
static Requirement all(Requirement... requirements) {
return () -> Arrays.stream(requirements).allMatch(Requirement::check);
}

/**
* Generates a {@link Requirement} that is true when any of the given requirements are true.
*/
static @NotNull Requirement any(@NotNull Requirement... requirements) {
static Requirement any(Requirement... requirements) {
return () -> Arrays.stream(requirements).anyMatch(Requirement::check);
}

/**
* Generates a {@link Requirement} that is true when none of the given requirements are true, i.e. all are false.
*/
static @NotNull Requirement none(Requirement... requirements) {
static Requirement none(Requirement... requirements) {
return () -> Arrays.stream(requirements).noneMatch(Requirement::check);
}

/**
* Generates a {@link Requirement} that is true when precisely one of the given requirements is true.
*/
static @NotNull Requirement one(Requirement... requirements) {
static Requirement one(Requirement... requirements) {
return () -> {
// Use a for loop instead of Stream.count() so that we can return early. We only need to count past 1.
boolean oneFound = false;
Expand Down

0 comments on commit 85d1cdb

Please sign in to comment.