# 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 wrappers
- `V`: the wrapper result type

## Constructors

### new ClassWrapperTree {#com.jsmacrosce.jsmacros.core.helper.ClassWrapperTree_constructor-Class-Function-}

```js
new ClassWrapperTree(Class<K> baseType, Function<K, V> baseTypeWrapper)
```

Initializes the fallback wrapper used when no registered child type matches.

**Parameters:**
- `baseType`: type handled by this tree's fallback wrapper
- `baseTypeWrapper`: fallback wrapper function

## Methods

### getSubtypeWrapper {#com.jsmacrosce.jsmacros.core.helper.ClassWrapperTree_getSubtypeWrapper-Class-}

```js
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 type
- `U`: wrapper result type

**Returns:** the first matching descendant, or this node as the fallback

### registerType {#com.jsmacrosce.jsmacros.core.helper.ClassWrapperTree_registerType-Class-Function-}

```js
registerType(Class<T extends K> type, Function<T extends K, U extends V> wrapper): void
```

Registers or replaces a wrapper and places assignable registered types beneath it.

**Parameters:**
- `type`: input class to register
- `wrapper`: function applied to matching values

**Type Parameters:**
- `T`: registered input type
- `U`: result type produced by the wrapper

### wrap {#com.jsmacrosce.jsmacros.core.helper.ClassWrapperTree_wrap-T-}

```js
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`
