UcteRegulation implements UcteRecord { @Override public void fix() { if (phaseRegulation != null) { if (phaseRegulation.getU() <= 0) { LOGGER.warn("Phase regulation of transformer '{}' has a bad target voltage {}, set to undefined", transfoId, phaseRegulation.getU()); phaseRegulation.setU(Float.NaN); } if (phaseRegulation.getN() == null || phaseRegulation.getN() == 0 || phaseRegulation.getNp() == null || Float.isNaN(phaseRegulation.getDu())) { LOGGER.warn("Phase regulation of transformer '{}' removed because incomplete", transfoId); phaseRegulation = null; } } if (angleRegulation != null) { if (angleRegulation.getN() == null || angleRegulation.getN() == 0 || angleRegulation.getNp() == null || Float.isNaN(angleRegulation.getDu()) || Float.isNaN(angleRegulation.getTheta())) { LOGGER.warn("Angle regulation of transformer '{}' removed because incomplete", transfoId); angleRegulation = null; } else { if (angleRegulation.getType() == null) { LOGGER.warn("Type is missing for angle regulation of transformer '{}', default to {}", transfoId, UcteAngleRegulationType.ASYM); angleRegulation.setType(UcteAngleRegulationType.ASYM); } } } } UcteRegulation(UcteElementId transfoId, UctePhaseRegulation phaseRegulation, UcteAngleRegulation angleRegulation); UcteElementId getTransfoId(); UctePhaseRegulation getPhaseRegulation(); void setPhaseRegulation(UctePhaseRegulation phaseRegulation); UcteAngleRegulation getAngleRegulation(); void setAngleRegulation(UcteAngleRegulation angleRegulation); @Override void fix();  }
@Test public void testFix() { UcteElementId id = createElementId(); UcteRegulation regulation = new UcteRegulation(id, null, null); UctePhaseRegulation invalidPhaseRegulation1 = new UctePhaseRegulation(0.0f, 1, 1, -10); UctePhaseRegulation invalidPhaseRegulation2 = new UctePhaseRegulation(Float.NaN, null, null, Float.NaN); UctePhaseRegulation invalidPhaseRegulation3 = new UctePhaseRegulation(Float.NaN, 0, null, Float.NaN); UctePhaseRegulation invalidPhaseRegulation4 = new UctePhaseRegulation(Float.NaN, 1, null, Float.NaN); UctePhaseRegulation invalidPhaseRegulation5 = new UctePhaseRegulation(Float.NaN, 1, 0, Float.NaN); regulation.setPhaseRegulation(invalidPhaseRegulation1); regulation.fix(); assertNotNull(regulation.getPhaseRegulation()); assertTrue(Float.isNaN(invalidPhaseRegulation1.getU())); testFix(regulation, invalidPhaseRegulation2); testFix(regulation, invalidPhaseRegulation3); testFix(regulation, invalidPhaseRegulation4); testFix(regulation, invalidPhaseRegulation5); UcteAngleRegulation invalidAngleRegulation1 = new UcteAngleRegulation(0.0f, 0.0f, 1, 1, 0.0f, null); UcteAngleRegulation invalidAngleRegulation2 = new UcteAngleRegulation(Float.NaN, Float.NaN, null, null, Float.NaN, null); UcteAngleRegulation invalidAngleRegulation3 = new UcteAngleRegulation(Float.NaN, Float.NaN, 0, null, Float.NaN, null); UcteAngleRegulation invalidAngleRegulation4 = new UcteAngleRegulation(Float.NaN, Float.NaN, 1, null, Float.NaN, null); UcteAngleRegulation invalidAngleRegulation5 = new UcteAngleRegulation(Float.NaN, Float.NaN, 1, 0, Float.NaN, null); UcteAngleRegulation invalidAngleRegulation6 = new UcteAngleRegulation(Float.NaN, Float.NaN, 1, 0, Float.NaN, null); UcteAngleRegulation invalidAngleRegulation7 = new UcteAngleRegulation(0.0f, Float.NaN, 1, 0, Float.NaN, null); regulation.setAngleRegulation(invalidAngleRegulation1); regulation.fix(); assertNotNull(regulation.getAngleRegulation()); assertEquals(UcteAngleRegulationType.ASYM, invalidAngleRegulation1.getType()); testFix(regulation, invalidAngleRegulation2); testFix(regulation, invalidAngleRegulation3); testFix(regulation, invalidAngleRegulation4); testFix(regulation, invalidAngleRegulation5); testFix(regulation, invalidAngleRegulation6); testFix(regulation, invalidAngleRegulation7); }