Skip to content

Commit d005096

Browse files
committed
chore: tidying and no-prefix value source overload
1 parent 7ed6b74 commit d005096

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

src/main/java/net/kyori/option/Option.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
*/
3939
@ApiStatus.NonExtendable
4040
public interface Option<V> {
41-
4241
/**
4342
* Create an option with a boolean value type.
4443
*

src/main/java/net/kyori/option/value/ValueSource.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
*/
3535
@FunctionalInterface
3636
public interface ValueSource {
37+
/**
38+
* A value source that will extract option values from environment variables.
39+
*
40+
* <p>Any of the characters {@code :}, {@code /}, and {@code -} will be replaced with {@code _}.</p>
41+
*
42+
* @return an environment variable-backed value source with no prefix
43+
* @since 1.1.0
44+
*/
45+
static @NotNull ValueSource environmentVariable() {
46+
return environmentVariable("");
47+
}
48+
3749
/**
3850
* A value source that will extract option values from environment variables.
3951
*
@@ -45,7 +57,19 @@ public interface ValueSource {
4557
* @since 1.1.0
4658
*/
4759
static @NotNull ValueSource environmentVariable(final @NotNull String prefix) {
48-
return new ValueSources.EnvironmentVariables(prefix);
60+
return new ValueSources.EnvironmentVariable(prefix);
61+
}
62+
63+
/**
64+
* A value source that will extract option values from system properties.
65+
*
66+
* <p>Any of the characters {@code :} and {@code /} will be replaced with {@code .}.</p>
67+
*
68+
* @return a system property-backed value source with no prefix
69+
* @since 1.1.0
70+
*/
71+
static @NotNull ValueSource systemProperty() {
72+
return systemProperty("");
4973
}
5074

5175
/**
@@ -59,7 +83,7 @@ public interface ValueSource {
5983
* @since 1.1.0
6084
*/
6185
static @NotNull ValueSource systemProperty(final @NotNull String prefix) {
62-
return new ValueSources.SystemProperties(prefix);
86+
return new ValueSources.SystemProperty(prefix);
6387
}
6488

6589
/**

src/main/java/net/kyori/option/value/ValueSources.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@
3131
import org.jetbrains.annotations.Nullable;
3232

3333
final class ValueSources {
34-
static final ValueSource ENVIRONMENT = new EnvironmentVariables("");
35-
static final ValueSource SYSTEM_PROPERTIES = new SystemProperties("");
34+
static final ValueSource ENVIRONMENT = new EnvironmentVariable("");
35+
static final ValueSource SYSTEM_PROPERTIES = new SystemProperty("");
3636

3737
private ValueSources() {
3838
}
3939

40-
static final class EnvironmentVariables implements ValueSource {
40+
static final class EnvironmentVariable implements ValueSource {
4141
private static final Pattern ENVIRONMENT_SUBST_PATTERN = Pattern.compile("[:\\-/]");
4242
private static final String ENVIRONMENT_VAR_SEPARATOR = "_";
4343

4444
private final String prefix;
4545

46-
EnvironmentVariables(final String prefix) {
46+
EnvironmentVariable(final String prefix) {
4747
this.prefix = prefix.isEmpty() ? "" : prefix.toUpperCase(Locale.ROOT) + ENVIRONMENT_VAR_SEPARATOR;
4848
}
4949

@@ -66,13 +66,13 @@ static final class EnvironmentVariables implements ValueSource {
6666
}
6767
}
6868

69-
static final class SystemProperties implements ValueSource {
69+
static final class SystemProperty implements ValueSource {
7070
private static final Pattern SYSTEM_PROP_SUBST_PATTERN = Pattern.compile("[:/]");
7171
private static final String SYSTEM_PROPERTY_SEPARATOR = ".";
7272

7373
private final String prefix;
7474

75-
SystemProperties(final String prefix) {
75+
SystemProperty(final String prefix) {
7676
this.prefix = prefix.isEmpty() ? "" : prefix + SYSTEM_PROPERTY_SEPARATOR;
7777
}
7878

src/test/java/net/kyori/option/value/ValueSourceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void testReadSystemProperties() {
5959

6060
@Test
6161
void testReadSystemPropertiesNoPrefix() {
62-
final ValueSource systemProperties = ValueSource.systemProperty("");
62+
final ValueSource systemProperties = ValueSource.systemProperty();
6363
assertNull(systemProperties.value(C));
6464
assertNull(systemProperties.value(C_D));
6565

0 commit comments

Comments
 (0)