Module ultimategdbot.api
Class ConfigEntryBuilder<D extends GuildConfigData<D>,T>
- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.guildconfig.ConfigEntryBuilder<D,T>
-
- Type Parameters:
D
- the type of data object storing the value of the entry being builtT
- the type of value supported by the entry being built
public class ConfigEntryBuilder<D extends GuildConfigData<D>,T> extends Object
Provides methods to build a configuration entry.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ConfigEntryBuilder<D,T>
setDisplayName(String displayName)
Specifies a user-friendly name for this entry.ConfigEntryBuilder<D,T>
setValidator(Validator<T> validator)
Specifies the validator that will validate new values set to the entry.ConfigEntryBuilder<D,T>
setValueGetter(Function<? super D,? extends reactor.core.publisher.Mono<T>> valueGetter)
Specifies how to extract the value from the data object.ConfigEntryBuilder<D,T>
setValueSetter(BiFunction<? super D,? super T,? extends D> valueSetter)
Specifies how to update the value and store it in the data object.
-
-
-
Method Detail
-
setDisplayName
public ConfigEntryBuilder<D,T> setDisplayName(@Nullable String displayName)
Specifies a user-friendly name for this entry. If not set or is set tonull
, the display name will be the same as the key.- Parameters:
displayName
- the display name to set- Returns:
- this builder
-
setValueGetter
public ConfigEntryBuilder<D,T> setValueGetter(@Nullable Function<? super D,? extends reactor.core.publisher.Mono<T>> valueGetter)
Specifies how to extract the value from the data object. If no value is present (e.g null in database), an emptyMono
should be returned. If not set or is set tonull
, the function will always return an emptyMono
.- Parameters:
valueGetter
- the function that extracts and returns the value from the data object with asynchronous capabilities- Returns:
- this builder
-
setValueSetter
public ConfigEntryBuilder<D,T> setValueSetter(@Nullable BiFunction<? super D,? super T,? extends D> valueSetter)
Specifies how to update the value and store it in the data object. The function MUST NOT have any side-effects, i.e should not do anything other than setting the value. Since configurators and entries are thread-safe and atomically set new values in a lock-free way, the setter is prone to be called more than once at each value update.If nothing is set or is set to
null
, the entry will be marked as read-only and any attempt to modify the value will fail- Parameters:
valueSetter
- the bifunction that updates the value and stores it in the data object, then returns the mutated data object (might as well return a new instance if the data object is immutable)- Returns:
- this builder
-
setValidator
public ConfigEntryBuilder<D,T> setValidator(@Nullable Validator<T> validator)
Specifies the validator that will validate new values set to the entry. If not set or is set tonull
,Validator.allowingAll()
will be used.- Parameters:
validator
- the validator to set- Returns:
- this builder
-
-