Interface AttrOptionDynamic
- All Known Subinterfaces:
ClientUser, ExternalServerBuilderSetting, UserSession, UserSessions<SessionContext, Session>
- All Known Implementing Classes:
DefaultClientUser, ExternalServerBuilder, ExternalSetting, SocketUserSession, SocketUserSessions
public interface AttrOptionDynamic
AttrOptionDynamic
AttrOptionDynamic options = ...;
AttrOption<Long> timeKey = AttrOption.valueOf("myLongValue");
// set long value
this.option(timeKey, 123L);
// get long value
long val = this.option(timeKey);
AttrOption<Integer> intKey = AttrOption.valueOf("myIntegerValue");
// set int value
this.option(intKey, 123);
// get int value
int age = this.option(intKey);
- Author:
- 渔民小镇
- date:
- 2022-01-31
-
Method Summary
Modifier and TypeMethodDescriptionGets the dynamic member attributes (options)default <T> voidifNull(AttrOption<T> option, Supplier<T> supplier) Executes the given operation if the dynamic attribute value is null, otherwise does nothing.default <T> voidifPresent(AttrOption<T> option, Consumer<T> consumer) Executes the given operation if the dynamic attribute exists and is not null, otherwise does nothing.default <T> Toption(AttrOption<T> option) Gets the option value.default <T> AttrOptionsoption(AttrOption<T> option, T value) Sets a new option with a specific value.default <T> ToptionValue(AttrOption<T> option, T value) Gets the option value.
-
Method Details
-
getOptions
AttrOptions getOptions()Gets the dynamic member attributes (options)- Returns:
- The dynamic member attributes
-
option
Gets the option value. Returns the default value if the option does not exist.- Parameters:
option- The attribute option- Returns:
- The option value, or the default option value if the option does not exist.
-
optionValue
Gets the option value. Returns the specified value if the option does not exist or is null.- Parameters:
option- The attribute optionvalue- The specified value- Returns:
- The option value, or the specified value if the option is null or does not exist.
-
option
Sets a new option with a specific value.Use a null value to remove the previously set
AttrOption.- Parameters:
option- The attribute optionvalue- The option value, null to remove the previously setAttrOption.- Returns:
- this
-
ifPresent
Executes the given operation if the dynamic attribute exists and is not null, otherwise does nothing.- Type Parameters:
T- The type of the attribute value- Parameters:
option- The attribute optionconsumer- The given operation. Executed only if the option's value exists and is not null.
-
ifNull
Executes the given operation if the dynamic attribute value is null, otherwise does nothing. The returned value from the operation will be set as the dynamic attribute's value.- Type Parameters:
T- The type of the attribute value- Parameters:
option- The attribute optionsupplier- The given operation. Executed only when the option's value is null.
-