Package: BlockTaskAggregator

BlockTaskAggregator

nameinstructionbranchcomplexitylinemethod
BlockTaskAggregator(List, BlockFactory)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
assignTasks(ToplevelBlockTask, ListIterator)
M: 0 C: 28
100%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 0 C: 7
100%
M: 0 C: 1
100%
lambda$0(ListIterator, ToplevelBlockTask)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
stream()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017 Eurotech and/or its affiliates and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Eurotech
11: *******************************************************************************/
12:
13: package org.eclipse.kura.driver.block.task;
14:
15: import java.util.List;
16: import java.util.ListIterator;
17: import java.util.stream.Stream;
18:
19: import org.eclipse.kura.driver.block.Block;
20: import org.eclipse.kura.driver.block.BlockAggregator;
21: import org.eclipse.kura.driver.block.BlockFactory;
22:
23: /**
24: * <p>
25: * Represents a specialized version of {@link BlockAggregator} that operates on {@link BlockTask} instances.
26: * This class performs the aggregation of the input blocks in the same way as {@link BlockAggregator} does, and always
27: * returns {@link ToplevelBlockTask} instances as result of the aggregation.
28: * </p>
29: *
30: * <p>
31: * If any {@link BlockTask} is found in the input block list, it will be assigned to the proper parent task in the
32: * result list, basing on the start and end addresses of the two tasks.
33: * <p>
34: *
35: * <p>
36: * The result of the aggregation performed by this class is therefore a generally two level tree structure: the first
37: * level of
38: * the tree is composed by {@link ToplevelBlockTask} instances responsible of managing a data buffer, the second level
39: * is composed by {@link BlockTask} instances that perform an operation using the buffer of the parent. See
40: * {@link ToplevelBlockTask} for more information on this structure.
41: * <p>
42: *
43: * @see ToplevelBlockTask
44: * @see BlockTask
45: */
46: public class BlockTaskAggregator extends BlockAggregator<ToplevelBlockTask> {
47:
48: /**
49: * Creates a new {@link BlockAggregator} instance that operates on the given list of blocks.
50: * The provided list must be mutable as it will be sorted every time the {@link BlockAggregator#stream()} method is
51: * called.
52: *
53: * @param inputBlocks
54: * a mutable list of input blocks.
55: * @param factory
56: * a {@link BlockFactory} instance that will be used to create the output blocks during the aggregation
57: * process.
58: */
59: public BlockTaskAggregator(List<Block> tasks, BlockFactory<ToplevelBlockTask> factory) {
60: super(tasks, factory);
61: }
62:
63: private void assignTasks(ToplevelBlockTask toplevelTask, ListIterator<Block> tasks) {
64: Block next = null;
65:• while (tasks.hasNext() && (next = tasks.next()).getEnd() <= toplevelTask.getEnd()) {
66:• if (next instanceof BlockTask) {
67: toplevelTask.addChild((BlockTask) next);
68: }
69: }
70:• if (next != null) {
71: tasks.previous();
72: }
73: }
74:
75: /**
76: * {@inheritDoc}
77: */
78: @Override
79: public Stream<ToplevelBlockTask> stream() {
80: final Stream<ToplevelBlockTask> result = super.stream();
81: final ListIterator<Block> blocks = this.blocks.listIterator();
82: return result.map(toplevelTask -> {
83: assignTasks(toplevelTask, blocks);
84: return toplevelTask;
85: });
86: }
87:
88: }