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 Type
    Method
    Description
    Gets the dynamic member attributes (options)
    default <T> void
    ifNull(AttrOption<T> option, Supplier<T> supplier)
    Executes the given operation if the dynamic attribute value is null, otherwise does nothing.
    default <T> void
    ifPresent(AttrOption<T> option, Consumer<T> consumer)
    Executes the given operation if the dynamic attribute exists and is not null, otherwise does nothing.
    default <T> T
    option(AttrOption<T> option)
    Gets the option value.
    default <T> AttrOptions
    option(AttrOption<T> option, T value)
    Sets a new option with a specific value.
    default <T> T
    optionValue(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

      default <T> T option(AttrOption<T> 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

      default <T> T optionValue(AttrOption<T> option, T value)
      Gets the option value. Returns the specified value if the option does not exist or is null.
      Parameters:
      option - The attribute option
      value - The specified value
      Returns:
      The option value, or the specified value if the option is null or does not exist.
    • option

      default <T> AttrOptions option(AttrOption<T> option, T value)
      Sets a new option with a specific value.

      Use a null value to remove the previously set AttrOption.

      Parameters:
      option - The attribute option
      value - The option value, null to remove the previously set AttrOption.
      Returns:
      this
    • ifPresent

      default <T> void ifPresent(AttrOption<T> option, Consumer<T> consumer)
      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 option
      consumer - The given operation. Executed only if the option's value exists and is not null.
    • ifNull

      default <T> void ifNull(AttrOption<T> option, Supplier<T> supplier)
      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 option
      supplier - The given operation. Executed only when the option's value is null.