diff --git a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/WindingType.java b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/WindingType.java index 918ee5ef6ae..244507730db 100644 --- a/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/WindingType.java +++ b/cgmes/cgmes-model/src/main/java/com/powsybl/cgmes/model/WindingType.java @@ -15,7 +15,7 @@ */ public enum WindingType { - PRIMARY, SECONDARY, TERTIARY; + PRIMARY, SECONDARY, TERTIARY, UNKNOWN; /** * Retrieve the WindingType for the given transformer winding/end. @@ -25,23 +25,21 @@ public enum WindingType { public static WindingType windingType(PropertyBag end) { if (end.containsKey("windingType")) { // For CIM14 (CIM ENTSOE Profile1) primary is determined by TransformerWinding.windingType - String wtype = end.getLocal("windingType"); - if (wtype.endsWith("WindingType.primary")) { - return WindingType.PRIMARY; - } else if (wtype.endsWith("WindingType.secondary")) { - return WindingType.SECONDARY; - } else if (wtype.endsWith("WindingType.tertiary")) { - return WindingType.TERTIARY; - } + return switch (end.getLocal("windingType")) { + case "WindingType.primary" -> WindingType.PRIMARY; + case "WindingType.secondary" -> WindingType.SECONDARY; + case "WindingType.tertiary" -> WindingType.TERTIARY; + default -> WindingType.UNKNOWN; + }; } else if (end.containsKey("endNumber")) { // For CIM16 (CGMES 2.4.15) primary is defined by TransformerEnd.endNumber try { return WindingType.values()[end.asInt("endNumber") - 1]; } catch (Exception e) { - return WindingType.PRIMARY; + return WindingType.UNKNOWN; } } - return WindingType.PRIMARY; + return WindingType.UNKNOWN; } /** diff --git a/cgmes/cgmes-model/src/test/java/com/powsybl/cgmes/model/WindingTypeTest.java b/cgmes/cgmes-model/src/test/java/com/powsybl/cgmes/model/WindingTypeTest.java index e613ad651a5..c1c23839e55 100644 --- a/cgmes/cgmes-model/src/test/java/com/powsybl/cgmes/model/WindingTypeTest.java +++ b/cgmes/cgmes-model/src/test/java/com/powsybl/cgmes/model/WindingTypeTest.java @@ -46,8 +46,8 @@ void cim14WindingTypeTest() { end4 = new PropertyBag(Collections.singletonList(WINDING_TYPE), true); end4.put(WINDING_TYPE, "WindingType.quaternary"); - assertEquals(WindingType.PRIMARY, WindingType.windingType(end4)); - assertEquals(1, WindingType.endNumber(end4)); + assertEquals(WindingType.UNKNOWN, WindingType.windingType(end4)); + assertEquals(4, WindingType.endNumber(end4)); } @Test @@ -69,7 +69,7 @@ void cim16WindingTypeTest() { end4 = new PropertyBag(Collections.singletonList(END_NUMBER), true); end4.put(END_NUMBER, "4"); - assertEquals(WindingType.PRIMARY, WindingType.windingType(end4)); - assertEquals(1, WindingType.endNumber(end4)); + assertEquals(WindingType.UNKNOWN, WindingType.windingType(end4)); + assertEquals(4, WindingType.endNumber(end4)); } }