Skip to content

Commit d978f9f

Browse files
committed
Fix stream reference parsing with surrounding whitespace
1 parent e109131 commit d978f9f

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/main/java/neqsim/process/processmodel/ProcessSystem.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,16 +3999,17 @@ public StreamInterface resolveStreamReference(String ref) {
39993999
if (ref == null || ref.trim().isEmpty()) {
40004000
return null;
40014001
}
4002+
String normalizedRef = ref.trim();
40024003

40034004
String unitName;
40044005
String port = "outlet";
40054006

4006-
if (ref.contains(".")) {
4007-
String[] parts = ref.split("\\.", 2);
4008-
unitName = parts[0];
4009-
port = parts[1].toLowerCase();
4007+
if (normalizedRef.contains(".")) {
4008+
String[] parts = normalizedRef.split("\\.", 2);
4009+
unitName = parts[0].trim();
4010+
port = parts[1].trim().toLowerCase();
40104011
} else {
4011-
unitName = ref;
4012+
unitName = normalizedRef;
40124013
}
40134014

40144015
ProcessEquipmentInterface unit = getUnit(unitName);

src/test/java/neqsim/process/processmodel/JsonProcessBuilderTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ void testBuildWithSeparatorAndCompressor() {
6565
assertNotNull(process.getUnit("Comp"));
6666
}
6767

68+
@Test
69+
void testBuildWithWhitespaceAroundStreamReference() {
70+
SystemSrkEos fluid = new SystemSrkEos(298.15, 50.0);
71+
fluid.addComponent("methane", 0.85);
72+
fluid.addComponent("ethane", 0.10);
73+
fluid.addComponent("propane", 0.05);
74+
fluid.setMixingRule("classic");
75+
76+
Stream feed = new Stream("feed", fluid);
77+
neqsim.process.equipment.separator.Separator separator =
78+
new neqsim.process.equipment.separator.Separator("HP Sep", feed);
79+
ProcessSystem process = new ProcessSystem();
80+
process.add(feed);
81+
process.add(separator);
82+
83+
assertNotNull(process.resolveStreamReference(" feed "),
84+
"resolveStreamReference should trim whitespace for plain stream names");
85+
StreamInterface gasOutWithWhitespace = process.resolveStreamReference(" HP Sep. gasOut ");
86+
assertNotNull(gasOutWithWhitespace,
87+
"resolveStreamReference should trim whitespace around unit and port tokens");
88+
}
89+
6890
@Test
6991
void testBuildWithMultipleFluids() {
7092
String json = "{" + "\"fluids\": {" + " \"gas\": {" + " \"model\": \"SRK\","

0 commit comments

Comments
 (0)