| 1 | package pro.verron.officestamper.core; | |
| 2 | ||
| 3 | import pro.verron.officestamper.api.ContextTree; | |
| 4 | ||
| 5 | import java.util.ArrayList; | |
| 6 | import java.util.List; | |
| 7 | ||
| 8 | /// A branch in the context tree. | |
| 9 | public class ContextBranch | |
| 10 | implements ContextTree { | |
| 11 | private final ContextRoot tree; | |
| 12 | private final List<Object> branch; | |
| 13 | ||
| 14 | /// Constructs a ContextBranch with a single root object. | |
| 15 | /// | |
| 16 | /// @param tree the context root tree. | |
| 17 | /// @param root the root object of the branch. | |
| 18 | public ContextBranch(ContextRoot tree, Object root) { | |
| 19 | this(tree, List.of(root)); | |
| 20 | } | |
| 21 | ||
| 22 | /// Constructs a ContextBranch with a list of objects forming the branch. | |
| 23 | /// | |
| 24 | /// @param tree the context root tree. | |
| 25 | /// @param branch the list of objects in the branch. | |
| 26 | public ContextBranch(ContextRoot tree, List<Object> branch) { | |
| 27 | this.tree = tree; | |
| 28 | this.branch = branch; | |
| 29 | } | |
| 30 | ||
| 31 | /// Adds a new branch with the given object. | |
| 32 | /// | |
| 33 | /// @param object the object to add to the branch. | |
| 34 | /// | |
| 35 | /// @return the key of the added branch. | |
| 36 | public String addBranch(Object object) { | |
| 37 | var newBranch = new ArrayList<>(branch); | |
| 38 | newBranch.add(object); | |
| 39 | var contextBranch = new ContextBranch(tree, newBranch); | |
| 40 |
1
1. addBranch : replaced return value with "" for pro/verron/officestamper/core/ContextBranch::addBranch → KILLED |
return tree.addBranch(contextBranch); |
| 41 | } | |
| 42 | ||
| 43 | /// Returns the root object of the branch. | |
| 44 | /// | |
| 45 | /// @return the root object. | |
| 46 | public Object root() { | |
| 47 |
1
1. root : replaced return value with null for pro/verron/officestamper/core/ContextBranch::root → NO_COVERAGE |
return branch.getLast(); |
| 48 | } | |
| 49 | ||
| 50 | /// Returns the list of objects in the branch, in reverse order. | |
| 51 | /// | |
| 52 | /// @return the list of objects. | |
| 53 | public List<Object> list() { | |
| 54 |
1
1. list : replaced return value with Collections.emptyList for pro/verron/officestamper/core/ContextBranch::list → TIMED_OUT |
return List.copyOf(branch) |
| 55 | .reversed(); | |
| 56 | } | |
| 57 | ||
| 58 | @Override | |
| 59 | public String toString() { | |
| 60 |
1
1. toString : replaced return value with "" for pro/verron/officestamper/core/ContextBranch::toString → KILLED |
return String.valueOf(branch.getLast()); |
| 61 | } | |
| 62 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 47 |
1.1 |
|
| 54 |
1.1 |
|
| 60 |
1.1 |