Skip to content
Merged
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
1 change: 1 addition & 0 deletions .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@

<!-- https://checkstyle.org/config_imports.html#IllegalImport -->
<module name="IllegalImport">
<property name="illegalClasses" value="org.jetbrains.annotations.Nullable, org.jetbrains.annotations.NotNull"/>
<property name="illegalPkgs" value="sun, jdk, com.sun"/>
</module>

Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {

dependencies {
compileOnlyApi(libs.jetbrainsAnnotations)
compileOnlyApi(libs.jspecify)
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.api)
testRuntimeOnly(libs.junit.engine)
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ junit = "5.11.4"

[libraries]
jetbrainsAnnotations = "org.jetbrains:annotations:26.0.2"
jspecify = { module = "org.jspecify:jspecify", version = "1.0.0"}
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
junit-api = { module = "org.junit.jupiter:junit-jupiter-api" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine" }
Expand All @@ -24,4 +25,4 @@ indra-crossdoc = { id = "net.kyori.indra.crossdoc", version.ref = "indra" }
indra-licenser-spotless = { id = "net.kyori.indra.licenser.spotless", version.ref = "indra" }
indra-publishing-sonatype = { id = "net.kyori.indra.publishing.sonatype", version.ref = "indra" }
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0" }
spotless = "com.diffplug.spotless:7.0.2"
spotless = "com.diffplug.spotless:7.0.2"
9 changes: 4 additions & 5 deletions src/main/java/net/kyori/option/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

import net.kyori.option.value.ValueType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

/**
* A representation of a configurable option.
Expand Down Expand Up @@ -80,7 +79,7 @@ static <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E>
* @return the flag id
* @since 1.0.0
*/
@NotNull String id();
String id();

/**
* Get the type of the option value.
Expand All @@ -90,7 +89,7 @@ static <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E>
* @deprecated for removal since 1.1.0, use {@link #valueType()} instead
*/
@Deprecated
default @NotNull Class<V> type() {
default Class<V> type() {
return this.valueType().type();
}

Expand All @@ -100,7 +99,7 @@ static <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E>
* @return the value type
* @since 1.0.0
*/
@NotNull ValueType<V> valueType();
ValueType<V> valueType();

/**
* Get a default value for the option, if any is present.
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/net/kyori/option/OptionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,27 @@

import java.util.Objects;
import net.kyori.option.value.ValueType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

final class OptionImpl<V> implements Option<V> {

private final String id;
private final ValueType<V> type;
private final @Nullable V defaultValue; // excluded from equality comparisons, it does not form part of the option identity

OptionImpl(final @NotNull String id, final @NotNull ValueType<V> type, final @Nullable V defaultValue) {
OptionImpl(final String id, final ValueType<V> type, final @Nullable V defaultValue) {
this.id = id;
this.type = type;
this.defaultValue = defaultValue;
}

@Override
public @NotNull String id() {
public String id() {
return this.id;
}

@Override
public @NotNull ValueType<V> valueType() {
public ValueType<V> valueType() {
return this.type;
}

Expand Down
29 changes: 14 additions & 15 deletions src/main/java/net/kyori/option/OptionSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

import java.util.Set;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

import static java.util.Objects.requireNonNull;

Expand All @@ -45,7 +44,7 @@ public interface OptionSchema {
* @return the global schema
* @since 1.1.0
*/
static OptionSchema.@NotNull Mutable globalSchema() {
static OptionSchema.Mutable globalSchema() {
return OptionSchemaImpl.Instances.GLOBAL;
}

Expand All @@ -58,7 +57,7 @@ public interface OptionSchema {
* @return the mutable child schema
* @since 1.1.0
*/
static OptionSchema.@NotNull Mutable childSchema(final @NotNull OptionSchema schema) {
static OptionSchema.Mutable childSchema(final OptionSchema schema) {
final OptionSchemaImpl impl;
if (schema instanceof OptionSchemaImpl.MutableImpl) {
impl = (OptionSchemaImpl) ((Mutable) schema).frozenView();
Expand All @@ -76,7 +75,7 @@ public interface OptionSchema {
* @return a mutable schema
* @since 1.1.0
*/
static OptionSchema.@NotNull Mutable emptySchema() {
static OptionSchema.Mutable emptySchema() {
return new OptionSchemaImpl(null).new MutableImpl();
}

Expand All @@ -86,7 +85,7 @@ public interface OptionSchema {
* @return known options
* @since 1.1.0
*/
@NotNull Set<Option<?>> knownOptions();
Set<Option<?>> knownOptions();

/**
* Return whether the provided option is known within this scheam.
Expand All @@ -95,23 +94,23 @@ public interface OptionSchema {
* @return whether the option is known
* @since 1.1.0
*/
boolean has(final @NotNull Option<?> option);
boolean has(final Option<?> option);

/**
* Create a builder for an unversioned option state containing only options within this schema.
*
* @return the builder
* @since 1.1.0
*/
OptionState.@NotNull Builder stateBuilder();
OptionState.Builder stateBuilder();

/**
* Create a builder for a versioned option state containing only values for options within this schema.
*
* @return the builder
* @since 1.1.0
*/
OptionState.@NotNull VersionedBuilder versionedStateBuilder();
OptionState.VersionedBuilder versionedStateBuilder();

/**
* Create an empty option state within this schema.
Expand All @@ -138,7 +137,7 @@ interface Mutable extends OptionSchema {
* @return the flag instance
* @since 1.1.0
*/
@NotNull Option<String> stringOption(final @NotNull String id, final @Nullable String defaultValue);
Option<String> stringOption(final String id, final @Nullable String defaultValue);

/**
* Create an option with a boolean value type.
Expand All @@ -150,7 +149,7 @@ interface Mutable extends OptionSchema {
* @return the flag instance
* @since 1.1.0
*/
@NotNull Option<Boolean> booleanOption(final @NotNull String id, final boolean defaultValue);
Option<Boolean> booleanOption(final String id, final boolean defaultValue);

/**
* Create an option with an integer value type.
Expand All @@ -162,7 +161,7 @@ interface Mutable extends OptionSchema {
* @return the flag instance
* @since 1.1.0
*/
@NotNull Option<Integer> intOption(final @NotNull String id, final int defaultValue);
Option<Integer> intOption(final String id, final int defaultValue);

/**
* Create an option with a double value type.
Expand All @@ -174,7 +173,7 @@ interface Mutable extends OptionSchema {
* @return the flag instance
* @since 1.1.0
*/
@NotNull Option<Double> doubleOption(final @NotNull String id, final double defaultValue);
Option<Double> doubleOption(final String id, final double defaultValue);

/**
* Create an option with an enum value type.
Expand All @@ -188,7 +187,7 @@ interface Mutable extends OptionSchema {
* @return the flag instance
* @since 1.1.0
*/
<E extends Enum<E>> @NotNull Option<E> enumOption(final @NotNull String id, final @NotNull Class<E> enumClazz, final @Nullable E defaultValue);
<E extends Enum<E>> Option<E> enumOption(final String id, final Class<E> enumClazz, final @Nullable E defaultValue);

/**
* Return a view of this schema which does not allow consumers to register new options.
Expand All @@ -198,6 +197,6 @@ interface Mutable extends OptionSchema {
* @return the frozen view of this schema
* @since 1.1.0
*/
@NotNull OptionSchema frozenView();
OptionSchema frozenView();
}
}
31 changes: 15 additions & 16 deletions src/main/java/net/kyori/option/OptionSchemaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import net.kyori.option.value.ValueType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jspecify.annotations.Nullable;

import static java.util.Objects.requireNonNull;

Expand All @@ -47,23 +46,23 @@ final class OptionSchemaImpl implements OptionSchema {
}

@Override
public @NotNull Set<Option<?>> knownOptions() {
public Set<Option<?>> knownOptions() {
return Collections.unmodifiableSet(new HashSet<>(this.options.values()));
}

@Override
public boolean has(final @NotNull Option<?> option) {
public boolean has(final Option<?> option) {
final Option<?> own = this.options.get(option.id());
return own != null && own.equals(option);
}

@Override
public OptionState.@NotNull Builder stateBuilder() {
public OptionState.Builder stateBuilder() {
return new OptionStateImpl.BuilderImpl(this);
}

@Override
public OptionState.@NotNull VersionedBuilder versionedStateBuilder() {
public OptionState.VersionedBuilder versionedStateBuilder() {
return new OptionStateImpl.VersionedBuilderImpl(this);
}

Expand Down Expand Up @@ -99,54 +98,54 @@ <T> Option<T> register(final String id, final ValueType<T> type, final @Nullable
}

@Override
public @NotNull Option<String> stringOption(final @NotNull String id, final @Nullable String defaultValue) {
public Option<String> stringOption(final String id, final @Nullable String defaultValue) {
return this.register(id, ValueType.stringType(), defaultValue);
}

@Override
public @NotNull Option<Boolean> booleanOption(final @NotNull String id, final boolean defaultValue) {
public Option<Boolean> booleanOption(final String id, final boolean defaultValue) {
return this.register(id, ValueType.booleanType(), defaultValue);
}

@Override
public @NotNull Option<Integer> intOption(final @NotNull String id, final int defaultValue) {
public Option<Integer> intOption(final String id, final int defaultValue) {
return this.register(id, ValueType.integerType(), defaultValue);
}

@Override
public @NotNull Option<Double> doubleOption(final @NotNull String id, final double defaultValue) {
public Option<Double> doubleOption(final String id, final double defaultValue) {
return this.register(id, ValueType.doubleType(), defaultValue);
}

@Override
public @NotNull <E extends Enum<E>> Option<E> enumOption(final @NotNull String id, final @NotNull Class<E> enumClazz, final @Nullable E defaultValue) {
public <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E> enumClazz, final @Nullable E defaultValue) {
return this.register(id, ValueType.enumType(enumClazz), defaultValue);
}

@Override
public @NotNull OptionSchema frozenView() {
public OptionSchema frozenView() {
return OptionSchemaImpl.this;
}

// base scheam methods

@Override
public @NotNull Set<Option<?>> knownOptions() {
public Set<Option<?>> knownOptions() {
return OptionSchemaImpl.this.knownOptions();
}

@Override
public boolean has(final @NotNull Option<?> option) {
public boolean has(final Option<?> option) {
return OptionSchemaImpl.this.has(option);
}

@Override
public OptionState.@NotNull Builder stateBuilder() {
public OptionState.Builder stateBuilder() {
return OptionSchemaImpl.this.stateBuilder();
}

@Override
public OptionState.@NotNull VersionedBuilder versionedStateBuilder() {
public OptionState.VersionedBuilder versionedStateBuilder() {
return OptionSchemaImpl.this.versionedStateBuilder();
}

Expand Down
Loading