Class HierarchyTree<K,V>
- java.lang.Object
-
- org.optaweb.employeerostering.util.HierarchyTree<K,V>
-
- Type Parameters:
K- The type of the key element in the HierarchyV- The type of the value element in the Hierarchy
public class HierarchyTree<K,V> extends Object
A data structure representing a hierarchy tree. Each node in the tree represent a subclass of the Hierarchy. Can be used to find the most specific class an object is applicable to (example: in a Hierarchy tree containing Throwable and RuntimeException, IllegalStateException should map to RuntimeException, not Throwable).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceHierarchyTree.HierarchyRelation<K>static classHierarchyTree.HierarchyRelationship
-
Constructor Summary
Constructors Constructor Description HierarchyTree(HierarchyTree.HierarchyRelation<K> hierarchyRelation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<V>getHierarchyClassValue(K key)Finds the most specific hierarchy class of key, and returns its value.voidputInHierarchy(K key, V value)Puts the hierarchy class into the Hierarchy tree.
-
-
-
Constructor Detail
-
HierarchyTree
public HierarchyTree(HierarchyTree.HierarchyRelation<K> hierarchyRelation)
-
-
Method Detail
-
putInHierarchy
public void putInHierarchy(K key, V value)
Puts the hierarchy class into the Hierarchy tree.- Parameters:
key- The key of the hierarchy class, determines where it is put into the tree.value- The value of the hierarchy class.
-
getHierarchyClassValue
public Optional<V> getHierarchyClassValue(K key)
Finds the most specific hierarchy class of key, and returns its value. If it belongs to multiple hierarchy branches (example: in the divisibility hierarchy tree with classes "2" and "3", "6" belongs to both "2" and "3"), it returns the value of the most specific hierarchy class of a random branch.- Parameters:
key- What to find the most specific hierarchy class of.- Returns:
- The value of the most specific hierarchy class of key.
-
-