Class AbstractOption<T extends AbstractOption<T,U,V>,U extends AbstractOptionValue<U,T,V>,V>

java.lang.Object
com.linecorp.armeria.common.util.AbstractOption<T,U,V>
Type Parameters:
T - the type of the option.
U - the type of the option value holder.
V - the type of the option value.
All Implemented Interfaces:
Comparable<AbstractOption<?,?,?>>
Direct Known Subclasses:
ClientFactoryOption, ClientOption

public abstract class AbstractOption<T extends AbstractOption<T,U,V>,U extends AbstractOptionValue<U,T,V>,V> extends Object implements Comparable<AbstractOption<?,?,?>>
A configuration option.
See Also:
  • Constructor Details

    • AbstractOption

      protected AbstractOption(String name, V defaultValue, Function<V,V> validator, BiFunction<U,U,U> mergeFunction)
      Creates a new instance.
      Parameters:
      name - the name of this option
  • Method Details

    • allOptions

      protected static <T extends Set<?>> T allOptions(Class<?> type)
      Returns all available options of the specified option type.
      Returns:
      the options which are instances of the specified type.
    • of

      protected static <T extends AbstractOption<?, ?, ?>> T of(Class<?> type, String name)
      Returns the option of the specified option type and name.
      Returns:
      the option which is an instance of the specified type and which has the specified name.
    • define

      protected static <T extends AbstractOption<T, U, V>, U extends AbstractOptionValue<U, T, V>, V> T define(Class<?> type, String name, V defaultValue, AbstractOption.Factory<T,U,V> optionFactory, Function<V,V> validator, BiFunction<U,U,U> mergeFunction)
      Defines a new option.
      Type Parameters:
      T - the type of the option.
      U - the type of the option value holder.
      V - the type of the option value.
      Parameters:
      type - the type of the option, e.g. ClientOption.
      name - the name of the option, e.g. "RESPONSE_TIMEOUT_MILLIS".
      defaultValue - the default value of the option.
      optionFactory - the AbstractOption.Factory that creates a new option.
      validator - the Function which is used for validating ane normalizing an option value.
      mergeFunction - the BiFunction which is used for merging old and new option values.
      Returns:
      a new option instance.
      Throws:
      IllegalStateException - if an option with the specified name exists already.
    • name

      public final String name()
      Returns the name of this option.
    • defaultValue

      public final V defaultValue()
      Returns the default value of this option.
    • newValue

      public final U newValue(V value)
      Returns a newly created option value.
    • doNewValue

      protected abstract U doNewValue(V value)
      Implement this method to return a new option value.
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public final int compareTo(AbstractOption<?,?,?> o)
      Specified by:
      compareTo in interface Comparable<T extends AbstractOption<T,U,V>>
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object