Class BaseTreeNodeTransformer
java.lang.Object
io.github.astrapi69.gen.tree.convert.BaseTreeNodeTransformer
The class
BaseTreeNodeTransformer provides algorithms for converting between the
BaseTreeNode objects and TreeIdNode objects. This is useful if you want to save
BaseTreeNode objects in a store, you have first to transform the BaseTreeNode
objects (you want to store) to TreeIdNode objects and save them. Note: The
BaseTreeNode object can not be stored-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,K> BaseTreeNode<T, K> getRoot(@NonNull Map<K, TreeIdNode<T, K>> treeIdNodeMap) Retrieves the rootBaseTreeNodeobject from the given @link Map} object that containsTreeIdNodeobjects as values and the id as keystatic <T,K> Map<K, BaseTreeNode<T, K>> toKeyBaseTreeNodeMap(@NonNull BaseTreeNode<T, K> root) Transforms the givenBaseTreeNodeobject to aMapobject with the key and the correspondingBaseTreeNodeobjectsstatic <T,K> Map<K, TreeIdNode<T, K>> toKeyMap(@NonNull BaseTreeNode<T, K> root) Transforms the givenBaseTreeNodeobject to aMapobject with the key and the correspondingTreeIdNodeobjectsstatic <T,K> TreeIdNode<T, K> toTreeIdNode(@NonNull BaseTreeNode<T, K> baseTreeNode) Transforms the givenBaseTreeNodeobject to aTreeIdNodeobjectstatic <T,K> Map<K, BaseTreeNode<T, K>> transform(@NonNull Map<K, TreeIdNode<T, K>> treeIdNodeMap) Transforms the givenMapobject that containsTreeIdNodeobjects as values and the id as key
-
Method Details
-
toKeyMap
Transforms the givenBaseTreeNodeobject to aMapobject with the key and the correspondingTreeIdNodeobjects- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
root- theBaseTreeNodeobject to transform- Returns:
- a
Mapobject with the correspondingTreeIdNodeobjects
-
toTreeIdNode
Transforms the givenBaseTreeNodeobject to aTreeIdNodeobject- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
baseTreeNode- theBaseTreeNodeobject to convert- Returns:
- the new created
TreeIdNodeobject
-
toKeyBaseTreeNodeMap
public static <T,K> Map<K,BaseTreeNode<T, toKeyBaseTreeNodeMapK>> (@NonNull @NonNull BaseTreeNode<T, K> root) Transforms the givenBaseTreeNodeobject to aMapobject with the key and the correspondingBaseTreeNodeobjects- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
root- theBaseTreeNodeobject to transform- Returns:
- a
Mapobject with the correspondingBaseTreeNodeobjects
-
transform
public static <T,K> Map<K,BaseTreeNode<T, transformK>> (@NonNull @NonNull Map<K, TreeIdNode<T, K>> treeIdNodeMap) Transforms the givenMapobject that containsTreeIdNodeobjects as values and the id as key- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeIdNodeMap- theMapobject with theTreeIdNodeobjects to transform- Returns:
- a
Mapobject with the correspondingBaseTreeNodeobjects
-
getRoot
public static <T,K> BaseTreeNode<T,K> getRoot(@NonNull @NonNull Map<K, TreeIdNode<T, K>> treeIdNodeMap) Retrieves the rootBaseTreeNodeobject from the given @link Map} object that containsTreeIdNodeobjects as values and the id as key- Type Parameters:
T- the generic type of the valueK- the generic type of the id of the node- Parameters:
treeIdNodeMap- theMapobject with theTreeIdNodeobjects to transform- Returns:
- the root
BaseTreeNodeobject or null if not found
-