Package gov.usgs.earthquake.nshmp.tree
Interface LogicTree<T>
-
- Type Parameters:
T
- the type of value stored in the branches of the tree
- 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
LogicTree.Builder<T>
A single-useLogicTree
builder.static class
LogicTree.EnumBuilder<E extends Enum<E>,T>
A single-useLogicTree
builder where eachBranch.id()
of the built tree is anEnum.name()
and eachBranch.value()
is any value type.static class
LogicTree.EnumValueBuilder<E extends Enum<E>>
A single-useLogicTree
builder where eachBranch.id()
of the built tree is anEnum.name()
and eachBranch.value()
is the enum value itself.static class
LogicTree.StringValueBuilder
A single-useLogicTree
builder where eachBranch.id()
andBranch.value()
of the built tree is the same string.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <T> LogicTree.Builder<T>
builder(String name)
Return a new, single-useLogicTree
builder.static <E extends Enum<E>,T>
LogicTree.EnumBuilder<E,T>enumBuilder(String name)
Return a new, single-useLogicTree
builder where eachBranch.id()
of the built tree is anEnum.name()
and eachBranch.value()
is any value type.static <E extends Enum<E>>
LogicTree.EnumValueBuilder<E>enumValueBuilder(String name)
Return a new, single-useLogicTree
builder where eachBranch.id()
of the built tree is anEnum.name()
and eachBranch.value()
is the enum value itself.String
name()
Return the name of this tree.Branch<T>
sample(double probability)
Return a logic tree branch corresponding to the supplied probability.List<Branch<T>>
sample(double[] probabilities)
Return a list of logic tree branches corresponding to the supplied probabilities.static <T> LogicTree<T>
singleton(String name, String id, T value)
A logic tree with a single branch.static LogicTree.StringValueBuilder
stringValueBuilder(String name)
Return a new, single-useLogicTree
builder where eachBranch.id()
andBranch.value()
of the built tree is the same string.static <T> String
toString(LogicTree<T> tree)
String representation of a logic tree for use by concrete implementations.-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
-
-
-
-
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
. ForP < 0.0
, method returns the first branch of the tree; forP >= 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
. ForP < 0.0
, method returns the first branch of the tree; forP >= 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 treeid
- of the lone branchvalue
- of the lone branch
-
builder
static <T> LogicTree.Builder<T> builder(String name)
Return a new, single-useLogicTree
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-useLogicTree
builder where eachBranch.id()
of the built tree is anEnum.name()
and eachBranch.value()
is any value type.- Type Parameters:
E
- the enum ID type of each branchT
- the value type of each branch- Parameters:
name
- of the tree
-
enumValueBuilder
static <E extends Enum<E>> LogicTree.EnumValueBuilder<E> enumValueBuilder(String name)
Return a new, single-useLogicTree
builder where eachBranch.id()
of the built tree is anEnum.name()
and eachBranch.value()
is the enum value itself.- Type Parameters:
E
- the enum value type of each branch- Parameters:
name
- of the tree
-
stringValueBuilder
static LogicTree.StringValueBuilder stringValueBuilder(String name)
Return a new, single-useLogicTree
builder where eachBranch.id()
andBranch.value()
of the built tree is the same string.- Parameters:
name
- of the tree
-
-