Class HierarchyTree<K,​V>

  • Type Parameters:
    K - The type of the key element in the Hierarchy
    V - 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).
    • 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.