use of com.cas.circuit.TermTeam in project TeachingInSimulation by ScOrPiOzzy.
the class ElecCompDef method afterUnmarshal.
public void afterUnmarshal(Unmarshaller u, Object parent) {
jackMap = jackList.stream().collect(Collectors.toMap(Jack::getId, data -> data));
terminalMap = terminalList.stream().collect(Collectors.toMap(Terminal::getId, data -> data));
stitchMap = stitchList.stream().collect(Collectors.toMap(Stitch::getId, data -> data));
resisStatesMap = resisStateList.stream().collect(Collectors.toMap(ResisState::getId, data -> data));
//
termAndStich.putAll(terminalMap);
termAndStich.putAll(stitchMap);
jackList.stream().forEach(jack -> termAndStich.putAll(jack.getStitchList().stream().collect(Collectors.toMap(Terminal::getId, Function.identity(), (key1, key2) -> key2, HashMap::new))));
magnetismList.stream().forEach(mag -> {
mag.getVoltageIOList().forEach(io -> {
Terminal term1 = getTerminal(io.getTerm1Id());
Terminal term2 = getTerminal(io.getTerm2Id());
if (term1 == null) {
throw new NullPointerException(name + "里的" + io.getTerm1Id() + "端子没找到");
} else {
term1.getVoltIOs().add(io);
io.setTerm1(term1);
}
if (term2 == null) {
throw new NullPointerException(name + "里的" + io.getTerm2Id() + "端子没找到");
} else {
term2.getVoltIOs().add(io);
io.setTerm2(term2);
}
});
});
resisStateList.stream().forEach(state -> {
state.getResisRelationList().forEach(resis -> {
resis.setTerm1(getTerminal(resis.getTerm1Id()));
resis.setTerm2(getTerminal(resis.getTerm2Id()));
if (state.getIsDef() == null) {
System.out.println("ElecCompDef.build()");
}
if (state.getIsDef()) {
resisRelationAdded(resis);
}
});
});
terminalList.forEach(t -> t.setElecComp(this));
// 将所有连接头进行分类
// Key:分类的名称, List<Terminal>一组的连接头
Map<String, List<Terminal>> groupTerminals = termAndStich.values().stream().filter(t -> t.getTeam() != null).collect(Collectors.groupingBy(Terminal::getTeam));
groupTerminals.entrySet().forEach(e -> new TermTeam(e.getKey(), e.getValue()));
paramMap = params.stream().collect(Collectors.toMap(Param::getKey, Param::getValue));
// ------------------
if (logic == null) {
logic = new BaseElectricCompLogic();
}
logic.setElecComp(this);
logic.initialize();
}
use of com.cas.circuit.TermTeam in project TeachingInSimulation by ScOrPiOzzy.
the class ElecCompDef method onAllChildAdded.
@Override
protected void onAllChildAdded() {
super.onAllChildAdded();
// 搜集所有的连接头和针脚
// 搜集连接头
termAndStich.putAll(terminalMap);
// 搜集所有的针脚
Map<String, Terminal> stitchMap = null;
Iterator<Entry<String, Terminal>> it = null;
Entry<String, Terminal> entry = null;
for (BaseVO<?> baseVO : children) {
if (baseVO instanceof Jack) {
stitchMap = ((Jack) baseVO).getStitch();
it = stitchMap.entrySet().iterator();
while (it.hasNext()) {
entry = it.next();
termAndStich.put(entry.getValue().getLocalKey(), entry.getValue());
}
}
}
for (Magnetism mag : magnetisms) {
for (VoltageIO voltIO : mag.getVoltageIOs()) {
Terminal term1 = getTerminal(voltIO.getPO().getTerm1Id());
Terminal term2 = getTerminal(voltIO.getPO().getTerm2Id());
if (term1 == null) {
throw new NullPointerException(po.getName() + "里的" + voltIO.getPO().getTerm1Id() + "端子没找到");
} else {
term1.getVoltIOs().add(voltIO);
voltIO.setTerm1(term1);
}
if (term2 == null) {
throw new NullPointerException(po.getName() + "里的" + voltIO.getPO().getTerm2Id() + "端子没找到");
} else {
term2.getVoltIOs().add(voltIO);
voltIO.setTerm2(term2);
}
}
}
for (ResisState resisState : resisStates) {
for (BaseVO<?> baseVO : resisState.getChildren()) {
ResisRelation resis = (ResisRelation) baseVO;
resis.setTerm1(getTerminal(resis.getPO().getTerm1Id()));
resis.setTerm2(getTerminal(resis.getPO().getTerm2Id()));
if (resisState.isDef()) {
resisRelationAdded(resis);
}
}
}
//
Map<String, List<Terminal>> teamTerminalMap = new LinkedHashMap<String, List<Terminal>>();
String teamName = null;
for (Terminal terminal : termAndStich.values()) {
teamName = terminal.getPO().getTeam();
if (Util.notEmpty(teamName)) {
if (!teamTerminalMap.containsKey(teamName)) {
teamTerminalMap.put(teamName, new ArrayList<Terminal>());
}
teamTerminalMap.get(teamName).add(terminal);
}
}
for (Entry<String, List<Terminal>> entry2 : teamTerminalMap.entrySet()) {
new TermTeam(teamName, entry2.getValue());
}
for (BlockState blockState : blockStates) {
for (BaseVO<?> baseVO : blockState.getChildren()) {
BlockRelation block = (BlockRelation) baseVO;
block.setPort1(getGasPort(block.getPO().getPortId1()));
block.setPort2(getGasPort(block.getPO().getPortId2()));
if (blockState.isDef()) {
blockRelationAdded(block);
}
}
}
}
Aggregations