public class MergeMenus<M extends MenuItem<M>> extends Object
MenuItem
s hierarchies; perform a Merge on them. While MenuItem
is Comparable
, the merge operations strictly look @ MenuItem.getName()
and by default this is case-insensitive.
MenuItem
to be merged, and secondary hierarchy to the second MenuItem
.Constructor and Description |
---|
MergeMenus() |
Modifier and Type | Method and Description |
---|---|
org.apache.commons.collections.Transformer |
getMenuIdTranslator()
It maybe possible that the identifiers of 2 nodes may not match but imply the same node.
|
Comparator<M> |
getSort()
An Optional Sorting algorithm to apply on merged children
|
boolean |
merge(M hierarchy1,
M hierarchy2,
Set<String> searchedSet)
Merge two
MenuItem ; merge the second hierarchy into the first (Fold Left operation). |
void |
normalize(M hierarchyTobeNormalized)
Apply the
menuIdTranslator to the MenuItem |
void |
setMenuIdTranslator(org.apache.commons.collections.Transformer menuIdTranslator)
It maybe possible that the identifiers of 2 nodes may not match but imply the same node.
|
void |
setSort(Comparator<M> sort)
An Optional Sorting algorithm to apply on merged children
|
public void normalize(M hierarchyTobeNormalized)
menuIdTranslator
to the MenuItem
hierarchyTobeNormalized
- as MenuItempublic boolean merge(M hierarchy1, M hierarchy2, Set<String> searchedSet)
MenuItem
; merge the second hierarchy into the first (Fold Left operation). Common nodes will retain value from hierarchy1.
MenuItem.name
s are case insensitive while comparing.
Merge Algorithm: Compare the 2nd hierarchy root(s) to every element till they find a match (MenuItems should be normalized before comparison). if they find a match, then the elements of the
2nd hierarchy nodes under the matched parent are recursively matched, till all items are merged. If @ any level matches are not found then
the node with its children is appended.
hierarchy1
- as MenuItem
hierarchy2
- as MenuItem
searchedSet
- as Optional scratch space.During the merge process some combinations of searches are repeated, improve efficiency by eliminating search paths once discovered.
Improves efficiency by 5 to 6 times on small trees of depth 3; on larger trees could be more significant.public org.apache.commons.collections.Transformer getMenuIdTranslator()
MenuItem.getName()
The Transformer
expects to take in a MenuItem (with a name of type understood by the secondary Hierarchy and translated to a MenuItem with a understood by the first Hierarchy)
MenuItem.compareTo(MenuItem)
is case insensitive on the name.public void setMenuIdTranslator(org.apache.commons.collections.Transformer menuIdTranslator)
MenuItem.getName()
The Transformer
expects to take in a MenuItem (with a name of type understood by the secondary Hierarchy and translated to a MenuItem with a understood by the first Hierarchy)
MenuItem.compareTo(MenuItem)
is case insensitive on the name.public Comparator<M> getSort()
public void setSort(Comparator<M> sort)
Copyright © 2018. All rights reserved.