Package com.powsybl.commons.report
Interface ReportNode
- All Known Implementing Classes:
ReportNodeImpl
,ReportNodeNoOp
public interface ReportNode
A
ReportNode
allows building up functional reports with a tree hierarchy.
Each ReportNode
is defined by
- a map of
TypedValue
indexed by their keys, - a default
String
message template containing the functional message in the default language, which may contain references to those values or to the values of one of its ancestors, - a
String
message key identifying the unique corresponding functional report template; this key is used in particular to build a dictionary of all the message templates, - a collection of
ReportNode
children, possibly empty.
TypedValue
values should be referred to by their key in the message template, using the ${key}
syntax, in order to be later replaced by StringSubstitutor
for instance when formatting
the string for the end user.
The ReportNode
values may be referred to within the corresponding messageTemplate, or within any of its
descendants. Be aware that any descendant might override a value by giving a new value to an existing key.
All implementations of ReportNode
need to take that inheritance into account.
Instances of ReportNode
are not thread-safe.
When a new thread is created, a new ReportNode
should be provided to the process in that thread.
A ReportNode
is not meant to be shared with other threads.
Therefore, it should rather not be saved as a class parameter of an object which could be used by separate threads.
In those cases it should instead be passed on in methods through their arguments.
The ReportNode
is designed for multilingual support.
Indeed, each ReportNode
message can be translated based on their key and using the value keys in the desired order.
- Author:
- Florian Dupuy <florian.dupuy at rte-france.com>
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet the children of current nodeGet the message of current node, replacing${key}
references in the message template with the corresponding values, either contained in current node or in one of its parents.Get the message key for current node.Get the message template for current node.Get the value corresponding to the given keyGet the values which belong to current node (does not include the inherited values)void
include
(ReportNode reportRoot) Add aReportNode
as a child of currentReportNode
.Create a new adder to create aReportNode
child.static ReportNodeBuilder
Create a new builder for creating a rootReportNode
.void
Print to given writer the current report node and its descendantsdefault void
Print to given path the current report node and its descendantsvoid
writeJson
(com.fasterxml.jackson.core.JsonGenerator generator) Serialize the current report node
-
Field Details
-
NO_OP
A No-op implementation ofReportNode
-
-
Method Details
-
newRootReportNode
Create a new builder for creating a rootReportNode
.- Returns:
- a
ReportNodeBuilder
-
getMessageKey
String getMessageKey()Get the message key for current node. Note that each key needs to correspond to a unique message template. This allows to build up a dictionary of message templates indexed by their key.- Returns:
- the key
-
getMessageTemplate
String getMessageTemplate()Get the message template for current node.- Returns:
- the message template
-
getMessage
String getMessage()Get the message of current node, replacing${key}
references in the message template with the corresponding values, either contained in current node or in one of its parents.- Returns:
- the message
-
getValues
Map<String,TypedValue> getValues()Get the values which belong to current node (does not include the inherited values)- Returns:
- the values unmodifiable map
-
getValue
Get the value corresponding to the given key- Parameters:
valueKey
- the key to request- Returns:
- the value
-
getChildren
List<ReportNode> getChildren()Get the children of current node- Returns:
- the children nodes
-
newReportNode
ReportNodeAdder newReportNode()Create a new adder to create aReportNode
child.- Returns:
- the created
ReportNodeAdder
-
include
Add aReportNode
as a child of currentReportNode
.- Parameters:
reportRoot
- theReportNode
to add, it needs to be a rootReportNode
-
writeJson
Serialize the current report node- Parameters:
generator
- the jsonGenerator to use for serialization- Throws:
IOException
-
print
Print to given path the current report node and its descendants- Parameters:
path
- the writer to write to- Throws:
IOException
-
print
Print to given writer the current report node and its descendants- Parameters:
writer
- the writer to write to- Throws:
IOException
-