Class OptionsByType<T>
- java.lang.Object
-
- com.oracle.coherence.concurrent.executor.util.OptionsByType<T>
-
- Type Parameters:
T- the base type of the options in the collection
- All Implemented Interfaces:
com.tangosol.io.ExternalizableLite,com.tangosol.io.pof.PortableObject,Serializable
- Direct Known Subclasses:
OptionsByType.EmptyOptionsByType
public class OptionsByType<T> extends Object implements com.tangosol.io.ExternalizableLite, com.tangosol.io.pof.PortableObject
A mutable collection of zero or more values, typically called an options, internally arranged as a map, keyed by the concrete type of each option in the collection.- Since:
- 21.12
- Author:
- bo
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceOptionsByType.DefaultDefines how anOptionsByTypecollection may automatically determine a suitable default value for a specific class of option at runtime when the said option does not exist in anOptionsByTypecollection.protected static classOptionsByType.EmptyOptionsByType<T>An optimizedOptionsByTypeimplementation for representing emptyOptionsByType.
-
Field Summary
Fields Modifier and Type Field Description protected Class<T>m_clzOfOptionTheClassof the option in the collection.protected LinkedHashMap<Class<? extends T>,T>m_mapOptionsByTypeThe map of the options, keyed by their concrete class.
-
Constructor Summary
Constructors Constructor Description OptionsByType()Constructor forExternalizableLitesupport.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OptionsByType<T>add(T option)Adds an option to the collection, replacing an existing option of the same concrete type if one exists.OptionsByType<T>addAll(OptionsByType<? extends T> optionsByType)Adds all current options into the specifiedOptionsByTypeto this collection, replacing existing options of the same concrete type where they exist.OptionsByType<T>addAll(T[] options)Adds an array of options to the collection, replacing existing options of the same concrete type where they exist.T[]asArray()Obtains the current collection of options as an array.<O extends T>
booleancontains(Class<O> clzOfOption)Determines if an option of the specified concrete type is in the collection.booleancontains(T option)Determines if the specified option (and type) is in theOptionsByType.static <T> OptionsByType<T>empty()Constructs an emptyOptionsByTypecollection.static <T> OptionsByType<T>from(Class<T> classOfOption, T[] baseOptions, T... options)Constructs anOptionsByTypecollection given an array of options.<U extends T>
Uget(Class<U> clzOfOption)Obtains the option for a specified concrete type from the collection.<U extends T>
Uget(Class<U> clzOfOption, U defaultOption)Obtains the option of a specified concrete type from the collection.protected <O extends T>
Class<O>getClassOf(Class<?> clzOfOption)Obtains the concrete type that directly implements / extends them_clzOfOptionoptionClass.protected Class<T>getClassOf(T option)Obtains the concrete option type.protected <U extends T>
UgetDefaultFor(Class<U> clzOfOption)Attempts to determine a "default" value for a given class.voidreadExternal(com.tangosol.io.pof.PofReader in)voidreadExternal(DataInput in)StringtoString()voidwriteExternal(com.tangosol.io.pof.PofWriter out)voidwriteExternal(DataOutput out)
-
-
-
Method Detail
-
get
public <U extends T> U get(Class<U> clzOfOption)
Obtains the option for a specified concrete type from the collection.Should the option not exist in the collection, an attempt is made to determine a suitable default based on the use of the
OptionsByType.Defaultannotation in the specified class, firstly by looking for and evaluating the annotated "public static U getter()" method, failing that, looking for and evaluating the annotated "public static U value = ...;" field, failing that, looking for an evaluating the annotated public no args constructor and finally, failing that, looking for an annotated field on an enum (assuming the class is an enum). Failing these approaches,nullis returned.- Type Parameters:
U- the type of value- Parameters:
clzOfOption- the concrete type of option to obtain- Returns:
- the option of the specified type or if undefined, the suitable default value (or
nullif one can't be determined)
-
get
public <U extends T> U get(Class<U> clzOfOption, U defaultOption)
Obtains the option of a specified concrete type from the collection.Should the type of option not exist, the specified default is returned.
- Type Parameters:
U- the type of value- Parameters:
clzOfOption- the type of option to obtaindefaultOption- the option to return if the specified type is not defined- Returns:
- the option of the specified type or the default if it's not defined
-
contains
public <O extends T> boolean contains(Class<O> clzOfOption)
Determines if an option of the specified concrete type is in the collection.- Type Parameters:
O- the type of option- Parameters:
clzOfOption- the class of option- Returns:
trueif the class of option is in theOptionsByTypefalseotherwise
-
contains
public boolean contains(T option)
Determines if the specified option (and type) is in theOptionsByType.- Parameters:
option- the option- Returns:
trueif the options is defined,falseotherwise
-
asArray
public T[] asArray()
Obtains the current collection of options as an array.- Returns:
- an array of options
-
from
@SafeVarargs public static <T> OptionsByType<T> from(Class<T> classOfOption, T[] baseOptions, T... options)
Constructs anOptionsByTypecollection given an array of options.- Type Parameters:
T- the type of options- Parameters:
classOfOption- theClassof the base type of the options in the collectionbaseOptions- the base optionsoptions- the array of options- Returns:
- an
OptionsByTypecollection
-
empty
public static <T> OptionsByType<T> empty()
Constructs an emptyOptionsByTypecollection.- Type Parameters:
T- the type of options- Returns:
- an empty
OptionsByTypecollection
-
add
public OptionsByType<T> add(T option)
Adds an option to the collection, replacing an existing option of the same concrete type if one exists.- Parameters:
option- the option to add- Returns:
- the
OptionsByTypeto permit fluent-style method calls
-
addAll
public OptionsByType<T> addAll(T[] options)
Adds an array of options to the collection, replacing existing options of the same concrete type where they exist.- Parameters:
options- the options to add- Returns:
- the
OptionsByTypeto permit fluent-style method calls
-
addAll
public OptionsByType<T> addAll(OptionsByType<? extends T> optionsByType)
Adds all current options into the specifiedOptionsByTypeto this collection, replacing existing options of the same concrete type where they exist.- Parameters:
optionsByType- theOptionsByTypeto add- Returns:
- the
OptionsByTypeto permit fluent-style method calls
-
getClassOf
protected Class<T> getClassOf(T option)
Obtains the concrete option type.- Parameters:
option- the option- Returns:
- the concrete
Classthat directly extends / implements the value interface ornullif the value isnull
-
getClassOf
protected <O extends T> Class<O> getClassOf(Class<?> clzOfOption)
Obtains the concrete type that directly implements / extends them_clzOfOptionoptionClass.- Type Parameters:
O- the option concrete type- Parameters:
clzOfOption- the class that somehow implements or extendsm_clzOfOption- Returns:
- the concrete
Classthat directly extends / implements them_clzOfOptionclass ornullif the specifiedClassdoesn't implement or extend them_clzOfOptionclass
-
getDefaultFor
protected <U extends T> U getDefaultFor(Class<U> clzOfOption)
Attempts to determine a "default" value for a given class.Aan attempt is made to determine a suitable default based on the use of the
OptionsByType.Defaultannotation in the specified class, firstly by looking for and evaluating the annotated "public static U getter()" method, failing that, looking for and evaluating the annotated "public static U value = ...;" field, failing that, looking for an evaluating the annotated public no args constructor and finally, failing that, looking for an annotated field on an enum (assuming the class is an enum). Failing these approaches,nullis returned.- Type Parameters:
U- the type of value- Parameters:
clzOfOption- the class- Returns:
- a default value or
nullif a default can't be determined
-
readExternal
public void readExternal(DataInput in) throws IOException
- Specified by:
readExternalin interfacecom.tangosol.io.ExternalizableLite- Throws:
IOException
-
writeExternal
public void writeExternal(DataOutput out) throws IOException
- Specified by:
writeExternalin interfacecom.tangosol.io.ExternalizableLite- Throws:
IOException
-
readExternal
public void readExternal(com.tangosol.io.pof.PofReader in) throws IOException- Specified by:
readExternalin interfacecom.tangosol.io.pof.PortableObject- Throws:
IOException
-
writeExternal
public void writeExternal(com.tangosol.io.pof.PofWriter out) throws IOException- Specified by:
writeExternalin interfacecom.tangosol.io.pof.PortableObject- Throws:
IOException
-
-