Class ResultElement
java.lang.Object
com.amalgamasimulation.studies.result.ResultElement
- Direct Known Subclasses:
Result,ResultDateTimeValue,ResultDoubleValue,ResultGroup,ResultPiecewiseFunctionValue,ResultStringValue
An abstract base class representing an element in a hierarchical result
structure. Provides functionality for building and navigating a tree of
result elements, including values, groups, and other specialized result
types.
This class maintains parent-child relationships and provides methods for element creation, hierarchical navigation and searching.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionchildren()Gets an unmodifiable view of the direct children of this element.Gets all descendants of this element (children, grandchildren, etc.).element(double value) Creates and adds a new double value element as a child of this element.element(PiecewiseFunction value) Creates and adds a new piecewise function value element.Creates and adds a new string value element.Creates and adds a new double value element with specified ID and value.element(String id, double value, DoubleFormats format) Creates and adds a new double value element with specified ID, value, and format.element(String id, PiecewiseFunction value) Creates and adds a new piecewise function value element with specified ID and value.Creates and adds a new string value element with specified ID and value.element(String id, Supplier<Double> valueSupplier, DoubleFormats format) Creates and adds a new double value element with specified ID, value supplier, and format.element(LocalDateTime value) Creates and adds a new date-time value element.Creates and adds a new double value element with a value supplier.find(ResultPath path) Finds an element by its path relative to this element.findByTags(String... byTags) Finds all elements in the hierarchy that have all the specified tags.findOrThrow(ResultPath path) Finds an element by path or throws an exception if not found.findOrThrow(String... path) Finds an element by path (specified as varargs) or throws an exception if not found.Gets all child double value elements under the specified path.getChildrenDoubleResults(String... path) Gets all child double value elements under the specified path.getChildrenGroups(ResultPath path) Gets all child group elements under the specified path.getChildrenGroups(String... path) Gets all child group elements under the specified path.getDateTimeOrThrow(ResultPath path) Gets a date-time value by path or throws an exception if not found or not a date-time value.getDateTimeOrThrow(String... pathElements) Gets a date-time value by path or throws an exception if not found or not a date-time value.getFunctionOrDefault(ResultPath path, PiecewiseFunction defaultValue) Gets a piecewise function by path or returns a default value if not found or not a function value.getFunctionOrThrow(ResultPath path) Gets a piecewise function by path or throws an exception if not found or not a function value.getGroupOrThrow(ResultPath path) Gets a group element by path or throws an exception if not found or not a group.doublegetOrDefault(ResultPath path, double defaultValue) Gets a double value by path or returns a default value if not found or not a double value.doublegetOrThrow(ResultPath path) Gets a double value by path or throws an exception if not found or not a double value.doublegetOrThrow(String... pathElements) Gets a double value by path or throws an exception if not found or not a double value.getStringOrThrow(ResultPath path) Gets a string value by path or throws an exception if not found or not a string value.getStringOrThrow(String... pathElements) Gets a string value by path or throws an exception if not found or not a string value.Creates and adds a new group element with the specified ID.Creates and adds a new group element with the specified ID.booleanChecks whether any sibling element has the same ID as the given one.id()Gets the identifier of this element.Sets the identifier for this element.Sets the identifier for this element.parent()Gets the parent element of this element, if it exists.path()Gets the hierarchical path to this element from the root.root()Gets the root element of the hierarchy containing this element.protected voidsetParent(ResultElement parent) Creates and adds a new summary group element with the specified ID.summaryResultGroup(String id, DoubleFormats format) Creates and adds a new summary group element with the specified ID and format.Adds a tag to this element.tags()Gets an unmodifiable view of the tags associated with this element.
-
Constructor Details
-
ResultElement
public ResultElement()
-
-
Method Details
-
id
Sets the identifier for this element. The ID must be unique among siblings.- Parameters:
id- the unique identifier for this element- Returns:
- this element for method chaining
- Throws:
IllegalStateException- if a sibling already exists with the same ID
-
id
Sets the identifier for this element. The ID must be unique among siblings.- Parameters:
id- the unique identifier for this elementresolveDuplicates- if true, if duplicates are found, "(n)" will be added to the ID- Returns:
- this element for method chaining
- Throws:
IllegalStateException- if a sibling already exists with the same ID
-
hasSiblingWithSameId
Checks whether any sibling element has the same ID as the given one.- Parameters:
id- The ID to check for duplicates among siblings.- Returns:
trueif at least one sibling has the same ID,falseotherwise. Returnsfalseif the parent is not present (i.e., the element is a root).
-
id
Gets the identifier of this element.- Returns:
- the element's identifier
-
path
Gets the hierarchical path to this element from the root. The path is constructed by joining all parent IDs with the delimiter.- Returns:
- the path to this element
-
parent
Gets the parent element of this element, if it exists.- Returns:
- an Optional containing the parent element, or empty if this is the root
-
children
Gets an unmodifiable view of the direct children of this element.- Returns:
- the list of child elements
-
descendants
Gets all descendants of this element (children, grandchildren, etc.).- Returns:
- a list of all descendant elements
-
element
Creates and adds a new double value element as a child of this element.- Parameters:
value- the double value- Returns:
- the newly created ResultDoubleValue
-
element
Creates and adds a new double value element with specified ID, value, and format.- Parameters:
id- the element IDvalue- the double valueformat- the display format for the value- Returns:
- the newly created ResultDoubleValue
-
element
Creates and adds a new string value element with specified ID and value.- Parameters:
id- the element IDvalue- the string value- Returns:
- the newly created ResultStringValue
-
element
Creates and adds a new double value element with specified ID and value.- Parameters:
id- the element IDvalue- the double value- Returns:
- the newly created ResultDoubleValue
-
element
Creates and adds a new double value element with specified ID, value supplier, and format.- Parameters:
id- the element IDvalueSupplier- a supplier for the double valueformat- the display format for the value- Returns:
- the newly created ResultDoubleValue
-
element
Creates and adds a new piecewise function value element with specified ID and value.- Parameters:
id- the element IDvalue- the piecewise function value- Returns:
- the newly created ResultPiecewiseFunctionValue
-
element
Creates and adds a new double value element with a value supplier.- Parameters:
valueSupplier- a supplier for the double value- Returns:
- the newly created ResultDoubleValue
-
element
Creates and adds a new piecewise function value element.- Parameters:
value- the piecewise function value- Returns:
- the newly created ResultPiecewiseFunctionValue
-
element
Creates and adds a new string value element.- Parameters:
value- the string value- Returns:
- the newly created ResultStringValue
-
element
Creates and adds a new date-time value element.- Parameters:
value- the date-time value- Returns:
- the newly created ResultDateTimeValue
-
group
Creates and adds a new group element with the specified ID.- Parameters:
id- the group IDresolveDuplicates- if true, if duplicates are found, "(n)" will be added to the ID- Returns:
- the newly created ResultGroup
-
group
Creates and adds a new group element with the specified ID.- Parameters:
id- the group ID- Returns:
- the newly created ResultGroup
-
summaryResultGroup
Creates and adds a new summary group element with the specified ID and format.- Parameters:
id- the group IDformat- the display format for the value- Returns:
- the newly created SummaryResultGroup
-
summaryResultGroup
Creates and adds a new summary group element with the specified ID.- Parameters:
id- the group ID- Returns:
- the newly created SummaryResultGroup
-
find
Finds an element by its path relative to this element.- Parameters:
path- the path to the element- Returns:
- an Optional containing the found element, or empty if not found
-
findOrThrow
Finds an element by path or throws an exception if not found.- Parameters:
path- the path to the element- Returns:
- the found element
- Throws:
NoSuchElementException- if the element is not found
-
findOrThrow
Finds an element by path (specified as varargs) or throws an exception if not found.- Parameters:
path- the path elements- Returns:
- the found element
- Throws:
NoSuchElementException- if the element is not found
-
getOrThrow
Gets a double value by path or throws an exception if not found or not a double value.- Parameters:
pathElements- the path elements as varargs- Returns:
- the double value
- Throws:
NoSuchElementException- if the element is not found or not a double value
-
getOrThrow
Gets a double value by path or throws an exception if not found or not a double value.- Parameters:
path- the path to the element- Returns:
- the double value
- Throws:
NoSuchElementException- if the element is not found or not a double value
-
getFunctionOrThrow
Gets a piecewise function by path or throws an exception if not found or not a function value.- Parameters:
path- the path to the element- Returns:
- the piecewise function
- Throws:
NoSuchElementException- if the element is not found or not a function value
-
getFunctionOrDefault
Gets a piecewise function by path or returns a default value if not found or not a function value.- Parameters:
path- the path to the elementdefaultValue- the default value to return if not found- Returns:
- the piecewise function or default value
-
getOrDefault
Gets a double value by path or returns a default value if not found or not a double value.- Parameters:
path- the path to the elementdefaultValue- the default value to return if not found- Returns:
- the double value or default value
-
getStringOrThrow
Gets a string value by path or throws an exception if not found or not a string value.- Parameters:
pathElements- the path elements as varargs- Returns:
- the string value
- Throws:
NoSuchElementException- if the element is not found or not a string value
-
getStringOrThrow
Gets a string value by path or throws an exception if not found or not a string value.- Parameters:
path- the path to the element- Returns:
- the string value
- Throws:
NoSuchElementException- if the element is not found or not a string value
-
getGroupOrThrow
Gets a group element by path or throws an exception if not found or not a group.- Parameters:
path- the path to the element- Returns:
- the group element
- Throws:
NoSuchElementException- if the element is not found or not a group
-
getDateTimeOrThrow
Gets a date-time value by path or throws an exception if not found or not a date-time value.- Parameters:
pathElements- the path elements as varargs- Returns:
- the date-time value
- Throws:
NoSuchElementException- if the element is not found or not a date-time value
-
getDateTimeOrThrow
Gets a date-time value by path or throws an exception if not found or not a date-time value.- Parameters:
path- the path to the element- Returns:
- the date-time value
- Throws:
NoSuchElementException- if the element is not found or not a date-time value
-
root
Gets the root element of the hierarchy containing this element.- Returns:
- the root element
-
setParent
-
getChildrenDoubleResults
Gets all child double value elements under the specified path.- Parameters:
path- the path to the parent element- Returns:
- a list of child double values
-
getChildrenDoubleResults
Gets all child double value elements under the specified path.- Parameters:
path- the path to the parent element- Returns:
- a list of child double values
-
getChildrenGroups
Gets all child group elements under the specified path.- Parameters:
path- the path elements- Returns:
- a list of child groups
-
getChildrenGroups
Gets all child group elements under the specified path.- Parameters:
path- the path to the parent element- Returns:
- a list of child groups
-
tags
Gets an unmodifiable view of the tags associated with this element.- Returns:
- the set of tags
-
findByTags
Finds all elements in the hierarchy that have all the specified tags.- Parameters:
byTags- the tags to match- Returns:
- a list of matching elements
-
tag
Adds a tag to this element.- Parameters:
tag- the tag to add- Returns:
- this element for method chaining
-