Package: BlockBossLogicProvider

BlockBossLogicProvider

nameinstructionbranchcomplexitylinemethod
BlockBossLogicProvider()
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
dispose()
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
lambda$provide$0(SignalHead)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
provide(SignalHead)
M: 8 C: 9
53%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 2 C: 2
50%
M: 0 C: 1
100%
provide(String)
M: 10 C: 11
52%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 2 C: 3
60%
M: 0 C: 1
100%
provideAll()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
register(BlockBossLogic)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
remove(BlockBossLogic)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: package jmri.jmrit.blockboss;
2:
3: import jmri.*;
4: import org.slf4j.Logger;
5: import org.slf4j.LoggerFactory;
6:
7: import javax.annotation.Nonnull;
8: import java.util.*;
9:
10: /**
11: * Provider for {@link BlockBossLogic} objects
12: *
13: * @author Paul Bender Copyright (C) 2020
14: */
15: public class BlockBossLogicProvider implements Disposable, InstanceManagerAutoDefault {
16:
17: private final SignalHeadManager signalHeadManager;
18: private final Map<SignalHead,BlockBossLogic> headToBlockBossLogicMap;
19:
20: public BlockBossLogicProvider() {
21: signalHeadManager = InstanceManager.getDefault(SignalHeadManager.class);
22: headToBlockBossLogicMap = new HashMap<>();
23: ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
24:• if (cm != null) {
25: cm.registerConfig(this, jmri.Manager.BLOCKBOSS);
26: }
27: }
28:
29: public BlockBossLogic provide(@Nonnull String signalName) {
30: SignalHead signalHead = signalHeadManager.getSignalHead(signalName);
31:• if (signalHead == null) {
32: log.error("SignalHead {} doesn't exist, BlockBossLogic.getExisting(\"{}\") cannot continue", signalName, signalName);
33: throw new IllegalArgumentException("Requested signal head doesn't exist");
34: }
35: return provide(signalHead);
36: }
37:
38: public BlockBossLogic provide(@Nonnull SignalHead signalHead){
39:• if (signalHead == null) {
40: log.error("BlockBossLogic requested for null signal head.");
41: throw new IllegalArgumentException("BlockBossLogic Requested for null signal head.");
42: }
43: return headToBlockBossLogicMap.computeIfAbsent(signalHead,o -> new BlockBossLogic(o.getDisplayName()));
44: }
45:
46: public void register(BlockBossLogic blockBossLogic){
47: headToBlockBossLogicMap.put(blockBossLogic.driveSignal.getBean(),blockBossLogic);
48: }
49:
50: public void remove(BlockBossLogic blockBossLogic){
51: headToBlockBossLogicMap.remove(blockBossLogic.driveSignal.getBean(),blockBossLogic);
52: }
53:
54: public Collection<BlockBossLogic> provideAll(){
55: return headToBlockBossLogicMap.values();
56: }
57:
58: public void dispose(){
59:• for (BlockBossLogic b : headToBlockBossLogicMap.values()) {
60: b.stop();
61: }
62: headToBlockBossLogicMap.clear();
63: }
64:
65: private static final Logger log = LoggerFactory.getLogger(BlockBossLogicProvider.class);
66:
67: }