Package com.linecorp.armeria.common.util
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:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static interface
AbstractOption.Factory<T extends AbstractOption<T,
U, V>, U extends AbstractOptionValue<U, T, V>, V> Creates a new option instance. -
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractOption
(String name, V defaultValue, Function<V, V> validator, BiFunction<U, U, U> mergeFunction) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected static <T extends Set<?>>
TallOptions
(Class<?> type) Returns all available options of the specified option type.final int
compareTo
(AbstractOption<?, ?, ?> o) final V
Returns the default value of this option.protected static <T extends AbstractOption<T,
U, V>, U extends AbstractOptionValue<U, T, V>, V>
Tdefine
(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.protected abstract U
doNewValue
(V value) Implement this method to return a new option value.final boolean
final int
hashCode()
final String
name()
Returns the name of this option.final U
Returns a newly created option value.protected static <T extends AbstractOption<?,
?, ?>>
TReturns the option of the specified option type and name.final String
toString()
-
Constructor Details
-
Method Details
-
allOptions
Returns all available options of the specified option type.- Returns:
- the options which are instances of the specified
type
.
-
of
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 specifiedname
.
-
define
protected static <T extends AbstractOption<T,U, T defineV>, U extends AbstractOptionValue<U, T, V>, V> (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
- theAbstractOption.Factory
that creates a new option.validator
- theFunction
which is used for validating ane normalizing an option value.mergeFunction
- theBiFunction
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
Returns the name of this option. -
defaultValue
Returns the default value of this option. -
newValue
Returns a newly created option value. -
doNewValue
Implement this method to return a new option value. -
hashCode
public final int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<T extends AbstractOption<T,
U, V>>
-
equals
-
toString
-