Skip to content

Commit

Permalink
feature-flag -> option
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Dec 17, 2023
1 parent f6faa2c commit f1bea25
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 143 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# feature-flag
# option

![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/KyoriPowered/feature-flag/build.yml?branch=trunk) [![MIT License](https://img.shields.io/badge/license-MIT-blue)](license.txt) [![Maven Central](https://img.shields.io/maven-central/v/net.kyori/feature-flag?label=stable)](https://search.maven.org/search?q=g:net.kyori%20AND%20a:feature-flag) ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.kyori/feature-flag?label=dev&server=https%3A%2F%2Fs01.oss.sonatype.org) [![Javadoc](https://img.shields.io/badge/javadoc-all-green)](https://jd.advntr.dev/)
![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/KyoriPowered/option/build.yml?branch=trunk) [![MIT License](https://img.shields.io/badge/license-MIT-blue)](license.txt) [![Maven Central](https://img.shields.io/maven-central/v/net.kyori/option?label=stable)](https://search.maven.org/search?q=g:net.kyori%20AND%20a:option) ![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.kyori/option?label=dev&server=https%3A%2F%2Fs01.oss.sonatype.org) [![Javadoc](https://img.shields.io/badge/javadoc-all-green)](https://jd.advntr.dev/)

A small library for handling version-based feature configuration.

Expand All @@ -10,6 +10,6 @@ We appreciate contributions of any type. For any new features or typo-fix/style

All the adventure projects are built with Gradle, require at least JDK 8, and use a common checkstyle configuration. Please make sure all tests pass, license headers are updated, and checkstyle passes to help us review your contribution.

`feature-flag` is released under the terms of the [MIT License](license.txt).
`option` is released under the terms of the [MIT License](license.txt).

[Discord]: https://discord.gg/MMfhJ8F
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sourceSets {
main {
multirelease {
alternateVersions(9)
moduleName("net.kyori.featureflag")
moduleName("net.kyori.option")
requireAllPackagesExported()
}
}
Expand All @@ -42,7 +42,7 @@ indraSonatype {
}

indra {
github("KyoriPowered", "feature-flag") {
github("KyoriPowered", "option") {
ci(true)
}
mitLicense()
Expand All @@ -56,7 +56,7 @@ indra {
signWithKeyFromPrefixedProperties("kyori")
configurePublications {
pom {
url = "https://feature-flag.kyori.net"
url = "https://option.kyori.net"
developers {
developer {
id = "kashike"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
group=net.kyori
version=1.0.0-SNAPSHOT
description=A small library for handling version-based feature configuration
description=A small library for handling version-based option configuration

javadocPublishRoot=https://jd.advntr.dev/

Expand Down
2 changes: 1 addition & 1 deletion license_header.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This file is part of feature-flag, licensed under the MIT License.
This file is part of option, licensed under the MIT License.

Copyright (c) $YEAR KyoriPowered

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ dependencyResolutionManagement {
}
}

rootProject.name = "feature-flag"
rootProject.name = "option"
4 changes: 0 additions & 4 deletions src/main/java/net/kyori/featureflag/package-info.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of feature-flag, licensed under the MIT License.
* This file is part of option, licensed under the MIT License.
*
* Copyright (c) 2023 KyoriPowered
*
Expand All @@ -21,25 +21,25 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.featureflag;
package net.kyori.option;

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

/**
* A representation of a feature that can be toggled to one of several values.
* A representation of a configurable option.
*
* <p>Keys must be unique among all feature flag instances.</p>
*
* @param <V> the value type
* @since 1.0.0
*/
@ApiStatus.NonExtendable
public interface FeatureFlag<V> {
public interface Option<V> {

/**
* Create a feature flag with a boolean value type.
* Create an option with a boolean value type.
*
* <p>Flag keys must not be reused between flag instances.</p>
*
Expand All @@ -48,12 +48,12 @@ public interface FeatureFlag<V> {
* @return the flag instance
* @since 1.0.0
*/
static FeatureFlag<Boolean> booleanFlag(final String id, final boolean defaultValue) {
return FeatureFlagImpl.flag(id, Boolean.class, defaultValue);
static Option<Boolean> booleanOption(final String id, final boolean defaultValue) {
return OptionImpl.option(id, Boolean.class, defaultValue);
}

/**
* Create a feature flag with an enum value type.
* Create an option with an enum value type.
*
* <p>Flag keys must not be reused between flag instances.</p>
*
Expand All @@ -64,30 +64,30 @@ static FeatureFlag<Boolean> booleanFlag(final String id, final boolean defaultVa
* @return the flag instance
* @since 1.0.0
*/
static <E extends Enum<E>> FeatureFlag<E> enumFlag(final String id, final Class<E> enumClazz, final E defaultValue) {
return FeatureFlagImpl.flag(id, enumClazz, defaultValue);
static <E extends Enum<E>> Option<E> enumOption(final String id, final Class<E> enumClazz, final E defaultValue) {
return OptionImpl.option(id, enumClazz, defaultValue);
}

/**
* Get the flag id.
* Get the option id.
*
* <p>This must be unique among feature flags.</p>
* <p>This must be unique among options.</p>
*
* @return the flag id
* @since 1.0.0
*/
@NotNull String id();

/**
* Get the type of the flag value.
* Get the type of the option value.
*
* @return the value type
* @since 1.0.0
*/
@NotNull Class<V> type();

/**
* Get a default value for the flag, if any is present.
* Get a default value for the option, if any is present.
*
* @return the default value
* @since 1.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of feature-flag, licensed under the MIT License.
* This file is part of option, licensed under the MIT License.
*
* Copyright (c) 2023 KyoriPowered
*
Expand All @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.featureflag;
package net.kyori.option;

import java.util.Objects;
import java.util.Set;
Expand All @@ -31,25 +31,25 @@

import static java.util.Objects.requireNonNull;

final class FeatureFlagImpl<V> implements FeatureFlag<V> {
final class OptionImpl<V> implements Option<V> {
private static final Set<String> KNOWN_KEYS = ConcurrentHashMap.newKeySet();

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

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

static <T> FeatureFlag<T> flag(final String id, final Class<T> type, final @Nullable T defaultValue) {
static <T> Option<T> option(final String id, final Class<T> type, final @Nullable T defaultValue) {
if (!KNOWN_KEYS.add(id)) {
throw new IllegalStateException("Key " + id + " has already been used. Feature flag keys must be unique.");
throw new IllegalStateException("Key " + id + " has already been used. Option keys must be unique.");
}

return new FeatureFlagImpl<>(
return new OptionImpl<>(
requireNonNull(id, "id"),
requireNonNull(type, "type"),
defaultValue
Expand All @@ -75,7 +75,7 @@ static <T> FeatureFlag<T> flag(final String id, final Class<T> type, final @Null
public boolean equals(final @Nullable Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
final FeatureFlagImpl<?> that = (FeatureFlagImpl<?>) other;
final OptionImpl<?> that = (OptionImpl<?>) other;
return Objects.equals(this.id, that.id)
&& Objects.equals(this.type, that.type);
}
Expand Down
Loading

0 comments on commit f1bea25

Please sign in to comment.