This is an automated email from the ASF dual-hosted git repository.
zuston pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/auron.git
The following commit(s) were added to refs/heads/master by this push:
new 117fc399 [AURON #1362] Add description() for ConfigOption (#1363)
117fc399 is described below
commit 117fc399575291b4c49b0b81119b6ecc1427dd75
Author: guixiaowen <[email protected]>
AuthorDate: Sun Sep 28 11:39:04 2025 +0800
[AURON #1362] Add description() for ConfigOption (#1363)
Co-authored-by: guihuawen <[email protected]>
---
.../apache/auron/configuration/ConfigOption.java | 9 +++++
.../apache/auron/configuration/ConfigOptions.java | 40 ++++++++++++++++------
.../auron/configuration/ConfigOptionTest.java | 15 ++++++++
3 files changed, 54 insertions(+), 10 deletions(-)
diff --git
a/auron-core/src/main/java/org/apache/auron/configuration/ConfigOption.java
b/auron-core/src/main/java/org/apache/auron/configuration/ConfigOption.java
index 3c93c4e5..5c566fc5 100644
--- a/auron-core/src/main/java/org/apache/auron/configuration/ConfigOption.java
+++ b/auron-core/src/main/java/org/apache/auron/configuration/ConfigOption.java
@@ -76,6 +76,15 @@ public class ConfigOption<T> {
return key;
}
+ /**
+ * Gets the description of configuration key
+ *
+ * @return
+ */
+ public String description() {
+ return description;
+ }
+
/**
* Checks if this option has a default value.
*
diff --git
a/auron-core/src/main/java/org/apache/auron/configuration/ConfigOptions.java
b/auron-core/src/main/java/org/apache/auron/configuration/ConfigOptions.java
index 517eb926..e872528c 100644
--- a/auron-core/src/main/java/org/apache/auron/configuration/ConfigOptions.java
+++ b/auron-core/src/main/java/org/apache/auron/configuration/ConfigOptions.java
@@ -30,6 +30,13 @@ import static
org.apache.auron.util.Preconditions.checkNotNull;
* .stringType()
* .defaultValue("/tmp");
*
+ * // simple string-valued option with a default value and with the description
+ * ConfigOption<String> tempDirs = ConfigOptions
+ * .key("tmp.dir")
+ * .description("this is a example of string")
+ * .stringType()
+ * .defaultValue("/tmp");
+ *
* // simple integer-valued option with a default value
* ConfigOption<Integer> batchSize = ConfigOptions
* .key("batch.size")
@@ -67,43 +74,53 @@ public class ConfigOptions {
/** The key for the config option. */
private final String key;
+ private String description = ConfigOption.EMPTY_DESCRIPTION;
+
/**
* Creates a new OptionBuilder.
- *
* @param key The key for the config option
*/
OptionBuilder(String key) {
this.key = key;
}
+ OptionBuilder(String key, String description) {
+ this.key = key;
+ this.description = description;
+ }
+
+ public OptionBuilder description(String description) {
+ return new OptionBuilder(key, description);
+ }
+
/** Defines that the value of the option should be of {@link Boolean}
type. */
public TypedConfigOptionBuilder<Boolean> booleanType() {
- return new TypedConfigOptionBuilder<>(key, Boolean.class);
+ return new TypedConfigOptionBuilder<>(key, Boolean.class,
description);
}
/** Defines that the value of the option should be of {@link Integer}
type. */
public TypedConfigOptionBuilder<Integer> intType() {
- return new TypedConfigOptionBuilder<>(key, Integer.class);
+ return new TypedConfigOptionBuilder<>(key, Integer.class,
description);
}
/** Defines that the value of the option should be of {@link Long}
type. */
public TypedConfigOptionBuilder<Long> longType() {
- return new TypedConfigOptionBuilder<>(key, Long.class);
+ return new TypedConfigOptionBuilder<>(key, Long.class,
description);
}
/** Defines that the value of the option should be of {@link Float}
type. */
public TypedConfigOptionBuilder<Float> floatType() {
- return new TypedConfigOptionBuilder<>(key, Float.class);
+ return new TypedConfigOptionBuilder<>(key, Float.class,
description);
}
/** Defines that the value of the option should be of {@link Double}
type. */
public TypedConfigOptionBuilder<Double> doubleType() {
- return new TypedConfigOptionBuilder<>(key, Double.class);
+ return new TypedConfigOptionBuilder<>(key, Double.class,
description);
}
/** Defines that the value of the option should be of {@link String}
type. */
public TypedConfigOptionBuilder<String> stringType() {
- return new TypedConfigOptionBuilder<>(key, String.class);
+ return new TypedConfigOptionBuilder<>(key, String.class,
description);
}
}
@@ -116,9 +133,12 @@ public class ConfigOptions {
private final String key;
private final Class<T> clazz;
- TypedConfigOptionBuilder(String key, Class<T> clazz) {
+ private final String description;
+
+ TypedConfigOptionBuilder(String key, Class<T> clazz, String
description) {
this.key = key;
this.clazz = clazz;
+ this.description = description;
}
/**
@@ -128,7 +148,7 @@ public class ConfigOptions {
* @return The config option with the default value.
*/
public ConfigOption<T> defaultValue(T value) {
- return new ConfigOption<>(key, clazz, value,
ConfigOption.EMPTY_DESCRIPTION);
+ return new ConfigOption<>(key, clazz, value, description);
}
/**
@@ -137,7 +157,7 @@ public class ConfigOptions {
* @return The config option without a default value.
*/
public ConfigOption<T> noDefaultValue() {
- return new ConfigOption<>(key, clazz, null,
ConfigOption.EMPTY_DESCRIPTION);
+ return new ConfigOption<>(key, clazz, null, description);
}
}
diff --git
a/auron-core/src/test/java/org/apache/auron/configuration/ConfigOptionTest.java
b/auron-core/src/test/java/org/apache/auron/configuration/ConfigOptionTest.java
index e71c34cd..5866a777 100644
---
a/auron-core/src/test/java/org/apache/auron/configuration/ConfigOptionTest.java
+++
b/auron-core/src/test/java/org/apache/auron/configuration/ConfigOptionTest.java
@@ -32,4 +32,19 @@ public class ConfigOptionTest {
ConfigOptions.key("boolean").booleanType().defaultValue(true);
Assert.assertEquals(true, booleanOption.defaultValue());
}
+
+ @Test
+ public void testConfigOptionAddDesc() {
+ ConfigOption<String> keyOption = ConfigOptions.key("key")
+ .description("this is a description of the key")
+ .stringType()
+ .noDefaultValue();
+ Assert.assertEquals("key", keyOption.key());
+ Assert.assertEquals(null, keyOption.defaultValue());
+ Assert.assertEquals(false, keyOption.hasDefaultValue());
+ ConfigOption<Boolean> booleanOption =
+ ConfigOptions.key("boolean").booleanType().defaultValue(true);
+ Assert.assertEquals(true, booleanOption.defaultValue());
+ Assert.assertEquals("this is a description of the key",
keyOption.description());
+ }
}