Interface LogicTree<T>

  • Type Parameters:
    T - the type of value stored in the branches of the tree
    All Superinterfaces:
    Collection<Branch<T>>, Iterable<Branch<T>>, List<Branch<T>>
    All Known Implementing Classes:
    LogicGroup, SourceTree

    public interface LogicTree<T>
    extends List<Branch<T>>
    A logic tree.

    Logic trees are implemented as immutable lists of branches, where each branch has an ID, value and weight. Factory methods are provided that return builders for specialized branch implementations.

    Author:
    U.S. Geological Survey
    • Method Detail

      • name

        String name()
        Return the name of this tree.
      • sample

        Branch<T> sample​(double probability)
        Return a logic tree branch corresponding to the supplied probability.

        Note: this method does not check that 0.0 ≤ P < 1.0. For P < 0.0, method returns the first branch of the tree; for P >= 1.0 method returns the last branch of the tree.

        Parameters:
        probability - in the range [0..1)
      • sample

        List<Branch<T>> sample​(double[] probabilities)
        Return a list of logic tree branches corresponding to the supplied probabilities.

        Note: this method does not check that each 0.0 ≤ P < 1.0. For P < 0.0, method returns the first branch of the tree; for P >= 1.0 method returns the last branch of the tree.

        Parameters:
        probabilities - array with values in the range [0..1)
      • toString

        static <T> String toString​(LogicTree<T> tree)
        String representation of a logic tree for use by concrete implementations.
        Parameters:
        tree - to render as a string
      • singleton

        static <T> LogicTree<T> singleton​(String name,
                                          String id,
                                          T value)
        A logic tree with a single branch.
        Type Parameters:
        T - the value type of each branch
        Parameters:
        name - of the tree
        id - of the lone branch
        value - of the lone branch
      • builder

        static <T> LogicTree.Builder<T> builder​(String name)
        Return a new, single-use LogicTree builder.
        Type Parameters:
        T - the value type of each branch
        Parameters:
        name - of the tree
      • enumBuilder

        static <E extends Enum<E>,​T> LogicTree.EnumBuilder<E,​T> enumBuilder​(String name)
        Return a new, single-use LogicTree builder where each Branch.id() of the built tree is an Enum.name() and each Branch.value() is any value type.
        Type Parameters:
        E - the enum ID type of each branch
        T - the value type of each branch
        Parameters:
        name - of the tree