ClassWrapperTree
com.jsmacrosce.jsmacros.core.helper.ClassWrapperTree
Registry that dispatches values to wrappers according to their runtime class.
Core's helper registry uses this tree to select helpers; scripts can also request wrapping through JavaUtils.getHelperFromRaw(raw).
js
const raw = Chat.createTextHelperFromString("hello").getRaw();
const helper = JavaUtils.getHelperFromRaw(raw);
if (helper !== null) print(helper);Type Parameters
K: the input type accepted by registered wrappersV: the wrapper result type
Constructors
new ClassWrapperTree
Methods
getSubtypeWrapper
getSubtypeWrapper(Class<T extends K> type): ClassWrapperTree<T extends K, U extends V>#Searches the first assignable child recursively, or returns this node if none matches. The fallback also applies when
type is unrelated to this node's registered type.Parameters:
type: class to look up
Type Parameters:
T: queried typeU: wrapper result type
Returns: the first matching descendant, or this node as the fallback
registerType
Registers or replaces a wrapper and places assignable registered types beneath it.
Parameters:
type: input class to registerwrapper: function applied to matching values
Type Parameters:
T: registered input typeU: result type produced by the wrapper
wrap
wrap(T extends K inputType): V#Applies the first matching registered wrapper to the input's runtime class.
Parameters:
inputType: value to wrap; must be non-null
Type Parameters:
T: input type
Returns: the selected wrapper's result, which may be
null