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