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 rootBaseTreeNode
object from the given @link Map} object that containsTreeIdNode
objects as values and the id as keystatic <T,
K> Map<K, BaseTreeNode<T, K>> toKeyBaseTreeNodeMap
(@NonNull BaseTreeNode<T, K> root) Transforms the givenBaseTreeNode
object to aMap
object with the key and the correspondingBaseTreeNode
objectsstatic <T,
K> Map<K, TreeIdNode<T, K>> toKeyMap
(@NonNull BaseTreeNode<T, K> root) Transforms the givenBaseTreeNode
object to aMap
object with the key and the correspondingTreeIdNode
objectsstatic <T,
K> TreeIdNode<T, K> toTreeIdNode
(@NonNull BaseTreeNode<T, K> baseTreeNode) Transforms the givenBaseTreeNode
object to aTreeIdNode
objectstatic <T,
K> Map<K, BaseTreeNode<T, K>> transform
(@NonNull Map<K, TreeIdNode<T, K>> treeIdNodeMap) Transforms the givenMap
object that containsTreeIdNode
objects as values and the id as key
-
Method Details
-
toKeyMap
Transforms the givenBaseTreeNode
object to aMap
object with the key and the correspondingTreeIdNode
objects- Type Parameters:
T
- the generic type of the valueK
- the generic type of the id of the node- Parameters:
root
- theBaseTreeNode
object to transform- Returns:
- a
Map
object with the correspondingTreeIdNode
objects
-
toTreeIdNode
Transforms the givenBaseTreeNode
object to aTreeIdNode
object- Type Parameters:
T
- the generic type of the valueK
- the generic type of the id of the node- Parameters:
baseTreeNode
- theBaseTreeNode
object to convert- Returns:
- the new created
TreeIdNode
object
-
toKeyBaseTreeNodeMap
public static <T,K> Map<K,BaseTreeNode<T, toKeyBaseTreeNodeMapK>> (@NonNull @NonNull BaseTreeNode<T, K> root) Transforms the givenBaseTreeNode
object to aMap
object with the key and the correspondingBaseTreeNode
objects- Type Parameters:
T
- the generic type of the valueK
- the generic type of the id of the node- Parameters:
root
- theBaseTreeNode
object to transform- Returns:
- a
Map
object with the correspondingBaseTreeNode
objects
-
transform
public static <T,K> Map<K,BaseTreeNode<T, transformK>> (@NonNull @NonNull Map<K, TreeIdNode<T, K>> treeIdNodeMap) Transforms the givenMap
object that containsTreeIdNode
objects 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
- theMap
object with theTreeIdNode
objects to transform- Returns:
- a
Map
object with the correspondingBaseTreeNode
objects
-
getRoot
public static <T,K> BaseTreeNode<T,K> getRoot(@NonNull @NonNull Map<K, TreeIdNode<T, K>> treeIdNodeMap) Retrieves the rootBaseTreeNode
object from the given @link Map} object that containsTreeIdNode
objects 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
- theMap
object with theTreeIdNode
objects to transform- Returns:
- the root
BaseTreeNode
object or null if not found
-